Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all 12845 articles
Browse latest View live

Check the Destination Color Profile

$
0
0

Is it possible to check the Destination Color Profile of a PDF?  I have exported a PDF with a specific Destination color profile, but I can't include the profile. Preferably I would like to be able to check from within AI. I can't seem to find this info in the metadata, and, since it's not included, I can't simply check the colorProfileName property.


Finding open paths in Illustrator CC 2017

$
0
0

Does anyone know of a script to find open paths in Illustrator CC 2017? I finally sucked it it up and 'upgraded' to CC and now my old script won't work. Any help or suggestions is greatly appreciated.

What is between 'preserve' and 'embed' in an svg?

$
0
0

I have a script that reads a bunch of svg files that I've exported from a folder. I use the script to determine if the export settings were set correctly for what I want to do next with the files. One of the people I work with said that svg files we use for a project need to be exported with the setting 'preserve' as opposed to 'embed' for the purposes of the project we're working on, so I wanted to add this property to the list of things my script can detect about svg files. The problem is, that analyzing the string of the svg files, I can't find any difference between a file that I export with the 'embed' setting and a file that I export with the 'preserve' setting (under images on the svg export menu). I'm sure there has to be some difference, but I suspect that the difference might be something that wouldn't show up in all files necessarily, like how font settings require that there be a text frame to make any difference in the exported file. The general idea of my code is the following:

 

Determine if the svg uses layer names as id names:

 

var layer1 = app.activeDocument.layers[0].name;

var layerNameRegex = new RegExp(layer1);

layer = str.match(layerNameRegex).length > 0;

 

I just use regular expressions to determine if the properties are present. I'd like to do a similar thing to determine if 'preserve' is used once I figure out the difference and what the files are that will have the difference in them.

 

Thanks in advance, any help is appreciated.

Issue with selecting text generated from input dialog window

$
0
0

----------------------------------------------------

Main Issue & Details

----------------------------------------------------

Adobe Illustrator CC 2018 — Javascript

 

The sample code below:

 

  • Opens a dialog window with an input field for multi-line text.
  • After clicking "OK", a new text frame is generated with the contents from the input field.
  • Displays alert message with # of number items selected

 

It is actually selected because I can immediately move the text box with my keyboard arrow keys after it is generated, but for some reason, it is not being read as being selected by the script for some reason, which prevents me from continuing with the rest of my script.

 

When tested with alert( slct.length ); like in the example code below, it returns a value of 0, even though it is selected, as I've mentioned.

 

 

**EDIT (May 25, 2018)**

 

Adding a couple screenshots for reference.

 

The dialog box with the multi-line text input:

dialogTextSelectIssue-screenshot-01.png

 

 

After clicking "OK", the text frame is generated, and clearly selected—iindicated by the selection around the text frame on the top left (if you can see it) but also from the selection indicators in the layers panel—yet alert( slct.length ); returns a value of 0. So trying to do anything else with the script that requires a current selection does not work:

dialogTextSelectIssue-screenshot-02.png

 

**END EDIT**

 

 

----------------------------------------------------

Things I've tried

----------------------------------------------------

 

In the script below, I have a redundant selection just to make sure it is selected, but it doesn't work. I've tried both methods individually as well, but just left them both here in the code so you guys can see.

 

I tried throwing in app.redraw(); at different places in the code as well to see if that would help, but didn't seem to work.

 

I usually have been able to select text frames and objects with .selected = true or attaching an attribute note and selecting it looping through all items in the document to select anything with the note. And it gets read by the script and can continue on.

 

Again, both methods do actually end up with the item selected, but for some reason, neither methods seem to be read as selected by the script in this scenario, so I can't continue with anything else in the script afterward. So possibly a problem specific to text generated from a dialog window input field / ScriptUI.

 

I imagine I'm missing something very simple. Hope that is the case, anyway. Would greatly appreciate anyone taking the time to look into this and provide any solutions or suggestions!

 

 

----------------------------------------------------

Sample Code

----------------------------------------------------

 

