Jump to content

I need to change SOME elements in a block, NOT all!


neeboy74

Recommended Posts

AAAARGH!!! Everywhere I look, everyone wants to change the layer/color of ALL the elements in a block. I have the exact opposite condition, I need to reach into a block and change individual elements to different layers. Here's what I have:

 

(defun C:test (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e)))
(vlax-for x blk
(vla-put-layer x "MDUCT");your layer here
)
)
)
(vla-regen doc acAllViewports)
(princ)
)

 

This routine will, unfortunately, change EVERYTHING in a block to a specified layer, and that's NOT what I need. I need to be able to, without opening the block editor, pick and change individual elements to different layers. If possible, I also need the objects to highlight themselves when picked, just like outside the editor in normal space as separate entities. Thanks in advance for any help!

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

 brackets please:

[code](defun C:test (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
(setq ss (ssget ":L" '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e)))
(vlax-for x blk
(vla-put-layer x "MDUCT");your layer here
)
)
)
(vla-regen doc acAllViewports)
(princ)
)

Link to comment
Share on other sites

Yes, I want to pick the elements individually on the screen. The routine would then drop them onto a layer predesignated in the code.

Link to comment
Share on other sites

Using nentsel is probably the only way to achieve this. But highlighting is not possible with that function.

(defun c:test ( / doc enm)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (while (setq enm (car (nentsel)))
   (vla-put-layer (vlax-ename->vla-object enm) "MDUCT")
   (vla-regen doc acactiveviewport)
 )
 (vla-regen doc acallviewports)
 (vla-endundomark doc)
 (princ)
)

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