Skip to main content
Participant
December 12, 2007
Question

getting spot color an making a list

  • December 12, 2007
  • 9 replies
  • 1026 views
Ok here is what i would like to do. I have a file with spot colors. I would like to script something so that a list is made with the name and a small square of color next to the corresponding color. I would like to it to do this for all the spot colors used in a document. I have to call out all the spot colors visually in each document. Possible? if show how do i figure out how to do it?
This topic has been closed for replies.

9 replies

Known Participant
May 24, 2008
Thanks for your response. How to delete the unused swatches through scripts. Please help me.

Thanks,
Prabudass
Participating Frequently
May 23, 2008
delete unused swatches (via action) and check swatch collection for colorType property.
Known Participant
May 23, 2008
I used the "spot color" and other color in illustrator file, in this case how can i get the spot color name which i used in that file. Please help me.

Prabudass
Participant
January 3, 2008
Before the holidays i worked on writing my own. The file zip HERE
is what i have so far. It does what i want it to but some times the fill doesn't work, the stroke on the box doesn't work, and i still have brackets on the names. How would i go about fixing/troubleshooting these issues?
JETalmage
Inspiring
December 29, 2007
Many thanks, RE. You explained it very well.

I was expecting that two things would cause the variable to be interpreted as a number: using the SwatchBoxTop variable as the top argument for the rectangle(), and using it in the expression with the + operator. I also thought that a variable value entered as a number woudl be interpreted as a number.

I will look into the parseInt and parseFloat functions and see if they can help me avoid this pitfall in the future.

JET
Participating Frequently
December 29, 2007
> So do you have any idea as to why it's failing to type the prompt value as a number? Javascript is supposed to recognize variable type by its context. I've used this kind of prompt for a numerical value in dozens of scripts without problem.

It's not really failing. It always accepts user input as a string. When later it needs to be reinterpreted as a number, JavaScript silently does so, and you're never the wiser.

The trouble with this particular script lies in a peculiarity in JavaScript's interpretation of the "+" operator. Namely:

b For + operators, if either argument is a String or converts preferentially to one, then it does string concatenation, not numeric addition.

In your script (uncommented to accept user input), swatchBoxSize is entered and recognized as a string (one way to verify this is to add the line

>alert(typeof swatchBoxSize);

after the input).

So, in line 24 (I'm counting all lines, including comments), when you say
> var swatchBoxTop=swatchBoxSize;

then the variable swatchBoxTop is also considered a string. Now, the problem line, number 38:

> swatchBoxTop+=(swatchBoxSize*1.25);

What is happening? swatchBoxSize is multiplied by 1.25. For this to happen, it is interpreted as a number, and the result is a number. But swatchBoxTop is still a string variable, and by the rule above, JavaScript uses "+" to do string concatenation! So if swatchBoxSize was 24, then the new value of swatchBoxTop is not 54, but 2430 ("24" + "30"). On the next pass, it becomes 243030, and so on. Note that all these values are successfully converted back to numbers. If you use a value not divisible by 4 -- say, 7 -- only two swatches will be drawn before you get an error: "Illegal Argument - argument 1 - Numeric value expected". This is because the values of swatchBoxTop progress like "7" "78.75" "78.758.75", the last of which cannot be reinterpreted as a number.

I can only assume that in other scripts you've fortuitously avoided this issue.

> Do you know if there is a way to explicitly declare a variable as an integer in Javascript, as one can in, say, Java?

JavaScript is loosely typed (while Java is strongly typed), so you can't force a variable to always be a certain type, no. However, search on the "parseInt" and "parseFloat" functions, which may help.

RE
JETalmage
Inspiring
December 29, 2007
Yep. That did it, RE. Thanks!

So do you have any idea as to why it's failing to type the prompt value as a number? Javascript is supposed to recognize variable type by its context. I've used this kind of prompt for a numerical value in dozens of scripts without problem.

Do you know if there is a way to explicitly declare a variable as an integer in Javascript, as one can in, say, Java?

Thanks again.

JET
Participating Frequently
December 29, 2007
JET,

Looks like the variable is not being interpreted as a number. If you use a temporary variable and force an arithmetic operation it works OK. E.g.:

var userSwatchBoxSize=Window.prompt("Enter the swatch box size in points:", 24);
var swatchBoxSize=userSwatchBoxSize/1

RE
JETalmage
Inspiring
December 28, 2007
This .zip archive contains a script that creates a "legend" of the Swatches in the current Swatches panel. For each Swatch, it creates a 24 pt square filled with the Swatch and a pointText label containing the name of the Swatch.

The script can be easily modified to create a legend for only spot colors by using docRef.spots instead of docRef.swatches. (In fact, I had it set that way originally, but decided I wanted it to list all named swatches, which is more useful to me.)

I encounted a puzzling problem with this, and would appreciate any knowledgeable insight:

When I try to let the user set the value of the swatchBoxSize variable in a prompt, rather than hard-coding the value (see the 2nd and 3rd line of the script), the resulting boxes and labels are spaced logarithmically, rather than uniformly, and therefore extend way beyond the bounds of the pasetboard. I don't understand why this occurs.

To see what I'm talking about, comment out the 2nd line and remove the comment slashes of the 3rd line. (I've only tried the script so far in Illustrator 13.0.0).

JET