Jump to content

Name of the block


Dayananda

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...