I have the following routine as a keyboard shortcut:
^C^C_change p la P-C-D-DEMO ;
It quickly moves selected objects to my demolition layer. The problem is I apply this routine to all sorts of objects from all sorts of layers. Almost all of these objects have all of their properties as ByLayer. When I move them to the demolition layer, I'd like to preserve their old appearance.
I'm looking for some macro or lisp logic that can...
LOOKUP each property
THEN
IF property is ByLayer
GETVAR from that layer and apply it to the object
ELSE keep the original property
It would be nice if this could just be a string to precede my code from above, but I'm guessing it will need to be a LISP because I'd like for it to work on selections of multiple objects from multiple layers.
I don't mind doing some of this work, just looking for some direction.
Thanks!
Solved! Go to Solution.
Solved by hencoop. Go to Solution.
First, It is always best to keep all of your work with BYLAYER for both linetype and color IMHO. To do so requires a separate layer for every linetype and color and other differentiation you need to make. That is why a good layer standard is essential. I recommend the CAD Layer Guidelines as a place to start.
However, if you must do what you are asking:
(DEFUN c:demoobjs (/ demo-objs cnt this-obj-ename this-edata assoc-6 assoc-62 this-obj-layer this-layer-edata this-layer-color this-layer-ltype this-obj ) (SETQ demo-objs (SSGET)) (SETQ cnt 0) (WHILE (< cnt (SSLENGTH demo-objs)) (SETQ this-obj-ename (SSNAME demo-objs cnt)) (SETQ this-edata (ENTGET this-obj-ename)) (IF (AND (SETQ assoc-6 (ASSOC 6 this-edata)) (SETQ assoc-62 (ASSOC 62 this-edata)) ) ;_ end of AND (SETQ assoc-6 NIL assoc62 NIL ) ;_ end of SETQ (PROGN (SETQ this-obj-layer (CDR (ASSOC 8 this-edata))) (SETQ this-layer-edata (ENTGET (TBLOBJNAME "LAYER" this-obj-layer)) ) ;_ end of SETQ (SETQ this-layer-color (CDR (ASSOC 62 this-layer-edata)) this-layer-ltype (CDR (ASSOC 6 this-layer-edata)) ) ;_ end of SETQ (VL-LOAD-COM) (SETQ this-obj (VLAX-ENAME->VLA-OBJECT this-obj-ename))
(VLAX-PUT-PROPERTY this-obj 'Layer "P-C-D-DEMO") (IF assoc-6 NIL (VLAX-PUT-PROPERTY this-obj 'Linetype this-layer-ltype) ) ;_ end of IF (IF assoc-62 NIL (ENTMOD (APPEND this-edata (LIST (CONS 62 this-layer-color))) ) ;_ end of ENTMOD ) ;_ end of IF (SETQ assoc-6 NIL assoc62 NIL ) ;_ end of SETQ ) ;_ end of PROGN ) ;_ end of IF (SETQ cnt (1+ cnt)) ) ;_ end of WHILE (PRINC) ) ;_ end of DEFUN
I believe the layer must already exist for the layer to be changed by this.
Thanks hencoop,
this is enough to get me going in the right direction, although it does behave a bit peculiarly as you have it written.
I agree on the importance of ByLayer properties and a good layer standard. My company has a daunting list of layers and stresses this importance a great deal, but has somehow fallen short in regards to the demolition aspect. Essentially, I just want to have my survey show up unmodified on my existing conditions sheet, have demo items highlighted on my demolition sheet, and then be gone on my proposed/layout sheet. While I could duplicate every layer I have and suffix their titles with "DEMO" or similar, it would double my amount of layers, which doesn't thrill me, and I would either be an odd duck in the company or have to pitch the idea to 200+ people.
Perhaps I need to think about this a bit more.
Anyway, thanks again for the help!
Please describe the peculiarity. Perhaps I can fix that for you.
It seems to handle certain selection combinations differently.
My first and only test was this...
Draw two lines on Layer "BLUEDASHED" (for this example)
Line one is Color ByLayer and Linetype Bylayer (Blue and Dashed)
Line two is Color Blue and Linetype Dashed
Results from running routine on Line one...
Line 1: Color Blue (ok) Linetype Dashed (ok) Layer "BLUEDASHED" (wrong)
Results from running routine on Line two...
Line 2: Color Blue (ok, didn't change) Linetype Dashed (ok, didn't change) Layer "BLUEDASHED" (wrong)
Results from running routine on Line one AND Line two...
Line 1: Color ByLayer (wrong, didn't change) Linetype Dashed (ok) Layer "P-C-D-DEMO" (ok)
Line 2: Color Blue (ok, didn't change) Linetype Dashed (ok, didn't change) Layer BLUEDASHED (wrong)
I can't parse the syntax well enough to completely diagnose, but intuitively it seems to be an order of operations malfunction. I think certain variables are not being updated after cnt+1. Also, change layer to DEMO shouldn't have any conditions, should just apply all the properties and as the last step move to DEMO layer.
Again, I came to you for help, I'm just trying to form a coherent speculation.
Thanks!
I don't know why VLAX-PUT-PROPERTY... did not always work but I see the same problem.
I reverted to old-school methods and it appears to work consistently for me.
(DEFUN c:demoobjs (/ demo-objs cnt this-obj-ename this-edata assoc-6 assoc-62 this-obj-layer this-layer-edata this-layer-color this-layer-ltype this-obj ) (SETQ demo-objs (SSGET)) (SETQ cnt 0) (WHILE (< cnt (SSLENGTH demo-objs)) (SETQ this-obj-ename (SSNAME demo-objs cnt)) (SETQ this-edata (ENTGET this-obj-ename)) (IF (TBLSEARCH "LAYER" "P-C-D-DEMO") NIL (COMMAND "-layer" "m" "P-C-D-DEMO" "") ) (PROGN (SETQ this-obj-layer (CDR (ASSOC 8 this-edata))) (SETQ this-layer-edata (ENTGET (TBLOBJNAME "LAYER" this-obj-layer)) ) ;_ end of SETQ (SETQ this-layer-color (CDR (ASSOC 62 this-layer-edata)) this-layer-ltype (CDR (ASSOC 6 this-layer-edata)) ) ;_ end of SETQ (SETQ this-edata (SUBST (CONS 8 "P-C-D-DEMO")(ASSOC 8 this-edata) this-edata) ) ;_ end of ENTMOD (IF (ASSOC 6 this-edata) (SETQ this-edata (SUBST (CONS 6 this-layer-ltype)(ASSOC 6 this-edata) this-edata) ) ;_ end of ENTMOD (SETQ this-edata (APPEND this-edata (LIST (CONS 6 this-layer-ltype))) ) ;_ end of ENTMOD ) (IF (ASSOC 62 this-edata) (SETQ this-edata (SUBST (CONS 62 this-layer-color)(ASSOC 62 this-edata) this-edata) ) ;_ end of ENTMOD (SETQ this-edata (APPEND this-edata (LIST (CONS 62 this-layer-color))) ) ;_ end of ENTMOD ) ;_ end of IF (ENTMOD this-edata) (ENTUPD this-obj-ename) ) ;_ end of PROGN (SETQ cnt (1+ cnt)) ) ;_ end of WHILE (PRINC) ) ;_ end of DEFUN