Change layer color to bylayer

Change layer color to bylayer

subs
Collaborator Collaborator
5,715 Views
7 Replies
Message 1 of 8

Change layer color to bylayer

subs
Collaborator
Collaborator

I'm trying to write a routine to change a selected object's color to Bylayer.

 

Not as straightforward as I would have thought.

Change, Properties, Color wants a number.  Entity subobject list doesn't display the color associated pair when it is set that way.  So...

 

I have one object's name stored in a variable.  I want that object's color to be Bylayer.

How can I do this?

 

thx

Buck Wyckoff
0 Likes
Accepted solutions (1)
5,716 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant
Accepted solution

(setq ABC (car(entsel)))

or

(setq ABC (ssget))

(command "_.CHPROP" ABC "" "_color" "ByLAyer" "")

 

__

 

or

(setq elist (entget ABC))

(if (assoc 62 elist)

     (entmod (subst '(62 . 256) (assoc 62 elist)elist))

     (entmod (cons '(62 . 256) elist))

)

 

or

(vla-put-color (vlax-ename->vla-object ABC) 256)

 

 

 

Sebastian

Message 3 of 8

subs
Collaborator
Collaborator

Awesome!  Thanks.

Buck Wyckoff
0 Likes
Message 4 of 8

DannyNL
Advisor
Advisor

Is your goal to use this routine as part of a larger one?

If not, you can also use the standard AutoCAD command SETBYLAYER to change the object's color to ByLayer.

0 Likes
Message 5 of 8

subs
Collaborator
Collaborator

Yes, it's part of a larger program.  Normally, without programming, I would select a group of objects and just change the layer in the properties window.  I didn't know about that command, so thanks.

 

I started using a program that creates contours on a pointcloud.  I import that into CAD, but the major and minor contours are set to a specific color.  I want to put the major and minors on their own layer set to Bylayer so when I hand the drawing off to the client, they can change the colors by simply changing the layer color.

 

I also want to thicken the major contours, but a problem I have is most contours are polylines and a few are lines.  When I have only polylines selected, I can change the global width in the properties dialog.  If a mixture of polyline and lines are selected, there is no thickness option in the dialog.  I know when I try to PEdit and line, it asks if I want to change it to a poly, then I can give it width.  Is there a command that changes lines to polys?

 

I want to completely automate the process by just running the program and it selects all the polys (or steps through the database one by one (entnext) checking if it is a poly, converting it to a poly if it is a line, checking the entity's color and if a major contour, changing it to the major contour layer, making color bylayer and adding thickness.  If the current color is a minor contour, setting it to bylayer and moving it to the minor contour layer.

 

I know how to do all of that except converting an entity to a polyline from a line.

Buck Wyckoff
0 Likes
Message 7 of 8

dgorsman
Consultant
Consultant

@cadffm wrote:

(setq ABC (car(entsel)))

or

(setq ABC (ssget))

(command "_.CHPROP" ABC "" "_color" "ByLAyer" "")

 

__

 

or

(setq elist (entget ABC))

(if (assoc 62 elist)

     (entmod (subst '(62 . 256) (assoc 62 elist)elist))

     (entmod (cons '(62 . 256) elist))

)

 

or

(vla-put-color (vlax-ename->vla-object ABC) 256)


In the ActiveX documentation, the "Color" property is noted as obsolete.  While it still works, it's probably better to use the TrueColor property and assign it a TrueColor interface object (create one interface object outside the loop, then assign it to the different objects inside the loop).  There's a few other benefits to doing it that way, including some useful properties and conversion methods for non-ACI colors.

 

And have a look in the ActiveX API for the constants which can make the code a bit more readable, such as "acByLayer", "acByBlock", "acRed", etc.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 8 of 8

ActivistInvestor
Mentor
Mentor

Don't be afraid to use the ActiveX Color property. The docs have claimed that it is obsolete and will be removed in 'future versions' for at least the past 10 years.

 

IOW, it is the documentation itself that is 'obsolete'.

 


@cadffm wrote:

 


(vla-put-color (vlax-ename->vla-object ABC) 256)

 

 

 




 

 

0 Likes