if( app.activeDocument ){    var doc = app.activeDocument;    var slct = doc.selection;     // Create the Dialog Window:    var dialogWindow = new Window( "dialog", "Generate Text from Input" );    // Input Text Box Title    var inputTextBoxTitle = dialogWindow.add( "group" );    inputTextBoxTitle.alignment = "left";    inputTextBoxTitle.add( "statictext", undefined, "Generate Text from Input:" );    // Input Text Box    var inputTextBox = dialogWindow.add( "edittext", [0, 0, 300, 100], "Lorem ipsum line 1.\nLorem ipsum line 2.\nLorem ipsum line 3.", {multiline: true, wantReturn: true} ); // [ Left, Top, Width, Height ]    inputTextBox.active = true;    // Button Group    var buttonGroup = dialogWindow.add( "group" );    buttonGroup.alignment = "right";    buttonGroup.add( "button", undefined, "OK" );    buttonGroup.add( "button", undefined, "Cancel" );    // If user clicks "OK", generate new text frame from input text:    if (dialogWindow.show () == 1) {        var generatedText = doc.textFrames.add();        generatedText.contents = inputTextBox.text;        generatedText.top = 0;        generatedText.left = 0;        generatedText.selected = true;        generatedText.note = "GENERATED TEXT";        app.redraw();    }    // Redundant selection, just to make sure:    for( var i = 0; i < doc.pageItems.length; i++ ){        if( doc.pageItems[i].note === "GENERATED TEXT" ){            doc.pageItems[i].selected = true;        }    }    // Display alert message with # of items selected:    alert( "# of items selected (app.activeDocument.selection.length) = " + slct.length );

}

 

Message was edited by: Author

Is there a way to ungroup and skip group with appearances?

$
0
0

I'd like to ungroup all groups on a given layer, but skip those that have clipping masks, opacity masks, appearances, blending modes, effects etc. The goal for example  with this being to then be able to then run other scripts then be able to export page items to layers for photoshop export, and maintain the look of the graphic. The clipping attribute is easily accessible, as are opacity and blending but I'm not seeing any indication of opacity masks or at the very least appearances so I could skip the group. Are these attributes available? The quick draft of my script is:

lng = app.activeDocument.layers[0].pageItems.length;
lyr = app.activeDocument.layers[0];
for(i=lng-1; i>=0;i--){
if(lyr.pageItems[i].typename == "GroupItem"){    if(lyr.pageItems[i].clipped == true) continue;    app.activeDocument.selection = null;    lyr.pageItems[i].selected = true;    app.executeMenuCommand("ungroup");    i = app.activeDocument.layers[0].pageItems.length;
}
}


Is this possible to achieve with extendscript?

Duplicate a group of unlocked items to new layer. Lock previously duplicated layer.

$
0
0

Digging around the scripting forum I found some very useful info for doing this. However, i cannot get the second portion of my script to run correctly and cannot figure out why.

First off the second function "newlayerunlockitems" does not execute at all, i think due to the "cannot modify locked objects error" from the lock black function.

Anyways, the only way i can get the second function to work is by ungrouping the unlocked items and then running the function by itself.

The first function can pull the item out and to a new layer but the second cannot.

I have been trying to solve this for the past few hours and feel like its a very simple oversight that I just am not seeing.

 

function lockblack(){  
var docRef = app.activeDocument;  
var layers = docRef.layers;  
var myPaths = docRef.pathItems;  
var pathLen = myPaths.length;  
var myPath = null;  
var newGroup = docRef.groupItems.add();
newGroup.name = "Black";
newGroup.move =(docRef, ElementPlacement.PLACEATEND);
for(var x= pathLen-1;x>=0;x--)  
{  
myPath = myPaths[x];  
if(myPath.filled && myPath.fillColor.spot)  
{     if(myPath.fillColor.spot.name === "BLK")
{
myPath.move( newGroup, ElementPlacement.PLACEATEND);
newGroup.locked = true;
}  
}  
}  
}lockblack();
function newlayerunlockitems(){
var docRef = app.activeDocument;  
var myPageItems = docRef.pathItems;   
var layers = docRef.layers; 
var ublay = layers.add();
ublay.name = "UnderbaseLayer";
for (var b = docRef.layers.length - 1; b > 0; b--) {
if (docRef.layers[b].locked == false) {
for (var a = docRef.layers[b].pathItems.length - 1; a >= 0; a--) {
if (docRef.layers[b].pathItems[a].guides != true) {
docRef.layers[b].pathItems[a].locked = false;
docRef.layers[b].pathItems[a].duplicate(ublay, ElementPlacement.PLACEATBEGINNING)
docRef.layers[b].pathItems[a].locked = true;
}
}
}
}
}newlayerunlockitems();

Recaman Sequence Script

$
0
0

Hi there,

 

First time posting here so if theres a better way to embed the code let me know! I am trying to write a script that will generate the recaman sequence in Illustrator. This sequence can create a beautiful arrangement of looping lines. The rules are quite simple:

       an=an1±n

       The minus sign is preferred. It is used if the resulting anis positive and not already in the sequence; otherwise the plus sign is used.

    

In other words, you increase the stepsize by a value of 1 with each iteration, and each number can only be used once. Anytime you CAN reverse direction to access a lower number you must, otherwise go forward.

 

First 12 numbers of the sequence: 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22

 

Image result for recaman sequence

