Jump to content

lisp to move all entities to layer 0 and change it's color from by layer modification


handasa

Recommended Posts

Greetings everybody

i have this lisp routine

(vl-load-com)
(defun c:COMBINELAYERS(/ doc blocks blk eo layers lay)
;CHANGE BY LAYER COLOR TO OVERRIDE COLOR 
 ;; Get the ActiveX object of the current dwg
 (setq doc    (vla-get-ActiveDocument (vlax-get-acad-object))
       blocks (vla-get-Blocks doc) ;Get the blocks collection
       layers (vla-get-Layers doc) ;Get the layers collection
 ) ;_ end of setq

 ;; Step through all blocks (including Model Space & Layouts)
 (vlax-for blk blocks
   ;; Step through all contained entities in block
   (vlax-for eo blk
     ;; Get the layer the entity is placed on
     (setq lay (vla-Item layers (vla-get-Layer eo)))
     (vla-put-Layer eo (getvar "CLAYER")) ;Change the entity to the current layer
     (if (= (vla-get-Color eo) 256)
       ;;If its colour bylayer, change it to overridden color to match
       (vla-put-Color eo (vla-get-color lay))
     ) ;_ end of if
     (if (= (strcase (vla-get-Linetype eo)) "BYLAYER")
       ;;If its linetype bylayer, change it to overridden linetype to match
       (vla-put-Linetype eo (vla-get-Linetype lay))
     ) ;_ end of if
     (if (= (vla-get-Lineweight eo) -1)
       ;;If its lineweight bylayer, change it to overridden lineweigth to match
       (vla-put-Lineweight eo (vla-get-Lineweight lay))
     ) ;_ end of if
   ) ;_ end of vlax-for
 ) ;_ end of vlax-for
 (princ)
) ;_ end of defun

which move all objects including blocks subentites to layer 0 or the current layer ..and change all bylayer colored objects to irrespective color

 

but i apply for all the drawing with no selection

 

i want the lisp to ask the user to select objects to apply to ... thanks in advance

Link to comment
Share on other sites

try this :-

You can only change selected objects...

Note- Objects within blocks won't be change, it will change the block color (if you have set to by block) and layer only. Cant change block entities as it will change the block definition and will reflect impact on other blocks too apart from selected blocks. Hope you got my point

(defun c:test (/ a b i)
 (if (setq a (ssget))
   (repeat (setq i (sslength a))
     (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
     (vla-put-layer b "sat")		;Replace "0" with (getvar "CLAYER") for current layer
     (vla-put-color b 256)
   )
 )
 (princ)
)

Link to comment
Share on other sites

@ satishrajdev thanks for your reply ... can you just modify my lisp to ask the user to select objects from drawing ? iam fairly new to lisps and its coding ...

thanks in advacne

Edited by handasa
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...