How to get an object by name in lisp ?

Discussion in 'AutoCAD' started by Felix_yu, Nov 23, 2004.

  1. Felix_yu

    Felix_yu Guest

    Hi, everyone

    I need to get an object in the drawing by its name in my Lisp program. In my drawing, it is a Block with some properties. I need to select it by using its name, how?

    If someone can help me ? Thanks very much ! It's very urgent!

    Felix

     
    Felix_yu, Nov 23, 2004
    #1
  2. (setq ss (ssget "x" (list (cons 2 "YourBlockNameHere"))))

    will create a selection set of insertions for a given block.

    (setq data (tblsearch "block" "YourBlockNameHere"))
    or
    (setq data (tblobjname "block" "YourBlockNameHere"))

    will give you the an entity list of the block definition

    Hope this helps.


    --
    Autodesk Discussion Group Facilitator


    to select it by using its name, how?
     
    Jason Piercey, Nov 23, 2004
    #2
  3. Felix_yu

    ECCAD Guest

    Felix_yu,
    This is a method.

    (vl-load-com)
    (setq ent (car (entsel "\nSelect a Block:")))
    (setq elist (entget ent))
    (setq obj (vlax-ename->vla-object ent))
    (setq oname (vlax-get obj 'ObjectName))
    (prompt "\n ")
    (princ ent)
    (prompt "\n ")
    (princ elist)
    (prompt "\n ")
    (princ obj)
    (prompt "\n ")
    (command "_erase" ent "")
     
    ECCAD, Nov 23, 2004
    #3
  4. typos! <grrr>
     
    Jason Piercey, Nov 23, 2004
    #4
  5. Felix_yu

    Felix_yu Guest

    I got it and it works well. Thanks very much !

    Felix
     
    Felix_yu, Nov 24, 2004
    #5
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.