I don't have extensive experience with javascript, so I borrowed bits and pieces from different scripts and tweaked them to fit this purpose. The thing I struggled with was how to capture whether or not a value in the sequence had been "represented". I made an array to hold them, however I didn't know how to determine if an array index was empty or not... I used undefined?

Also, as best as I could figure out, its quite difficult to generate a half circle/curved path with a script, so this script will take a 10px half circle with no fill and use that as a seed object to generate the rest.

When I run the script, it seems to get stuck in a loop of moving the sequence backwards rather than jumping forward, not sure why?

 

Here's what I've done so far:

 

//This script requires that a half circle with a diameter of 10 is placed. Select that object, then execute this script

 

 

//SETUP

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

var doc = app.activeDocument;

var selected = doc.selection;

var selectedWidth = selected[0].width;

var repeatAmount,

      myInput,

      splitInput,

      margin,

      selectedPosition;

var numberline = new Array(115); //Array used as proxy numberline to determine whether a number has been represented in sequence

      var x; //index

      var flip;

 

 

// Run

userPrompt();

selectedPosition = selected.position;

var newItem = selected[0].duplicate( doc, ElementPlacement.PLACEATEND );

numberline[0] = 0;

numberline[1] = 1; //0 and 1 are already taken up due to intial seed object

 

 

 

 

for(i=0; i< repeatAmount ; i++){

// adjust size for next step in sequence. Dependent on intial seed object being halfcircle with height(5) and width(10)

    newItem.width = newItem.width + 10;

    newItem.height = newItem.height + 5;

 

 

//shift right

    if (i == 0){

      x = 1;

      flip =false;

    }

    if (flip == false){

    var newposx = newItem.position[0] + ((newItem.width - 10)/2) + (newItem.width/2) - 5;

  } else if (flip == true){

    var newposx = newItem.position[0];

  }

 

 

// counterbalance y position with change in height dimension

if (i%2==0 || i == 0) {

    var newposy = newItem.position[1] + ((newItem.height - 5)/2) + (newItem.height/2)+2.5;

 

 

  } else {

    var newposy = (newItem.position[1]) - ((newItem.height - 5)/2) - (newItem.height/2)+5;

  }

 

 

//check if sequence should reverse

y = x - (newItem.width/10);

x = newItem.width/10 + x;

 

 

if ((y > 0) && (numberline[y]==undefined)) {

  newposx = newposx - newItem.width;

  numberline[y] = y;

  x=y;

  flip = true;

}else{

  numberline[x] = x;

  flip = false;

}

 

 

// place object

    newItem.position = [newposx,newposy];

// flip orientation

    newItem.transform(app.getScaleMatrix(100,-100)); //H flip matrix - feel free to change to (-100,100) for horizontal flip, etc.

    doc.selection = null;

    newItem.selected = true;

    var selectedPosition = selected.position;

    newItem.duplicate( doc, ElementPlacement.PLACEATEND );

}

 

 

// Iterations of recaman sequence

function userPrompt(){

    myInput = prompt('How many iterations?','25');

    repeatAmount = Number(myInput);

}

dynamic action does not working in palate button script

$
0
0

Hi Friend's

 

My dynamic action does not work in palette button option but it is working in dialog option. i need to know what is the issues going on my script. kindly help to complete this script

 

Button Palette script:

 

#target illustrator-21
#targetengine main

var win = new Window('palette', '');  
var tpanel = win.add ("tabbedpanel");  
tpanel.alignChildren = ["fill", "fill"];  
tpanel.preferredSize = [100,20];  
win.margins = 0;  
win.spacing = 0;  
var subtab1panel = tpanel.add ("tab", undefined, "Diadeis Script Panel");  
subtab1panel.orientation="row";  
subtab1panel.alignChildren = ["fill", "fill"];      
var t1group = subtab1panel.add("group");  
t1group.orientation = "row";  
t1group.alignChildren = ["fill", "fill"];  

var pfad = "/Applications/Diadeis Scripts/"      
var btnSelect1 = t1group.add('button', undefined, 'Ai Compare Zoom');  
var scriptToLoad1 =  function()    {        var callFunction = matchZoom +  '\rmatchZoom();';        btMessaging( 'illustrator', callFunction );    }   


function matchZoom() 
{
    var doc0= app.activeDocument;    var zoom = doc0.activeView.zoom;    var ctrPoint = doc0.activeView.centerPoint;    var idoc;        if (app.documents.length>1) {        for (var d=1; d<app.documents.length; d++) {            idoc = app.documents[d];            idoc.activeView.zoom = zoom;            idoc.activeView.centerPoint = ctrPoint;        }    }
}

