LISP: Move Block to a Layer based on the Block Attribute Value

LISP: Move Block to a Layer based on the Block Attribute Value

Anonymous
Not applicable
1,383 Views
3 Replies
Message 1 of 4

LISP: Move Block to a Layer based on the Block Attribute Value

Anonymous
Not applicable

I have a drawing which has blocks with an attribute called "GROUP", which has the layer name (the layer name the block is on) as its value. This attribute value comes from FIELD>OBJECT>LAYER info , when I move the block or change it to any layer, picking up the layer name and having the name of the layer as the value of the "GROUP" attribute of that block.

Now, I need to change the layers of these blocks, so I'm intending to ATTIN the "GROUP" attribute info to update the layer name for that block. I need a lisp to change/move the layer of the blocks to match the attribute value (i.e. the Layer name) of the "GROUP" attribute of that block.

Possible ? Can anyone help me with a LISP to do this ? Thanks.

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

ronjonp
Advisor
Advisor
Accepted solution

@Anonymouswrote:

 

...

Possible ? Can anyone help me with a LISP to do this ? Thanks.


Sure 🙂

(defun c:foo (/ l s)
  (if (setq s (ssget ":L" '((0 . "insert") (66 . 1))))
    (foreach b (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (if (setq	l
		 (vl-some '(lambda (x)
			     (cond ((= "GROUP" (strcase (vla-get-tagstring x))) (vla-get-textstring x)))
			   )
			  (vlax-invoke (vlax-ename->vla-object b) 'getattributes)
		 )
	  )
	(entmod (append (entget b) (list (cons 8 l))))
      )
    )
  )
  (princ)
)
Message 3 of 4

Anonymous
Not applicable

Thanks so much Perez....works like a charm 🙂

Cheers !

0 Likes
Message 4 of 4

ronjonp
Advisor
Advisor

Glad to help 🙂