Hello,
I'm working on a routine that will change objects on a particular layer to another layer.
I decided to do this with a list which I can expand in the future. My intentions are to capture all object on layer indicated by the 1st item in the list below and change their layer to the 2nd item in the list, then iterate thru every item in the list.
It somewhat works, but with a major problem:
It changes everything to "G-anno-Dims", instead of changing only the objects on layer within the list.
Here's the
(note: part of the code was barrowed from Lions60)Code:;;; Changes all drawing objects (even blocks and nested blocks) on ;;; specified valid layers in first dotted-pair to layer in 2nd (setq lnamelst '(("G-DIM" . "G-ANNO-DIMS") ("G-NOTE" . "G-ANNO-NOTE") ("G-NOTE2" . "G-ANNO-NOTE") ("G-TITL" . "G-ANNO-TITLE") ); Add to Layer list above ) ;_ end of setq ;for testing ;(foreach each lnamelst (princ (car each)(terpri))) (vl-load-com) (setq listLength (length lnamelst)) (foreach each lnamelst ;Outer Loop (setq acdoc (vla-get-activeDocument (vlax-get-acad-object))) (if (snvalid (car each)) (progn (or (tblsearch "LAYER" (car each)) (vla-add (vla-get-Layers acdoc) (car each)) ) (vlax-for blk (vla-get-Blocks acdoc) (vlax-for obj blk (vla-put-Layer obj (cdr each)) );end Vlax-for );end Vlax-for );end Progn (princ "\nInvalid layer name. Try Again") );end if );end foreach
____________________________________________
I initially started this with just the layer propety, but I get a duplication error if the layer already exists on the 2nd dotted pair layer.
Works great otherwise.
Snippet:
______________________________________Code:(foreach m lnamelst (progn (setq LayerSearch (tblsearch "LAYER" (car m))) (if (/= LayerSearch nil) (vla-put-Name (vla-Item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object))) (car m) ) (cdr m) ); Old-New Layer ) ) )
I would appreciate your help very much!
Thanks!


Reply With Quote

