Highlighted

How can I change ALL active document swatches from COLOUR TYPE - Process Colour to SPOT

New Here ,
Apr 11, 2019

Copy link to clipboard

Copied

Hi all,

This is my first foray into a forum, can anyone help?

I receive Autocad DWG dieline files (Saved in Autocad 2010 format) that I open directly into Illustrator. (Right click - open)

As part of my workflow I have to change all swatches in the active document to Spot colours.

The Operating system I'm using is Windows 10.

I'm using Illustrator 2019.

Can anyone offer any guidance or a solution on how I can automate this?

I use Illustrator actions a lot, but have never attempted to write any scripts yet -

but I feel I may need to on this one as actions commands don't seem to do do what I need.

All suggestions, guidance or scripts that can do this will be greatly appreciated.

Many thanks in advance.

Daryl.

Bonjour darylt44382031 ,

Je n'ai jamais été un fan d' AutoCad, trop complexe pour mes neurones mais j'avais conservé des documents DWG

sur un vieux disque dur (1992).

J'ai utilisé ENGIN.DWG pour faire un test, Le Cloud d'Orange
je suis parti dans une mauvaise direction avec :

  var swatch= activeDocument.swatches["AutoCAD Color 2"]

        swatch.colorType = ColorModel.SPOT;

qui ne donnait aucun résultat.

J'ai donc fait un script qui crée de nouvelles couleurs .SPOT à partir des couleurs existantes

et attribuer les nouvelles couleurs  correspondantes à chaque tracé.

Enfin supprimer les couleurs d'origine.

Comme la nuit porte conseil, le lendemain matin j'avais la solution que voici :

// JavaScript Document pour Illustrator

//processtospot_01.js

//Mon, 15 April 2019 09:00:59 GMT

// elleere Landry René

// Pour le document actif [0]

// convertir des spotColor Quadri (ColorModel.PROCESS) en Ton direct (ColorModel.SPOT)

// provenant d'AutoCAD Color Couleurs RVB

//-----------------

function processtospot() {

  var Spots, nbSpot,spt, swathsColorType;

      Spots = app.activeDocument.spots;

      nbSpot = Spots.length; //alert(nbSpot)

        for (var i = 0;  i < nbSpot; i++) {

          spt = Spots;

          swathsColorType = spt.colorType;

          //alert("swathColorType = "+swathsColorType);

            if (swathsColorType == ColorModel.PROCESS) {

              spt.colorType = ColorModel.SPOT;

            }

        }

}

//-----------------

if (app.documents.length) processtospot();

Si d'autres questions, me contacter par mail

De elleere

Topics

Scripting

Views

1.8K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How can I change ALL active document swatches from COLOUR TYPE - Process Colour to SPOT

New Here ,
Apr 11, 2019

Copy link to clipboard

Copied

Hi all,

This is my first foray into a forum, can anyone help?

I receive Autocad DWG dieline files (Saved in Autocad 2010 format) that I open directly into Illustrator. (Right click - open)

As part of my workflow I have to change all swatches in the active document to Spot colours.

The Operating system I'm using is Windows 10.

I'm using Illustrator 2019.

Can anyone offer any guidance or a solution on how I can automate this?

I use Illustrator actions a lot, but have never attempted to write any scripts yet -

but I feel I may need to on this one as actions commands don't seem to do do what I need.

All suggestions, guidance or scripts that can do this will be greatly appreciated.

Many thanks in advance.

Daryl.

Bonjour darylt44382031 ,

Je n'ai jamais été un fan d' AutoCad, trop complexe pour mes neurones mais j'avais conservé des documents DWG

sur un vieux disque dur (1992).

J'ai utilisé ENGIN.DWG pour faire un test, Le Cloud d'Orange
je suis parti dans une mauvaise direction avec :

  var swatch= activeDocument.swatches["AutoCAD Color 2"]

        swatch.colorType = ColorModel.SPOT;

qui ne donnait aucun résultat.

J'ai donc fait un script qui crée de nouvelles couleurs .SPOT à partir des couleurs existantes

et attribuer les nouvelles couleurs  correspondantes à chaque tracé.

Enfin supprimer les couleurs d'origine.

Comme la nuit porte conseil, le lendemain matin j'avais la solution que voici :

// JavaScript Document pour Illustrator

//processtospot_01.js

//Mon, 15 April 2019 09:00:59 GMT

// elleere Landry René

// Pour le document actif [0]

// convertir des spotColor Quadri (ColorModel.PROCESS) en Ton direct (ColorModel.SPOT)

// provenant d'AutoCAD Color Couleurs RVB

//-----------------

