Jump to content
Dayananda

Name of the block

Recommended Posts

Dayananda

How can I get the name of the block by Auto Lisp (not from visual lisp).

Share this post


Link to post
Share on other sites
dlanorh
4 hours ago, Dayananda said:

How can I get the name of the block by Auto Lisp (not from visual lisp).

 

If the block is not dynamic this will return the name of the block

 

(cdr (assoc 2 (entget (car (entsel "\nSelect Block : ")))))

 

  • Like 1

Share this post


Link to post
Share on other sites
Lee Mac

To cater for standard or dynamic blocks, you could the following Vanilla AutoLISP function, published on my site here:

;; Effective Block Name  -  Lee Mac
;; ent - [ent] Block Reference entity

(defun LM:al-effectivename ( ent / blk rep )
    (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
        (if
            (and
                (setq rep
                    (cdadr
                        (assoc -3
                            (entget
                                (cdr
                                    (assoc 330
                                        (entget
                                            (tblobjname "block" blk)
                                        )
                                    )
                                )
                               '("AcDbBlockRepBTag")
                            )
                        )
                    )
                )
                (setq rep (handent (cdr (assoc 1005 rep))))
            )
            (setq blk (cdr (assoc 2 (entget rep))))
        )
    )
    blk
)

Call the above with a block reference entity name, e.g.:

(if
    (and
        (setq e (car (entsel "\nSelect block: ")))
        (= "INSERT" (cdr (assoc 0 (entget e))))
    )
    (LM:al-effectivename e)
)

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...