Change all layers and entities with a certain color to another color

Change all layers and entities with a certain color to another color

Anonymous
Not applicable
3,185 Views
15 Replies
Message 1 of 16

Change all layers and entities with a certain color to another color

Anonymous
Not applicable

Hello, good morning everyone.
Someone can help me ?

I have some drawings that I need to change all layers that have color 2 to color 7, or color 3 to color 2 ... and so on.
Based on an excell file, for example, I placed the colors I needed in a first column so that in all layers that were configured for those colors, change to another color that was defined in a second column of the excell sheet.

Basically what I need is; I get files configured for encoding (with a ctb) that are different from the ones I use.
Or I have some of my drawings with some configuration that I then have to send with the colors to be worked or printed with another ctb and another color coding.
I don't know if it's explicit, but I hope it made me explain.

In addition to changing the colors associated with the layers, I also needed help if there were lines or entities in the drawing in colored blocks (for example, color 2 would have to be color 7, where color 3 would have to be to be color 2 ... equal to the coding for the layers).

I ask for help from someone who can easily help me with this.

Thank you all.

João M.

0 Likes
Accepted solutions (1)
3,186 Views
15 Replies
Replies (15)
Message 2 of 16

ВeekeeCZ
Consultant
Consultant

I think that the built-in LAYTRANS command is what you need.

0 Likes
Message 3 of 16

Anonymous
Not applicable

thanks for the reply, but that’s not what I need.
I have many drawings with different layers, and with LAYTRANS I am unable to map all layers by different names.
For example, in a drawing I have a layer with the name x_tta, with the color 3, which in another drawing I have the name x_ottl, but whose color is also 3 and in both I have to change, only the color (regardless of the name) for the color 2, it's almost just filters.
all layers whose color is X are called with the same name as each one, but then the colors change from X to Y, and so at least in the first 10 colors.

0 Likes
Message 4 of 16

devitg
Advisor
Advisor

@Anonymous , Hi Joa, please upload both samples,  xls, and a few  dwg.

 

Better than XLS , it is  CSV from Xls 

0 Likes
Message 5 of 16

Anonymous
Not applicable

hello Gabriel, thanks for the reply.
I send a file with the color tables of the original file (1st column of the excell) and the color I need to change after (2nd column).
I also send two dwg files with examples of how I have layers with very different names, but that the goal is just to change the colors in order to be in accordance with the excell tables (1st and 2nd column)

thanks

João

0 Likes
Message 6 of 16

jadranko
Contributor
Contributor
Accepted solution

Hello João,

 

Please check the attached lisp file.

Color tables are expected in csv format without headers, as @devitg suggested.

I translated your original table, dropped the colors that do not change (like 1,1) and attached it to this post for example.

 

Please note that there is no error checking code, you have to ensure valid color table file in order to avoid crashing the code.

 

 

0 Likes
Message 7 of 16

Anonymous
Not applicable

Good Morning, Jadranko
Show !
Thank you, thank you very much, ... I have been going around with some routines for a long time, but I had to do it in several parts, and one of them didn't work, I was already giving up.
Thank you,

 

0 Likes
Message 8 of 16

Anonymous
Not applicable

Great help Sir,

 

 Is it possible to update this lisp code with out excel import?

It means, if user wants to update the colors by user input at command prompt?

 

Advanced Thanks a lot Sir.

0 Likes
Message 9 of 16

jadranko
Contributor
Contributor

Hello @Anonymous,

 

I think it is more convenient to prepare csv file in editor before the substitution, especially if you run the same substitution on more than one file. If you'd like to modify it for direct entry, replace the block between the first two comment lines  (line numbers 3 - 12) with the following two lines of code:

(while (> (setq line (getstring t "Color substitution pair (oldcolor,newcolor): ")) "")
  (setq colorsubstlist (cons (read (strcat "(" (vl-string-subst " . " "," line) ")" )) colorsubstlist)))

 

When you run it, enter color substitution pair by pair like this:

Color substitution pair (oldcolor,newcolor): 2,7

Color substitution pair (oldcolor,newcolor): 3,2

Color substitution pair (oldcolor,newcolor): 6,3
Color substitution pair (oldcolor,newcolor): <enter on the empty line>

 

I hope this helps.

Best regards,

Jadranko

Message 10 of 16

jadranko
Contributor
Contributor

You are welcome João,

 

If you need complex mass updates, you could try AutoCAD Map 3D. It is now part of AutoCAD with Specialized Toolsets.

It has powerful queries and property alterations which helps you change properties on large number of carefully selected objects, even from many dwg files at once. It is possible to build the library of such queries and reuse them later on new files.

 

Best regards,

Jadranko

0 Likes
Message 11 of 16

Anonymous
Not applicable

thanks for your help,

thanks

Joao

0 Likes
Message 12 of 16

Anonymous
Not applicable

Dear Sir,

 

Thanks a lot for your help. I have tried, but couldn't done it.

I am requesting you to please update with original code.

 

Thanks in advacne Sir.

0 Likes
Message 13 of 16

jadranko
Contributor
Contributor

Hello @Anonymous,

 

Please find the amended file in the attachment.

 

Best regards,

Jadranko

0 Likes
Message 14 of 16

Anonymous
Not applicable

Thanks a lot Sir,

 

Working Nice

0 Likes
Message 15 of 16

DC-MWA
Collaborator
Collaborator

Hello,

I know this is an old post, but this is exactly what I was searching for. I'm hoping it can be modified to do view port layers (VPLayer) also.

 

0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

Why not make new ctb's that match the output required. We had multiple choose plot so correct CTB is used, the TIFF is a good example where it was monochrome but linetype thickness was changed for all colors. Can be used for various companies just get there ctb.

SeaHaven_0-1700616255969.png

 

 

0 Likes