function btMessaging( target, callFunction ) {
    var bt = new BridgeTalk();    bt.target = target;    bt.body = callFunction;    bt.send();
}  
var btnSelect2 = t1group.add('button', undefined, 'CTC');   
var scriptToLoad2 = new File(pfad+"CTC.jsx");     
var btnSelect3 = t1group.add('button', undefined, 'CTC (for Ferrero)');   
var scriptToLoad3 = new File(pfad+"CTC_Ferrero.jsx");

var btnSelect4 = t1group.add('button', undefined, 'CLD Automation');   
var scriptToLoad4 = new File(pfad+"VariableImporter.jsx");     
btnSelect1.onClick = scriptToLoad1;      
btnSelect2.onClick = function(){           var des = scriptToLoad2;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function      btnSelect3.onClick = function(){           var des = scriptToLoad3;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function     btnSelect4.onClick = function(){           var des = scriptToLoad4;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function  

win.center();  
win.show();

 

Example linked script:

//////////////////////////////////////////////////////////////////////////////////////
//This script will generate a Live Ai file and CTC Ai file.                                                            //
// Display dialog events : Live Rasterize Effect Setting, Check Spelling, Launch Workflow.          //
//Cleanup Process : Unused Graphics Style, Unused Swatches,  Unsed Symbol.                           //
// Version : 1.0                                                                                                                  //
///////////////////////////////////////////////////////////////////////////////////

if ( app.documents.length == 1 )

{
// Rasterize Effect Setting 
app.executeMenuCommand('Live Rasterize Effect Setting'); 

//Unlock ("Background",  "Artwork") Layers
var aDoc = app.activeDocument;  
var myLayers = aDoc.layers;  
var actName = ("Background");  
try {      aDoc.activeLayer = myLayers.getByName (actName);      redraw();      actLayer = aDoc.activeLayer;      actLayer.locked = false;      actLayer.visible = true;      redraw();      }  
catch (e) {      alert ("Layer "+actName+" not found")      } 

var aDoc = app.activeDocument;  
var myLayers = aDoc.layers;  
var actName = ("Artwork");  
try {      aDoc.activeLayer = myLayers.getByName (actName);      redraw();      actLayer = aDoc.activeLayer;      actLayer.locked = false;      actLayer.visible = true;      redraw();      }  
catch (e) {      alert ("Layer "+actName+" not found")      } 

// Check Spelling  
app.executeMenuCommand('Check Spelling'); 

// Check Find and Replace  
app.executeMenuCommand('Find and Replace'); 

// Link Replace 
function linkReplacer() {       var orginalUIL = app.userInteractionLevel;       app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;       if (app.documents.length == 0) {            alert('Please have an "Illustrator" document open before running this script.');            return;       } else {            docRef = app.activeDocument;       }                var defaultFolder = new Folder (Folder(app.activeDocument.path + '/../040 Images/043 High Res'));       var psdFolder = defaultFolder;       if (psdFolder == null) return;              with (docRef) {            var placedFiles = new Array();            for (var i = 0; i < placedItems.length; i++) {                 placedFiles.push(placedItems[i].file.name);            }                        for (var j = 0; j < placedItems.length; j++) {                 var rePlace = new File(psdFolder.fsName + '/' + placedFiles[j]);                 if (rePlace.exists) {                      placedItems[j].file = rePlace;                 } else {                      alert('File "' + placedFiles[j] + '" is missing?');                 }            }       }       app.userInteractionLevel = orginalUIL;  
}      linkReplacer(); 

//Unlock all Layers
function unlockedSubLayers ( layers ) {      var i = layers.length;      if ( i ) {          while ( i-- ) {              layers[i].locked = false;              unlockedSubLayers( layers[i].layers );          }      }  
}  
unlockedSubLayers( activeDocument.layers );

//Empty text boxes are removed
app.executeMenuCommand('cleanup menu item');  

//Lock all Layers
function lockedSubLayers ( layers ) {      var i = layers.length;      if ( i ) {          while ( i-- ) {              layers[i].locked = true;              lockedSubLayers( layers[i].layers );          }      }  
}  
lockedSubLayers( activeDocument.layers );


//Cleanup Dynamic Action
 function createAction ( actionString, set ) {                    var fpath = Folder ( "~/Desktop/" )          var f = File ( fpath + set + '.aia' );                    f.open( 'w' );          f.write( actionString );          f.close();          app.loadAction( f );          f.remove();       } 

function runActionScript(){            var set = 'Cleanup';            var action = 'Delete Unused Panel Items';                    var actionString = [            
"/version 3",
"/name [ 7",
"    436c65616e7570",
"]",
"/isOpen 0",
"/actionCount 1",
"/action-1 {",
"    /name [ 25",
"        44656c65746520556e757365642050616e656c204974656d73",
"    ]",
"    /keyIndex 0",
"    /colorIndex 0",
"    /isOpen 1",
"    /eventCount 12",
"    /event-1 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_symbol_palette)",
"        /localizedName [ 7",
"            53796d626f6c73",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 4294967295",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 12",
"        }",
"    }",
"    /event-2 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_symbol_palette)",
"        /localizedName [ 7",
"            53796d626f6c73",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 4294967295",
"            /type (enumerated)",
"            /name [ 13",
"                44656c6574652053796d626f6c",
"            ]",
"            /value 5",
"        }",
"    }",
"    /event-3 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-4 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_styles)",
"        /localizedName [ 14",
"            47726170686963205374796c6573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 14",
"        }",
"    }",
"    /event-5 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_styles)",
"        /localizedName [ 14",
"            47726170686963205374796c6573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 12",
"                44656c657465205374796c65",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-6 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-7 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_brush)",
"        /localizedName [ 5",
"            4272757368",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 8",
"        }",
"    }",
"    /event-8 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_brush)",
"        /localizedName [ 5",
"            4272757368",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 12",
"                44656c657465204272757368",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-9 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-10 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_swatches)",
"        /localizedName [ 8",
"            5377617463686573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 11",
"        }",
"    }",
"    /event-11 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_swatches)",
"        /localizedName [ 8",
"            5377617463686573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 13",
"                44656c65746520537761746368",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-12 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"}"          ].join( "\n" );            createAction( actionString, set );            app.doScript( action, set );            app.unloadAction( set, "" );        }  

runActionScript();
    



//recurse Layers
function recurseLayers( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var v = objArray[i].visible;                      if ( !v ) objArray[i].visible = true;                              // Recurse the contained layer collection                      if ( objArray[i].layers.length > 0 ) {                                recurseLayers( objArray[i].layers )                      }                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].visible = v;            }  
};    
function recurseGroups( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                              // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].hidden = h;            }  
};  



// populate Live file.
for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = new File(workingDocFile.toString());           workingDoc.saveAs(aiFile);     }

// Text to Outline
function outlineDocText(  ) {              if ( app.documents.length == 0 ) return;        var docRef = app.activeDocument;                recurseLayers( docRef.layers );      
};    
outlineDocText();   



//recurse Layers
  
function recurseLayers( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var v = objArray[i].visible;                      if ( !v ) objArray[i].visible = true;                          outlineText( objArray[i].textFrames );                          // Recurse the contained layer collection                      if ( objArray[i].layers.length > 0 ) {                                recurseLayers( objArray[i].layers )                      }                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].visible = v;            }  
};    
function recurseGroups( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                          outlineText( objArray[i].textFrames );                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].hidden = h;            }  
};    