function processtospot() {

  var Spots, nbSpot,spt, swathsColorType;

      Spots = app.activeDocument.spots;

      nbSpot = Spots.length; //alert(nbSpot)

        for (var i = 0;  i < nbSpot; i++) {

          spt = Spots;

          swathsColorType = spt.colorType;

          //alert("swathColorType = "+swathsColorType);

            if (swathsColorType == ColorModel.PROCESS) {

              spt.colorType = ColorModel.SPOT;

            }

        }

}

//-----------------

if (app.documents.length) processtospot();

Si d'autres questions, me contacter par mail

De elleere

Topics

Scripting

Views

1.8K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Apr 12, 2019

Copy link to clipboard

Copied

So what is the method by which you convert all the colors to spots?

Do you have regularly-repeating colors which you can count on and a library of swatches, so you can use Recolor art feature?

I'm not exactly sure if that could be recorded as an action any kind of preset - which would if possible allow some sort of action automation in that regard - but assuming it's all non-recordable if this is a method you use then at least there's a starting point.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Apr 14, 2019

Copy link to clipboard

Copied

Hi Silly-V

I currently have to double click each individual swatch colour then select "spot colour" from the colour type menu. I've just found that I can shift select all swatches and then change the properties of all selected - using the same method which IS an improvement - but I'd still love the script if it could do it all!

In respect to colours - the layers used in autocad have colours associated with them on import; however the names of each layer (in autocad) get lost in translation somewhere between autocad and illustrator.

Layer names translate differently each time - but always appear in Illustrator in the format: AUTOCAD Colour 1,2,3 etc.

The only common translation between autocad and illustrator I have found is the RGB colour.

My Ideal world is to have a script that selects each swatch individually by an RGB attribute, then using that RGB attribute - the scrip would first change the "colour type" to "spot colour" then secondly change the "swatch Name" from whatever it has been named - to a logical name for that layer. eg: "cut" or "crease".

Autocad Layer names are changed on import into illustrator described above - however colours for the autocad layers always import with the following RGB values below:

LAYER NAME - RGB VALUES

Cut layer - 255,0,0

Crease   - 0,153,0

Bleed - 0,127,255

Dimensions - 0,255,0

Unprinted zone - 255,0,255

Lines - 0,0,0

Construction - 255,255,0

Corner datum - 0,255,255

10mm cut/crease - 0,0,255

2 x 2mm perforations - 254,191,16

The above layer list can vary sometimes, eg - sometimes there will be more or sometimes less layers.

it all depends upon the dieline requirements, the layers listed are the main ones used.

I don't know if it is possible for a script to do this
(including the chance that some layers may be present or not) ?

but if it was, this would save me the task of repeatedly doing this routine for every drawing I import.

I'd welcome your thoughts.

Thanks

Daryl

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Apr 15, 2019

Copy link to clipboard

Copied

Bonjour darylt44382031

Tu veux obtenir cela ? si oui, j'ai la solution.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Apr 15, 2019

Copy link to clipboard

Copied

Bonjour Renel,

Thank you for your reply and your time to help me with my challenge.

If you have a script that has found the RVB colour and is then ready for me to add my own name, then this may work for me.

Are you able to share how you achieved this solution with me?

Regards

Daryl

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Apr 16, 2019

Copy link to clipboard

Copied

Bonjour darylt44382031 ,

Je n'ai jamais été un fan d' AutoCad, trop complexe pour mes neurones mais j'avais conservé des documents DWG

sur un vieux disque dur (1992).

J'ai utilisé ENGIN.DWG pour faire un test, Le Cloud d'Orange
je suis parti dans une mauvaise direction avec :

  var swatch= activeDocument.swatches["AutoCAD Color 2"]

        swatch.colorType = ColorModel.SPOT;

qui ne donnait aucun résultat.

J'ai donc fait un script qui crée de nouvelles couleurs .SPOT à partir des couleurs existantes

et attribuer les nouvelles couleurs  correspondantes à chaque tracé.

Enfin supprimer les couleurs d'origine.

Comme la nuit porte conseil, le lendemain matin j'avais la solution que voici :

// JavaScript Document pour Illustrator

//processtospot_01.js

//Mon, 15 April 2019 09:00:59 GMT

// elleere Landry René

// Pour le document actif [0]

// convertir des spotColor Quadri (ColorModel.PROCESS) en Ton direct (ColorModel.SPOT)

// provenant d'AutoCAD Color Couleurs RVB

//-----------------

