Add block name to blocks / anonymous blocks

Add block name to blocks / anonymous blocks

Anonymous
Not applicable
2,380 Views
3 Replies
Message 1 of 4

Add block name to blocks / anonymous blocks

Anonymous
Not applicable

Guys and Gals,

 

Does anybody have a lisp to add the block name to blocks and anonymous blocks?  It could change an attribute, that would be fine. The thing is we use (or should use) blocks, many blocks, in a given layout.  Many some are the same, many are different but they are all used to detail. If I could add the name and anonymous name to an attribute, I could identify them easily.

 

I see it working this way>

 

I start the lisp and create a selection set, probably a window.

 

The lisp goes through the selection and looks for blocks with attribute "XYZ".

 

For each "XYZ" it finds, it adds the block name and the effective name (if it is a dynamic block).

 

For you programmer types, this seems "wick'd" easy. 

 

 

Any takers?

 

 

Thanks!

 

Don

0 Likes
Accepted solutions (1)
2,381 Views
3 Replies
Replies (3)
Message 2 of 4

Ranjit_Singh
Advisor
Advisor
Accepted solution

Maybe like this. Minimal testing and no error trap.

(defun c:somefunc  (/ ss1 ssobj)
 (if (setq ss1 (ssget '((0 . "insert") (66 . 1))))
  (vlax-for i  (setq ssobj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
   (foreach j  (vlax-invoke i 'getattributes)
    (and (= "XYZ" (vla-get-tagstring j))
         (vla-put-textstring j
                             (strcat (vla-get-name i)
                                     (if (= :vlax-true (vla-get-isdynamicblock i))
                                      (strcat " " (vla-get-effectivename i))
                                      "")))))))
 (princ))

att_val.gif

 

Message 3 of 4

john.uhden
Mentor
Mentor

I don't think you can rename an anonymous block.  In fact I don't think you can rename block "A" to block "B" unless the definition of block "B" already exists.  I think you would have to find a way to create the new block by copying all the items from the original.  Hopefully I am wrong.

John F. Uhden

0 Likes
Message 4 of 4

Anonymous
Not applicable

Ranjit,

 

Perfect!  I knew one of you programming animals could jut pop it off like that! Exactly what I wanted!

 

Thanks!

 

 

Don

 

0 Likes