Get layer name from selecting point on arc?

Discussion in 'AutoCAD' started by clutz, Feb 20, 2004.

  1. clutz

    clutz Guest

    Description of what I'm trying to do:

    I need to write a lisp routine to insert a block on an arc, but the block needs to be on the same layer as the arc, no matter what the current layer is.

    Anyone help with this one?
     
    clutz, Feb 20, 2004
    #1
  2. clutz

    urugx Guest

    Write your routine using the following:

    Go to AutoCAD help, Autolisp section
    and read on the following lisp functions:
    setvar, getvar and command. These are
    the functions you might use in your lisp
    routine.

    Study the autocad command "insert".

    Start writing your routine by following
    these guidelines:
    1. Save current layer to a variable (clay).
    2. Get layer of arc selected (arclayer).
    3..Set current layer to arc's layer.
    4. Insert your block.
    5. Set current layer to original layer (clay).

    Test your routine. If it doesn't work, post
    your routine in this thread.
     
    urugx, Feb 20, 2004
    #2
  3. clutz

    urugx Guest

    Also study these additional Autolisp functions:
    entget, entsel, assoc, cdr etc.
     
    urugx, Feb 20, 2004
    #3
  4. clutz

    clutz Guest

    I understand where are you taking this, but that problem I'm have was I need to select a point on the arc and use that point to get the arc layer name and use it to insert the block to. Inserting the block is no problem. I'm having trouble getting the layer name of the arc from the point on the arc I have selected.
     
    clutz, Feb 20, 2004
    #4
  5. clutz

    urugx Guest

    Why don't you post your code?

    Are you using (ssget)? If so, try
    entsel so you have your entity and
    point where you want to insert your
    block.
     
    urugx, Feb 20, 2004
    #5
  6. clutz

    clutz Guest

    Here is the specific code. Right now this code will not let me select an arc but I can select a line. This is mainly what I'm trying to accomplish. Everything else in the code is fine. I don't know a lot about this stuff, so I get confused quickly..

    (defun elec1 ()
    (setvar "cmdecho" 0)
    (setq e nil)
    (setq objs (getvar "osmode") )
    (command "osnap" "quick,end,int,nea")
    (setq p1 (getpoint "Select location of symbol on wiring: "))
    (command "select" p1 "")
    (setq e (ssname (ssget "p") 0))
    (command "osnap" "")
    (setq ;e (car e)
    e (entget e)
    x1 (cdr (assoc 10 e))
    x2 (cdr (assoc 11 e))
    ln (cdr (assoc 8 e))
    a1 (angle x1 x2)
    a2 (angle x2 x1)
    a1 (rtd a1)
    )
    (command "layer" "s" ln "")
    )
    (defun c:c-w1 ()
    (setq ecl (getvar "clayer"))
    (setq snm "c-w1")
    (elec1)
    (command "insert" snm p1 ns "" "nea" pause "-layer" "s" ecl "")
    (setvar "osmode" objs)
    )

    Thanks
     
    clutz, Feb 20, 2004
    #6
  7. clutz

    Mike Weaver Guest

    Here is one way to do it:

    Mike

    (setq
    ent (entsel)
    p0 (osnap (cadr ent) "_near")
    lname (objectlayername ent)
    )

    (defun ObjectLayerName( ;Given an entity name, return the layer on which
    it resides
    ent ;may be an entity name or an entity assoc list
    /
    )
    (cond
    ((= "ENAME" (type ent))
    (cdr (assoc 8 (entget ent)))
    )
    ((and (listp ent) (boundp ent) (assoc 8 ent))
    (cdr (assoc 8 ent))
    )
    (T (alert (strcat "Invalid argument in ObjectLayerName function: "
    (vl-prin1-to-string ent))))
    )
    )


    needs to be on the same layer as the arc, no matter what the current layer
    is.
     
    Mike Weaver, Feb 20, 2004
    #7
  8. clutz

    ECCAD Guest

    clutz,
    In your post, you show:
    (setq ;e (car e)
    ...
    Is there 'really' a ";" after the (setq ?
    if so, remove it.

    Bob
     
    ECCAD, Feb 20, 2004
    #8
  9. clutz

    clutz Guest

    This is some old code that I'm trying to modify. It was in there from before and was working. I removed the ";" and still works the same. Not sure what it was for.

    Thanks
     
    clutz, Feb 20, 2004
    #9
  10. clutz

    ECCAD Guest

    Clutz,
    Oh. I see why it was there, put it back in..
    What do you get for variable ln when you grab the arc ?
    (prompt (strcat "\nLayer Name= " ln)) should echo it to command line..This way, you can debug (what) layer it is getting.

    Bob
     
    ECCAD, Feb 20, 2004
    #10
  11. An Arc doesn't have a dxf group code 11. You are trying to find the
    angle with a nil point.

    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

    work on arcs. Anyone have an idea on what needs changed so I can use
    the above code on an arc. When I select an arc to insert the symbol
    on, it display the following error:
     
    Ken Alexander, Feb 20, 2004
    #11
  12. clutz

    clutz Guest

    Thanks for all the info everyone... I figured it out... :)
     
    clutz, Feb 20, 2004
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.