function processtospot() {

  var Spots, nbSpot,spt, swathsColorType;

      Spots = app.activeDocument.spots;

      nbSpot = Spots.length; //alert(nbSpot)

        for (var i = 0;  i < nbSpot; i++) {

          spt = Spots;

          swathsColorType = spt.colorType;

          //alert("swathColorType = "+swathsColorType);

            if (swathsColorType == ColorModel.PROCESS) {

              spt.colorType = ColorModel.SPOT;

            }

        }

}

//-----------------

if (app.documents.length) processtospot();

Si d'autres questions, me contacter par mail

De elleere

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Apr 16, 2019

Copy link to clipboard

Copied

Merci Renel,

vous avez un beau cerveau et une habileté pour le code java.

You have admirably answered my can I change all my colours to SPOT colour with a script.

My following code challenge to you would then be to search for the RGB / RVB values (listed earlier) in a document then name the swatches to "cut" "crease" etc if they were found in the document swatch list.

I would be very grateful if you could fathom this out.

regards

Daryl.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Apr 17, 2019

Copy link to clipboard

Copied

Bonjour darylt44382031 ,

Très heureux de donner satisfaction.

Je n'ai pas bien compris ta proposition,

le mieux serait de m'envoyer un mail avec un exemple

Avant et après.

Il ne devrait pas y avoir de difficulté.

Enregistré pour Ai version CS6 impératif.

A+

René

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 23, 2019

Copy link to clipboard

Copied

Hi Daryl,

after you turned all your colors to spots you could use method getInternalColor() that will return an array of numbers that reflect the color values internally used for that spot. Excatly what you need to see if an array like [255,0,0] is returned then rename the spot to "Cut".

To compare a string with an array of numbers you could use to the toString() method on the returned array.

Here some dummy code run on one spot color stored in variable mySpot to see the logic:

// Assumption, that there is a spot color:

var mySpot = app.activeDocument.spots[0];

// Data array of arrays that reflect color values and new color names

// Currently there is one entry for spot color "Cut".

var a = [ [ "255,0,0" , "Cut" ] ];

// Do the comparison with getInternalColor() that returns an array of numbers.

// If true rename the spot color:

if( a[0][0] == mySpot.getInternalColor().toString() ){ mySpot.name = a[0][1] };

Much better would be to build the data array this way:

var a = [];

a[ "255,0,0" ] = "Cut";

var mySpots = app.activeDocument.spots;

for( var n=0 ; n<mySpots.length; n++ )

{

    var internalColorString = mySpots.getInternalColor().toString();

   

    if( internalColorString in a )

    {

        mySpots.name = a[ internalColorString ];   

    };

   

};

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 23, 2019

Copy link to clipboard

Copied

Now you could simply expand the key/value pairs of array a to include more data:

var a = [];

a[ "255,0,0" ] = "Cut";

a[ "0,153,0" ] = "Crease";

a[ "0,127,255" ] = "Bleed";

a[ "0,255,0" ] = "Dimensions";

and so on.

The in operator of the if statement in the loop of my script snippet in my reply above will always look if a given color value ( as string ) is already in the array a and applies the given value for that key string, the new name of the spot.

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Apr 23, 2019

Copy link to clipboard

Copied

Hi Uwe,

Thank you very much for your direction and help,

I have populated all my RGB colours & names into your script framework below.

In Illustrator, after changing all my swatches to spot colour, I then ran your script.

However, when it's run, I receive this error message?

Once I click OK, I find that only the following colours have been renamed.

I have checked that all the RGB attributes are correct in Autocad (before saving),
then I checked again - when opened in Illustrator too.

As I'm VERY new to code, have I missed something?

Many thanks

Daryl

Here is the Illustrator - test file I have used

var a = [];

a[ "255,0,0" ] = "Cut";

a[ "0,153,0" ] = "Crease";

a[ "0,153,204" ] = "Bleed";

a[ "127,255,0" ] = "Dimensions";

a[ "114,0,153" ] = "Barcode_EAN_13";

a[ "153,0,204" ] = "Barcode_EAN_8";

a[ "255,255,0" ] = "Construction";

a[ "0,255,255" ] = "Corner_Datum";

a[ "127,127,255" ] = "Cut Crease_3x3mm";

a[ "153,102,204" ] = "Cut Crease_10x10mm";

a[ "0,0,0" ] = "Lines_and_points";

a[ "255,191,127" ] = "Perforate_2x2mm";

a[ "200,168,90" ] = "Perforate_10x10mm";

a[ "204,102,0" ] = "Score";

a[ "128,128,128" ] = "text";

a[ "255,0,255" ] = "Unprinted";

var mySpots = app.activeDocument.spots;

for( var n=0 ; n<mySpots.length; n++ )

