Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autocad change colour script help

5 REPLIES 5
Reply
Message 1 of 6
miloRTZPE
372 Views, 5 Replies

Autocad change colour script help

Hi!

 

I am trying to to make a script work for my AutoCAD, script that changes layer colours to one in my colour book - I have a set of commands already like:

 

-LAYER
Set
FEATURES
Color
COlorbook
Color Book One
Terrain
FEATURES

 

which works, however sometimes a certain file is missing a layer from that list and therefore the script fails. Is there a way to make its o the script ignores the missing layer and moves to the next command?

 

Thanks!

5 REPLIES 5
Message 2 of 6
pendean
in reply to: miloRTZPE

the MAKE option in -LAYER command not only SETs the layer as active, but if it is missing it will go ahead and create it too.

Experiment an rewrite your script.
Message 3 of 6
miloRTZPE
in reply to: miloRTZPE

Hi,

 

Thanks for the reply.

 

From what I understand, I dont need to make a layer as the layers are already there in the DWG file (see Attachment 1) These layers in the attachment have a default colour which I need to change using a script to a colours from my colour book. (See attachment 2) here you see the content of the script - it contains all possible layer names and what colour from the colour book they should have.

 

However when I try to run the script, and one of the layers is missing (which happens, not all files will contain the entire list of these layers some can have 5 layers from the list and other can have 12+) it fails with the following command: Cannot find layer "FEATURES", this can happen to any layer that is not present. 

 

Its very strange, as the script works when it only has a list of layers that are currently present in the DWG file - So for example if Terrain, Road, Greenspace are the only layers and script only contains these 3 then it works. But I can not make individual scripts for individual files as it destroys the idea of having to change these colours quickly.

 

Hence why I am trying to see if someone knows why the script would not work. I am taking this on from someone who is no longer present so any input or suggestions are very welcome.

 

Thanks,

Attachment 1.jpg

Attachment 2.jpg

  

Message 4 of 6
pendean
in reply to: miloRTZPE

One more time, the MAKE option in -LAYER command
1) can SET the layer as active if it is present
2) but if it is missing it will go ahead and create it then SET it.

It has a dual function, all in one.

Stop using SET only: start using MAKE instead.

Try again.

Message 5 of 6
miloRTZPE
in reply to: pendean

Oh my yes! I I understood it finally! sorry!

 

It worked! However, like you said it creates empty layers and colours them in - Is there a purge all command I can add at the end?

 

I tried something like 

 

-Purge

A

O

 

But the above didnt work - any suggestion?

 

Thank you!

Message 6 of 6
pendean
in reply to: miloRTZPE

PURGE command will not remove active/set layers: otherwise it works just fine.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report