function outlineText( objArray ) {                // Reverse this loop as it brakes the indexing            for ( var i = objArray.length-1; i >= 0; i-- ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                          var g = objArray[i].createOutline(  );                          // Return new group to previous Text Frame values                      g.locked = l;                      g.hidden = h;                }    
}; 


// Menu Command of Find Font 
app.executeMenuCommand('Adobe Illustrator Find Font Menu Item'); 

// populate CTC file.

for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = new File(workingDocFile.toString().replace(".ai","_CTC.ai"));           workingDoc.saveAs(aiFile);     }                
for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = Folder (File(workingDocFile.toString().replace("_CTC.ai",".ai")));           app.open (aiFile);     }

 //Launch Workflow Dynamic Action
 function createAction1 ( actionString, set ) {                    var fpath = Folder ( "~/Desktop/" )          var f = File ( fpath + set + '.aia' );                    f.open( 'w' );          f.write( actionString );          f.close();          app.loadAction( f );          f.remove();       } 

function runActionScript1(){            var set = 'diadeis';            var action = 'Launch Workflow';                    var actionString = [            
"/version 3",
"/name [ 7",
"    64696164656973",
"]",
"/isOpen 1",
"/actionCount 1",
"/action-1 {",
"    /name [ 15",
"        4c61756e636820576f726b666c6f77",
"    ]",
"    /keyIndex 0",
"    /colorIndex 0",
"    /isOpen 0",
"    /eventCount 1",
"    /event-1 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_commandManager)",
"        /localizedName [ 16",
"            416363657373204d656e75204974656d",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 3",
"        /parameter-1 {",
"            /key 1769238125",
"            /showInPalette 4294967295",
"            /type (ustring)",
"            /value [ 18",
"                4c61756e636820576f726b666c6f772e2e2e",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1818455661",
"            /showInPalette 4294967295",
"            /type (ustring)",
"            /value [ 15",
"                4c61756e636820576f726b666c6f77",
"            ]",
"        }",
"        /parameter-3 {",
"            /key 1668114788",
"            /showInPalette 4294967295",
"            /type (integer)",
"            /value 2164260958",
"        }",
"    }",
"}"            ].join( "\n" );            createAction( actionString, set );            app.doScript( action, set );            app.unloadAction( set, "" );        }  

