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

Using action to run a javascript script causes crash

New Here ,
Nov 06, 2022 Nov 06, 2022

I want fast accessability to a specific script, but running it through the actions menu crashes Illustator. However, running it through the scripts menu does not.

After logging to debug the script I found that the script only crashes when I play actions with app.doScript(), otherwise everything works fine.

 

Here's a copy of the script (I am using Illustrator v25.0):

 

workDoc = app.documents[0];
exportDoc = app.documents["Export.ai"];

artNames = []; //for renaming art


function deselect () {
app.executeMenuCommand("deselectall");
}


function selectAll(type) {
if (type == "compoundPaths") {
for (item=0; item < app.activeDocument.activeLayer.compoundPathItems.length; item++) {
app.activeDocument.activeLayer.compoundPathItems[item].selected = true;
}
} else if(type == "textFrames") {
for (item = 0; item < app.activeDocument.activeLayer.textFrames.length; item++) {
app.activeDocument.activeLayer.textFrames[item].selected = true;
}
} else if(type == "paths") {
for (item = 0; item < app.activeDocument.activeLayer.pathItems.length; item++) {
app.activeDocument.activeLayer.pathItems[item].selected = true;
}
} else if(type == "groups") {
for (item = 0; item < app.activeDocument.activeLayer.groupItems.length; item++) {
app.activeDocument.activeLayer.groupItems[item].selected = true;
}
}
}

for (layer = 0; layer < workDoc.layers.length - 1; layer++) { //cycling through each layer for visible designs
if (workDoc.layers[layer].visible == true) {
app.activeDocument = workDoc;
workDoc.activeLayer = workDoc.layers[layer];


//dup art
for (art = 0; art < workDoc.layers[layer].layers["Design"].compoundPathItems.length; art++) {
if (workDoc.layers[layer].layers["Design"].compoundPathItems[art].hidden == false) {
app.activeDocument = workDoc;
deselect();

//duplicate artwork
workDoc.layers[layer].layers["Design"].compoundPathItems[art].duplicate(exportDoc.layers["Design"]);

//note art name
artNames.push(workDoc.layers[layer].layers["Design"].compoundPathItems[art].name);
}

}


//dup text
app.activeDocument = workDoc;
workDoc.activeLayer = workDoc.layers[layer];

for (text = 0; text < workDoc.layers[layer].layers["Font"].textFrames.length; text++) {
if (workDoc.layers[layer].layers["Font"].textFrames[text].hidden == false) {
app.activeDocument = workDoc;
deselect();

//duplicate text
workDoc.layers[layer].layers["Font"].textFrames[text].duplicate(exportDoc.layers["Design"]); //for pathfinder
workDoc.layers[layer].layers["Font"].textFrames[text].duplicate(exportDoc.layers["Font"]); //for export
}

}
}
}


//outline and offset text
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Design"];

deselect();
selectAll("textFrames");

for (text=0; text < exportDoc.layers["Design"].textFrames.length; text++) {
exportDoc.layers["Design"].textFrames[text].createOutline();
}
app.doScript("offset", "trueOutline"); //<-- crash


//copy offset text
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Design"];

deselect();
selectAll("paths");
exportDoc.layers["Design"].groupItems[0].duplicate(exportDoc.layers["Font"]); //held temp


//cleanup text
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Design"];

deselect();
selectAll("groups");
for (sel=0; sel < exportDoc.selection.length; sel++) {
exportDoc.selection[0].remove();
}


//pathfinder
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Design"];

for (art = 0; art < exportDoc.layers["Design"].compoundPathItems.length; art++) {
deselect();
exportDoc.layers["Design"].compoundPathItems[art].selected = true;

for (text = 0; text < exportDoc.layers["Font"].groupItems.length; text++) {
exportDoc.layers["Font"].groupItems[text].duplicate(exportDoc.layers["Design"]);
exportDoc.layers["Design"].groupItems[0].selected = true;
}

//app.executeMenuCommand("Live Minus Front"); //throws error
app.doScript("minusFront", "trueOutline"); //<-- crash
}


//cleanup temp offset text
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Font"];

deselect();
selectAll("groups");
for (sel=0; sel < exportDoc.selection.length; sel++) {
exportDoc.selection[0].remove();
}


//outline export text
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Font"];

exportDoc.layers["Font"].textFrames[0].createOutline();


//rename art
app.activeDocument = exportDoc;
exportDoc.activeLayer = exportDoc.layers["Font"];

for (art = 0; art < artNames.length; art++) {
exportDoc.layers["Design"].pageItems[art].name = artNames[art];
}

 

 

And these are my docs:

Illustrator_YwUbdYkFuF.pngexpand image

Illustrator_IgxM5runNT.pngexpand image

Any ideas for a solution, or is there another way to use a shortcut for running the script?

TOPICS
Scripting
220
Translate
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
Adobe
Advisor ,
Nov 06, 2022 Nov 06, 2022

Hello @endlessnugget 

 

See the link below for a possible alternative solution, there's both Mac and PC options discussed...

https://graphicdesign.stackexchange.com/questions/63439/how-to-set-keyboard-shortcut-to-run-script-i...

 

Regards,

Mike

Translate
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 ,
Nov 06, 2022 Nov 06, 2022
LATEST

Yep, it is best to run the script via a 3rd party solution. You can read more about why here.

Translate
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