• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Illustrator Scripting help

Explorer ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

So with the help of the wonderful Adobe community I put together this script.

try { var newSpot = app.activeDocument.swatches.getByName("CutContour")}

catch (e) {

var newSpot = app.activeDocument.spots.add();

var newColor = new CMYKColor();

newColor.cyan = 0;

newColor.magenta = 100;

newColor.yellow = 0;

newColor.black = 0;

newSpot.name = "CutContour";

newSpot.colorType = ColorModel.SPOT;

newSpot.color = newColor;

var newSpotColor = new SpotColor();

newSpotColor = newSpot;

newSpotColor.tint = 100; 
 }

var _sel = app.activeDocument;
var spotColor = app.activeDocument.swatches.getByName('CutContour');
    _sel.stroked = true;
    _sel.layers[0].pathItems[2].strokeColor = spotColor.color; 
  

What i need help with is eclosing that last part in a for loop and replacing the 2 with a counter.

for (var i=0;i=<2;i++){
 _sel.stroked = true;
 _sel.layers[0].pathItems[i].strokeColor = spotColor.color;
}

 Like so. However this gives me the error that the compiler expected a { at line 3 in the above snipit.

can somone please tell me what I'm doing wrong. I'd greatly appreciate it.

TOPICS
Scripting

Views

320

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
community guidelines

correct answers 1 Correct answer

Explorer , Mar 18, 2021 Mar 18, 2021

Fixed it. Don't know why but I worked when I replaced "i" with "cnt" and

cnt =< 2

with

cnt < _sel.layers[0].pathItems.length

 

Votes

Translate

Translate
Adobe
Explorer ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

Fixed it. Don't know why but I worked when I replaced "i" with "cnt" and

cnt =< 2

with

cnt < _sel.layers[0].pathItems.length

 

Votes

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
community guidelines
Community Expert ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

i think the problem was in your for loop. in the loop condition, you have this:

 

i =< 2

 

instead of this:

 

i <= 2

 

edit for more clarification. As soon as the interpreter sees the "=" sign, it starts looking for a value to assign to the variable that came before it. in this case, your code is attempting to set the value of "i" to "<" which is invalid.

In order to check for less then or equal to, the less than must come first (likewise for >=, the equal sign needs to come at the end).

 

Votes

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
community guidelines
Explorer ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

Yeah, that was my initial instinct too, but with both "<=" and "=<" I got the "expected {" error. Might have done somthing else wrong though.

Votes

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
community guidelines
Explorer ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

Apologies "}" not "{"

Votes

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
community guidelines
Community Expert ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

there was nothing else wrong in the code you posted above.. i just tested this loop (which i copied and pasted from above, and flipped the >= to <=) and it worked just fine.

 

 

for (var i=0;i<=2;i++){
    //_sel.stroked = true;
    //_sel.layers[0].pathItems[i].strokeColor = spotColor.color;
    $.writeln("i = " + i);
}

 

 

edit.. it's possible you put a comma somewhere where there should have been a semicolon? like this:

for(var i=0;i<=2,i++)

i've done that loads of times and i think that would give you the same error.

Votes

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
community guidelines
Explorer ,
Mar 19, 2021 Mar 19, 2021

Copy link to clipboard

Copied

LATEST

Yeah that sounds about right. Thanks for the contribution.

Votes

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
community guidelines