runActionScript1();

alert('Completed');
}
             else              {                               alert('Multiple Artworks are opened.\n Close all other reference files \n Expect Final artwork file');                  !  }

Thanks and regards.

Kalaimani.S


Recursive loop pageItems do not find all

$
0
0

Good day.

I'm newbie in scripting, and have a small problem:

 

When I recursive loop through pageItems, not all of them are seems to be selected.
Maybe anyone can point what I'm missing?

 

var recolorObj = [];
var getAllDocumentPathItems = function() {   var doc = app.activeDocument;   for (var n = 0; n < doc.pageItems.length; n++)  {        var obj = doc.pageItems[n];        if (!obj.editable || obj.locked) continue;        getAllPathItemsRecursive(obj);  }   return recolorObj;
};

var getAllPathItemsRecursive = function(obj, sourceColor) {
   switch (obj.typename) {        case "PathItem":             recolorObj.push(obj);        break;        case "CompoundPathItem":             for (var i = 0; i < obj.pathItems.length; i++) {                  getAllPathItemsRecursive(obj.pathItems[i], sourceColor);            }        break;        case "GroupItem":             // $.writeln("compoundPathItems: ", obj.compoundPathItems.length);            // $.writeln("pathItems: ", obj.pathItems.length);            // $.writeln("pageItems: ", obj.pageItems.length);            // $.writeln("graphItems: ", obj.graphItems.length); // 0            // $.writeln("groupItems: ", obj.groupItems.length);            // $.writeln("legacyTextItems: ", obj.legacyTextItems.length); // 0            // $.writeln("nonNativeItems: ", obj.nonNativeItems.length); // 0            // $.writeln("placedItems: ", obj.placedItems.length); // 0            // $.writeln("rasterItems: ", obj.rasterItems.length); // 0            // $.writeln("symbolItems: ", obj.symbolItems.length); // 0             for (var i1 = 0; i1 < obj.pathItems.length; i1++) {                  getAllPathItemsRecursive(obj.pathItems[i1], sourceColor);            }             for (var i2 = 0; i2 < obj.compoundPathItems.length; i2++) {                  getAllPathItemsRecursive(obj.compoundPathItems[i2], sourceColor);            }             for (var i3 = 0; i3 < obj.groupItems.length; i3++) {                  getAllPathItemsRecursive(obj.groupItems[i3], sourceColor);            }             for (var i4 = 0; i4 < obj.pageItems.length; i4++) {                  getAllPathItemsRecursive(obj.pageItems[i4], sourceColor);            }        break;        default:            $.writeln("[*] Ignored type: ", obj.typename);        break;  }
};

var reColor = function() {
   alert(recolorObj.length);   if (recolorObj.length === 0) {        getAllDocumentPathItems();  }   for (var i = 0; i < recolorObj.length; i++)  {        try {             recolorObj[i].filled = true;             recolorObj[i].stroked = true;             recolorObj[i].fillColor.gray = Math.round(Math.random() * (90 - 30) + 30);             recolorObj[i].strokeColor = Math.round(Math.random() * (90 - 30) + 30);       } catch(e) {            $.writeln(e, " [", recolorObj[i], "]");       }  }
};

reColor ();

 

Source:

source.png

Result:

result.png

How to encode non roman alphabet when exporting SVGs with ExtendScript

$
0
0

I want to encode non roman alphabets as greek, russian etc, when exporting SVGs, how could I achieve that with ExtendScript?

 

Thank you

Set Ruler Units

$
0
0

Hello!

I am trying to set the units of a new document I created so that when I open it again the ruler and default units will be in Inches.

if tried several things but seam to be stumped... can anyone help out?

 

example code of what I have tried

var newDoc = app.documents.add();

app.preferences.setIntegerPreference("rulerType",2);


app.preferences.setIntegerPreference("rulerType",2);

 

but no Matter what number I use the document is still in Points

"Save A Copy" scripting problem

$
0
0

I'm trying to create a "Save As PDF" script for Illustrator that will allow me to keep my active document as an Illustrator (.AI) file open.

 

In my workflow, I need to create compressed PDF version of my Illustrator file for clients, WHILE I'm working on an Illustrator file. In other words, I need to keep the .AI file open and have the .PDF file saved in the background.

 

Currently this is how I do this:

1. Choose "Save A Copy..."

2. Choose PDF

3. Choose PDF Preset from the drop-down menu.

4. Use the keyboard to delete " copy" which is automatically appended.

5. Choose "Save  PDF"

 

Of course I can easily just choose "Save As.." and choose pdf, but then my file is no longer an Illustrator (.ai) file.

I've been able to code a script which will automatically save my document as a pdf with a specific preset but it only works on the "Save As..." command. I need it to work on the "Save A Copy..." command. If I could just figure out a way to automatically remove the " copy" suffix that's automatically appended to the filename it would be a breeze.

 

Can you assist me in figuring this out?

Image Resolution - Text

$
0
0

Hi,

 

     Is there is any difference in illustrator for the below cases.

 

     1. Open pdf file which resolution is 400 in illustrator with the resolution 120 when open.

 

     2. Open pdf file which resolution is 400 in illustrator with the same resolution when open and then change the resolution to 120.

 

     Any difference in quality/display image?

 

    

     3. Is there is any version issue in lower and higher for the same process (point 1)?

 

 

Thanks,

Sudha K

an Illustrator error occurred: 1346458189 ('PARM')

$
0
0

Hello everyone,

 

I am trying to open some documents in Illustrator CS4 by javascript, walk through all layers including sublayers, doing something (for now just reading the layernames and showing them at an alert), closing the document and continue with the next document in the given folder until all documents in that folder are done.

 

By doing so I found an error I never have seen so far and I cant figure out where it comes from exactly to get rid of it.

The Error an Illustrator error occurred: 1346458189 ('PARM') appears randomly when cycling through the layers of the document but only every second document, so I guess there might be something wrong with closing a document and realeasing all references but I could not figure out what.

 

Maybe someone got an idea on this problem? Posting my sourcecode (just a simple test-code) below.

 

 

#target illustrator

 

var sourceFolderPath = "/e/TestAI";

var destinationFolderPath = "/e/TestZielverzeichnis";

var fileNameDefinition = "*.ai";

var sourceFolder = new Folder(sourceFolderPath);

var destinationFolder = new Folder(destinationFolderPath);

 

runCheckTool();

 

function runCheckTool() {

var contentInput = sourceFolder.getFiles(fileNameDefinition);

var fileRef;

var docRef;

for (var i = 0; i < contentInput.length; i++) {

fileRef = null;

docRef = null;

try {

fileRef = new File(contentInput[i]);

docRef = open(fileRef);

} catch(e) {

alert("# 1: " + e);

}

 

try{

checkLayers(docRef.layers);

} catch(e) {

alert("# 2: " + i + " " + e);

}

 

try {

docRef.close(SaveOptions.DONOTSAVECHANGES);

alert("end file index: " + i);

} catch(e) {

alert("#3: " + e);

}

}

}

 

function checkLayers(layerRef) {

var countLayers = layerRef.length;

for (var j = countLayers - 1; j >= 0; j--) {

if(layerRef[j].layers.length > 0) {

checkLayers(layerRef[j].layers);

}

alert ("Layer: " + layerRef[j].name);

}

}

 

 

Screenshot001.png

Trying to run a python script from extend script

$
0
0

Hello,

I'm currently working on an illustrator script in which i need to run a separate python script with parameters.

I'm creating a .bat file in the same folder as the .py script, if i double click this bat file it runs the python script as normal, but if the jsx tries to execute it, it sais it cannot find the .py file.

Here is me code:

 

var scriptFile = new File($.fileName);

var scriptPath = scriptFile.parent; // leads to /c/projects/TechArt/adobe/illustrator/Illustrator_preview_script

var myScriptPath = File(app.activeScript);

var myScriptName = myScriptPath.fullName; // Leads to /c/Program Files/Adobe/Adobe Illustrator CC 2017/Support Files/Content/Windows/tmp000000001

var os = $.os;

 

 

if (os.indexOf("Windows") >=0)

{

  var batPath = scriptPath + "/runPyScript.bat";

  var runFile = File(batPath);

  if (!runFile.exists)

  {

    runFile = new File(batPath); // Create the bat file

  }

  runFile.encoding = "UTF-8";

  runFile.lineFeed = "Windows";

  runFile.open("w");

  runFile.write("python thumbnail_shortcut_illustrator.py " + folderPath + "\npause"); // write to the bat file

  runFile.close();

  runFile.execute(); // execute the bat file

 

This is the result if i run the .jsx script:

CantRunt.jpg

And this is the result if i double click the bat file:

CanRun.jpg

 

Am confusion


relink script issue.

$
0
0

Hello, everyone.

 

I am writing the script for relinking on illustrator file. It is perfectly working on illustrator CC2014. but I got the issue on illustrator CC2017 and illustrator CC2018.

 

Note: I am mentioned manual link location and Script linked locations differ on link palate location. snapshot for your reference.

 

kindly advice how to mention the folder location in the script.

 

Issue reference:

 

Screen Shot 2018-11-26 at 9.31.00 PM.png

 

Folder structure reference:

 

Screen Shot 2018-11-26 at 9.41.54 PM.png

 

Script reference:

 

#target illustrator-21 

 

function linkReplacer() { 

     var orginalUIL = app.userInteractionLevel; 

     app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 

 

 

     if (app.documents.length == 0) { 

          alert('Please have an "Illustrator" document open before running this script.'); 

          return; 

     } else { 

          docRef = app.activeDocument; 

     } 

        

 

 

     var defaultFolder = new Folder (Folder(app.activeDocument.path + '/../040 Images/043 High Res')); 

     var psdFolder = defaultFolder; 

     if (psdFolder == null) return; 

      

     with (docRef) { 

          var placedFiles = new Array(); 

          for (var i = 0; i < placedItems.length; i++) { 

               placedFiles.push(placedItems[i].file.name); 

          } 

           

          for (var j = 0; j < placedItems.length; j++) { 

               var rePlace = new File(psdFolder.fsName + '/' + placedFiles[j]); 

               if (rePlace.exists) { 

                    placedItems[j].file = rePlace; 

               } else { 

                    alert('File "' + placedFiles[j] + '" is missing?'); 

               } 

          } 

     } 

     app.userInteractionLevel = orginalUIL; 

 

linkReplacer();

on event stop the script

$
0
0

Hi,

 

I would like a script 'any one' to have a feature stoppin the script when illustrator promt a warning that leads me to decide to stop the script.

 

JPD

How do I batch-rename objects/paths (not just layers)?

$
0
0

Question from a complete n00b:

 

I need to rename a large number of selected objects/paths. This is because I want to use another script that only works when my objects have the default name, "<Path>". So really, I just need to remove existing names of objects.

This other script is here:

http://kelsocartography.com/blog/?p=325

 

Of course, I could manually remove names by double-clicking on objects in the layers palette and deleting the name, but that's no fun.

 

I've found some great scripts for renaming layers, but nothing for non-layer objects.

 

First, I'm trying to remove names from ALL objects in the document.  once that's working, I want to only remove names of selected objects.

 

Here's my very simple non-working javascript - (the whole thing):

 

app.activeDocument.pageItem.name = "";

 

my test Ai file is also really basic: a few rectangles, some of which have been named in the layers palette.

 

When I run this, I get:

Error 21: undefined is not and object.

Line: 1

->     app.activeDocument.pageItem.name = "";

 

I've tried a number of other approaches, and either get "undefined is not an object" or nothing happens. 

 

pageItem has "name" as a writable property, so I think it's what to use, but I really don't know what I'm doing - help!

I'd also happy to use actions, but I'm stuck on that too.

Illustrator Script code for removing selected items

$
0
0

Hello, I have an Illustrator script to go through certain functions and after it runs there are items selected that I need deleted. I cannot figure out the simple script to remove the selected items. I tried

 

var docSelected = app.activeDocument.selection;

docSelected.selected.remove();

 

but to no avail. Please help. I would greatly appreciate any tips and suggestions as I just need to know how to have the script to delete selected items. Thank you very much!

ExtendScript try/catch difference when script ran from ESTK and Illustrator

$
0
0

Hello,

 

I've written an ExtendScript for Illustrator using the ExtendScript ToolKit (ESTK).  This scripts works really well when running it in Illustrator from the ESTK (using the target application functionality).

 

However when I run it directly within Illustrator (by selecting it from the dropdown File > Scripts) I get a run time error.  Is this normal?  Should I expect differences when running the script in these two different ways?

 

The error is in this function...

 

```

function itemUsable (arr, item) {

    var usable = true;

    try {

        arr[item];

        usable = true;

    } catch(e) {

        $.global.alert(e);

        usable = false;

    }

    return usable;

}

```

 

The point of the code is to get around Illustrator's issue of throwing errors when accessing properties that don't always exist.  Ran from ESTK the try/catch statement catches the error "No such element" and then sets the function to return false.

 

When ran directly from Illustrator the error message fires but the try/catch doesn't seem to stop the script from exiting.

 

The only difference I can see is when running the script from ESTK the dropdown menu next to the application target dropdown is always (and has only the option) "main".  Running the script directly from Illustrator, when the error is thrown this dropdown option is set to the value "transient".

 

See this screenshot for an example what I mean

 

Screen Shot 2015-04-16 at 20.16.32.png

 

Any help would be much appreciated.

 

Thanks,

/t

Viewing all 12845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>