I want to change all pline in drawing to a specific object color (color 253). My code is not working & my brain is not functionning properly today.... Could somebody help...?
(DEFUN C:TR() (SETQ ALL_PLINE_IN_DRAWING (ssget "_X" '((0 . "LWPOLYLINE"))) number_of_pline_in_dwg (sslength ALL_PLINE_IN_DRAWING) entity (ssname ALL_PLINE_IN_DRAWING 1) data (entget entity) new_LAYER (list(cons 62 253)) data (append new_LAYER data) ) (entmod data) );END OF DEFUN
entmod could be rejecting your entity information because it may already have color information and your adding one to it without checking and changing the existing one.
I tried not to change too much of your code, Just taking out a couple lines of your code and adding an if condition. this is one way to do it.
(DEFUN C:TR()
(SETQ ALL_PLINE_IN_DRAWING (ssget "_X" '((0 . "LWPOLYLINE")))
number_of_pline_in_dwg (sslength ALL_PLINE_IN_DRAWING)
x -1
)
(while (not (= (setq x (1+ x)) number_of_pline_in_dwg))
(setq entity (ssname ALL_PLINE_IN_DRAWING number_of_pline_in_dwg)
data (entget entity)
)
(entmod (if (assoc 62 data) (subst (cons 62 253) (assoc 62 data) data) (cons (cons 62 253))))
);while
);END OF DEFUN
oh, was just editing code for ssget, and ken has mentioned the second part.
@Anonymous_Francois_Nant wrote:
I want to change all pline in drawing to a specific object color (color 253). My code is not working & my brain is not functionning properly today.... Could somebody help...?
(DEFUN C:TR() (SETQ ALL_PLINE_IN_DRAWING (ssget "_X" '((0 . "LWPOLYLINE"))) number_of_pline_in_dwg (sslength ALL_PLINE_IN_DRAWING) entity (ssname ALL_PLINE_IN_DRAWING 1) data (entget entity) new_LAYER (list(cons 62 253)) data (append new_LAYER data) ) (entmod data) );END OF DEFUN
That will do something to only one Polyline [the second one in the selection set -- the first is index number 0 in (ssname)]. You can find many examples of routines that step through selection sets in this Forum, to see how to make such a change to all of them. It would make use of your number_of_pline_in_dwg variable, which as it is you are not using for anything.
[I would use a different variable name than new_LAYER for that, but....]
I think you should (append) those lists in the other order -- (append data new_LAYER). Without trying it out in this specific situation, my experience with certain other entity data entries is that if there are two of the same association-number value [here the 62 for color], the later one "wins" the competition, and the earlier one is discarded. If that's true for color entries, and a Polyline already has a color override, as you have it, it will keep the color it has, because that will be later in the entity data list, and the color-253 entry will "lose." [It shouldn't make a difference if the Polyline does not have a color override, i.e. is Bylayer, and has no 62-code entry.]
If you have Polylines in different spaces [Model and Paper, and/or more than one Paper-space Layout], then to change them all, you need to do something like what you're trying to do, that modifies their entity data [or via VLA Properties]. But to do it to just things in one space, if that's where you are when you do it, it can be much simpler:
(command "_.chprop" (ssget "_X" '((0 . "LWPOLYLINE"))) "" "_color" 253 "")
Also consider whether you need to account for locked Layers. If something is on one of those, would you want the routine to leave it alone, or unlock the Layer and change it?
Thanks for the reply. To find the error in my coding I remove the loping coding stuff... that's why it will (just for now) only change one pline. From what i've seen, if an object's color is set "bylayer" it does not contain the (62 . Color #). I tried to append this (62 . Color #) & then entmod it but it doesnt work...
@Anonymous_Francois_Nant wrote:
Thanks for the reply. To find the error in my coding I remove the loping coding stuff... that's why it will (just for now) only change one pline. From what i've seen, if an object's color is set "bylayer" it does not contain the (62 . Color #). I tried to append this (62 . Color #) & then entmod it but it doesnt work...
It works for me, whether or not the object already has a color override, but only when the (62 . Color#) is appended onto the end of the entity data list, not if it's put at the beginning.
Also, if you're testing it in something with only one LWPolyline in it, it won't work because it will try to change the second item in a selection set with only one item in it.
Now I got you! (at the end of the data list not at the begining). Thanks for the really great support!! My brain now feel's much better...