A simple lesson for changing the properties of objects inside blocks

A simple lesson for changing the properties of objects inside blocks

Anonymous
Not applicable
1,456 Views
5 Replies
Message 1 of 6

A simple lesson for changing the properties of objects inside blocks

Anonymous
Not applicable

I'm trying dilligently to learn how to code in AutoLISP for changing things like layer assignments of objects inside blocks.

 

I've been looking at examples for a while now, and it's too much for me to take in all at once.  Please note the following code:

 

; Changes selected objects to Layer TO_THIS_LAYER
(defun c:TTL ()
(tolayer
(ssget "_:L") ;;selection
"TO_THIS_LAYER" ;;Layer
)
(princ)
)

I need to get to the next step: being able to make this kind of object property assignment change inside a block without opening the block editor every time.  I know it involves a few "vla--" commands.  Could someone format this simple program for me so I have a good, basic example to learn from?  Also is it possible to retain the object-selection-highlighting, or is that not possible when reaching directly into a block for edits? Thanks in advance!

0 Likes
Accepted solutions (1)
1,457 Views
5 Replies
Replies (5)
Message 2 of 6

jdiala
Advocate
Advocate
Accepted solution

Here is a quickie

 

(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)
)
Message 3 of 6

Anonymous
Not applicable

GREAT!  Thanks so much! Smiley HappySmiley Very Happy

0 Likes
Message 4 of 6

Anonymous
Not applicable

...OOPS, except it's changing everything inside the block, not just the single entity I pick.  Any chance of modifying your code for that?  My blocks have different lines inside them that need differing layer assignments.  Thanks!

0 Likes
Message 5 of 6

jdiala
Advocate
Advocate

@Anonymous wrote:

...OOPS, except it's changing everything inside the block, not just the single entity I pick.  Any chance of modifying your code for that?  My blocks have different lines inside them that need differing layer assignments.  Thanks!

 

 

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

 

0 Likes
Message 6 of 6

jdiala
Advocate
Advocate

Sorry my bad. Misunderstood your request the last time. Here you go.

 

(defun C:test ()
(vla-put-layer (vlax-ename->vla-object (car (nentsel))) "MDUCT")
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports)
)