{

    var internalColorString = mySpots.getInternalColor().toString();

   

    if( internalColorString in a )

    {

        mySpots.name = a[ internalColorString ];   

    };

   

};

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Apr 23, 2019

Copy link to clipboard

Copied

Bonjour darylt44382031,

Je n'ai pas de message d'erreur ?

Pour l'erreur : deux nuances ne peuvent pas avoir le même nom.

Voici la liste des couleurs internalColorString, avec cette méthode ne n'ai que 5 couleurs qui conviennent,

getInternalColor().toString();

126.999946832657,126.999946832657,255

255,191.000095009804,126.999946832657

153.000006079674,101.999993920326,204.000003039837

200.000064074993,168.000126779079,89.9999642372131

204.000003039837,101.999993920326,0

128.000053167343,128.000053167343,128.000053167343

0,153.000006079674,0

126.999946832657,255,0

0,153.000006079674,204.000003039837

114.000054001808,0,153.000006079674

153.000006079674,0,204.000003039837

255,255,0

0,255,255

255,0,0

0,0,0

255,0,255

100,100,100,100

Me contacter par mail

Enregistré pour Ai version CS6 impératif.

elleere

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 24, 2019

Copy link to clipboard

Copied

Hi Daryl,

as renél80416020 is showing, Illustrator's spot colors do not meet your expectations.

Some values are rounded if you look from the perspective of the UI.

That means:

1. Either you will round the values before you can do comparisons.

2. Or you rely on the unrounded values and implement them in your data set.

Option 2 might be unreliable, because you cannot be sure that the imported spots are always exactly the same.

Or Illustrator will round after the 12th digit after the dot and will do that differently with a different sample.

As I can see from your data set, there should be no error unless there is already a spot that you cannot rename that corresponds with an entry from the data set.

A function could be done that uses the next nabour of an existing spot's color value and apply the corresponding name.

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 24, 2019

Copy link to clipboard

Copied

If you loop all spot colors of your sample document and gather names and color values you see that two spots share the same color values. That special case is the cause of your error, I think. Spot named [Registration] cannot and should not be renamed.

AutoCAD Color    0,0,0

AutoCAD Color 10    127.000000029802,127.000000029802,255

AutoCAD Color 11    255,191.000003814697,127.000000029802

AutoCAD Color 12    255,255,0

AutoCAD Color 13    153.000006079674,102.000001519918,204.000003039837

AutoCAD Color 14    200.000003278255,168.000005185604,90.0000022351742

AutoCAD Color 15    204.000003039837,102.000001519918,0

AutoCAD Color 16    128.00000756979,128.00000756979,128.00000756979

AutoCAD Color 2    255,0,0

AutoCAD Color 3    0,153.000006079674,0

AutoCAD Color 4    255,0,255

AutoCAD Color 5    127.000000029802,255,0

AutoCAD Color 6    0,153.000006079674,204.000003039837

AutoCAD Color 7    0,255,255

AutoCAD Color 8    114.000000804663,0,153.000006079674

AutoCAD Color 9    153.000006079674,0,204.000003039837

[Registration]    0,0,0

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 24, 2019

Copy link to clipboard

Copied

FWIW: I think, that spot [Regstration] should be a category of its own, not a spot color. But apparently this is by design in Illustrator. Not so e.g. with InDesign. You can deal with that by asking the name of a spot in your loop and exclude [Registration] if found.

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Apr 24, 2019

Copy link to clipboard

Copied

Bonjour,

Pour passer [Registration] car il est possible de le renommer mais pas le supprimer.

if( mySpots.colorType == ColorModel.REGISTRATION){continue;}

Résultat obtenu avec deux méthodes différentes,

dont celle très élégante de Laubender

Me contacter par mail

Enregistré pour Ai version CS6 impératif, pour d'autres exemples.

elleere

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 24, 2019

Copy link to clipboard

Copied

Hi René,

thank you for pointing out that spot [Registration] indeed can be renamed.

FWIW: Another big difference to InDesign.

Thanks,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 25, 2019

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 11, 2020

Copy link to clipboard

Copied

Hello, René!

How are you?

 I ran that script on Illustrator 2020 and I got an Error when Illustrator gets the line with this code: "spt.colorType". Illustrator says something like "No such element". It looks like the Error is related to "colorType".

 

 I will wait for your answer.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Enthusiast ,
Jun 12, 2020

Copy link to clipboard

Copied

Salut Robsmith01!

C'est normal la ligne 14 est incomplète.

spt = Spots[i];

De elleere

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 12, 2020

Copy link to clipboard

Copied

Hello!

You are right.

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...