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

JS - Center Selection to Artboard / New Document with certain Artboard size

$
0
0

TL;DR:

how do I center my current selection to the artboard?

just like hitting the "horizontal align-center" and "vertical align-center" buttons.

 

 

Hi,

 

I've been searching for the last two hours and before my head hits the keyboard I wanted to ask you for help.

 

What I'm struggling with:

in my init function i create a new document and then copy all layers from the previous document step by step to the new document and then save it as SVG.

 

// Init

(function(){

          destination = Folder.selectDialog('Select folder for SVG files.', docPath);

          if (!destination){return;}

          holderDoc = app.documents.add();

          stepThroughAndExportLayers(docRef.layers);

}());

 

my problem is that holderDoc = app.documents.add(); always creates a document that is not the same size as my initial document where the layers get copied from.

 

so I want the exact same artboard size as in my initial document.

I'm fine with either doing it as fixed values or taking directly the values of the inital doc.

 

i tried this in the segment where I create the new document:

 

// Init

(function(){

  destination = Folder.selectDialog('Select folder for SVG files.', docPath);

  if (!destination){return;}

  holderDoc = app.documents.add();

  holderDoc.artboards[0].artboardRect = [0,0,128,128];

  stepThroughAndExportLayers(docRef.layers);

}());

 

and get this error message:

"Error 1200: an Illustrator error occured: 1346458189 ('PARM')

Line: 83

-> holderDoc.artboards[0].artboardRect = [0,0,128,128];"

 

which from what I've read on the web means that illustrator doesnt know what document to pick. but i have called it directly. so what could be the issue?

 

to clearify: I do not want to fit the artboard to the images/layer. the artboard should always have a certain size. (for me 128px by 128px)

 

I would highly appreciate you helping me with either fixing my approach or propose a completely new one.

Thanks so much in advance.

 

// edit: workaround


(function(){

          destination = Folder.selectDialog('Select folder for SVG files.', docPath);

          if (!destination){return;}

          var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];

          var ABRect = activeArtboard.artboardRect;

          holderDoc = app.documents.add();

          holderDoc.artboards.add(ABRect);

          holderDoc.artboards.remove(0);

          holderDoc.artboards.setActiveArtboardIndex(0);

          //stepThroughAndExportLayers(docRef.layers);

}());

 

i now added a new artboard to the new document with the same size as the artboard on the initial document.

i remove the predefined artboard on the new doc and set the new artboard as active.

BUT!

the artboard is now not centered into the window. which lets illustrator place my image with ctrl+c -> ctrl+v somewhere outside the artboard.

 

i now need to align my selection to the center of the artboard. but i cant find any reference on how to center a selection to the artboard.


Set unit preferences (Javascript)

$
0
0

I can't find a way to set the unit preferences for Illustrator CS6/CC using JavaScript.

 

I found that this works (setting units for stroke):

var units = 2; // 0-inches, 1-milllimeters, 2-points

app.preferences.setIntegerPreference("strokeUnits", units)

 

But I want to set the ruler units ("General" in the interface), and this does not work:

app.preferences.setIntegerPreference("rulerUnits", units)

 

Any help?

Peter

Exporting Adobe Illustrator XMP Data

$
0
0

Hello,

 

My biggest problem is that doesn't know how to write script. Can anyone kind enough to enlighten me with a ExtendScript to export Adobe illustrator XMP data into a xml file please?


Regards,

Jeno

Applescript: "execute menu command" syntax

$
0
0

Greetings,

 

Anyone know the syntax for using:

 

execute menu commandv : executes a menu command using the menu shortcut string

 

execute menu command

menu command stringtext : menu command shortcut

 

I can't figure out what string to use for the "menu command string" argument.

 

Thanks!

How to save a pdf to the desktop?

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

How convert Matrix to Rotate?

$
0
0

Example:

Value of Matrix of TextFrame:

MValueA=0.707110047340393

MValueB=0.707110047340393

MValueC=-0.707110047340393

MValueD=0.707110047340393

MValueTX=-11116.84375

MValueTY=-281.0703125

How convert Matrix to Rotate?

Does anybody know how to remove all "copy" word from AI layers name line?

$
0
0

I downloaded a PSD script that auto remove the word "copy" from all layers. Inside AI, I can't do that. Does anyone can help me? Here is the jsx PSD script file:

 

----------

 

///////////////////////////////////////////////////////////////////////////////
// Script Name: RenameLayers.jsx
// Version: 1.0
// Date: 2/27/08
// Usage: Removes 'copy 1, copy 2, etc' from name of all layers
///////////////////////////////////////////////////////////////////////////////

 

#target photoshop
//$.localize = true;
var displayDialogMode = app.displayDialogs;

 

app.bringToFront();
app.bringToFront();
app.displayDialogs = DialogModes.NO;

 

processObjects(app.documents, processDocument,function () {alert("You have no documents open")})
app.displayDialogs = displayDialogMode;

 

///////////////////////////////////////////////////////////////////////////////
// Function: processObjects
// Usage: Runs theMainFunction on every object in list theObjects
// Input: List of objects (documents, layers, etc.), Function to run on each object, Function to run on parent if there are no object
// Return: value returned from function used
///////////////////////////////////////////////////////////////////////////////
function processObjects(theObjects, theMainFunction, theAlternateFunction) {
var returnValue = null;
if (theObjects.length ==0) {
if (!(theAlternateFunction == undefined) && !(theAlternateFunction == null) && !(theAlternateFunction == "")) {
returnValue = theAlternateFunction (theObjects.parent);
}
} else {
if (!(theMainFunction == undefined) && !(theMainFunction == null) && !(theMainFunction == "")) {
for (var i = theObjects.length -1; i> -1; i--) {
returnValue += theMainFunction (theObjects[i], i);
}
}
}
return returnValue;
}

 

///////////////////////////////////////////////////////////////////////////////
// Function: processDocument
// Usage: Processes layers of document with 'processLayer' function
// Input: Document object, Document object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function processDocument(objectRef, i) {
app.activeDocument = objectRef
processObjects(objectRef.layers, processLayer, null);
}

 

///////////////////////////////////////////////////////////////////////////////
// Function: processLayer
// Usage: Removes 'copy' from layer name (processes Layer Set contents)
// Input: Layer object, Layer Object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function processLayer(objectRef, i) {
if (objectRef.typename == 'LayerSet') {
var layerCount = processObjects(objectRef.layers, processLayer);
}
renameLayer(objectRef)
return 0
}

 

///////////////////////////////////////////////////////////////////////////////
// Function: renameLayer
// Usage: Removes 'copy' from layer name (processes Layer Set contents)
// Input: Layer object, Layer Object index
// Return: none
///////////////////////////////////////////////////////////////////////////////
function renameLayer(objectRef) {
var theRegEx = new RegExp(/(\s*copy\s*\d*)+$/)

 

if (theRegEx.test(objectRef.name)) {
// save state of layer (visible or invisible)
var layerVisible = objectRef.visible
var indexNumber = 0
indexnumber = objectRef.name.indexOf(" copy")
objectRef.name = objectRef.name.substr(0,indexnumber)
objectRef.visible = layerVisible
}
return 0
}


----------

 

Anyone?


Reworking Photoshop layer renaming script for Illustrator

$
0
0

The Photoshop scripting guru Paul R over at RetouchPro has created a really cool script to batch rename and number selected Photoshop layers. I haven't found anything similar on the Illustrator side.

 

He's given permission for me to post it here in my hopes that some Illustrator scripting genius could come up with a similar script for Illustrator. Would it be terribly difficult to convert this into something Illustrator could use?

 

http://www.mediafire.com/file/g7usr73u0236p0a/Rename_&_Renumber_Selected_Layers.jsx

 

http://www.mediafire.com/file/dbah74x13bsa74c/Rename_&_Renumber_Selected_Layers.jsx.zip

 

rename-layers.png

applescript for saving ai files to pdf with specific preset not working

$
0
0

Hello all,

my applescript for saving ai files to pdf with my specific preset (A1) not working anymore (after installing cc 2014)

it worked for years .....

I need to work in CS6 still so I have both ai's on my machine

I copied my specific PDF preset in all PDF preset folders on my sysytem

It seems that the script doesn't find my specific pdf preset anymore

Is this still a bug ?

 

I get a illustrator error report 1129270854 ('FNOC')

 

The script:

-- fileList is a list of aliases to Illustrator files

-- destFolder is an alias to a folder where PDF files are saved

on SaveFilesAsPDF(fileList, destFolder)

    set destPath to destFolder as Unicode text

    repeat with aFile in fileList

        tell application "Finder" to set fileName to name of aFile

        set newFilePath to destPath & fileName

        tell application "Adobe Illustrator"

            open aFile

            save current document in file newFilePath as pdf with options {class:PDF save options, PDF preset:"A1"}

            close current document saving no

        end tell

    end repeat

end SaveFilesAsPDF

-- Call handler

set sourceFolder to choose folder with prompt "Source folder?"

tell application "Finder" to set fileList to every file of folder sourceFolder as alias list

set destFolder to choose folder with prompt "Destination folder?"

SaveFilesAsPDF(fileList, destFolder)

 

Why is it not working anymore, anyone?

thank you

pat

A Script to Find and Replace Layer Names

$
0
0

Are there any scripts to find and replace layer names?

 

There is an excellent script available for Photoshop which allows you to not only replace words in layer names, but also insert words as Prefixes, Suffixes and Sequential Numbers.

The illustrator version of this script only allows sequential numbering: It doesn't offer find and replacing of words.

 

Ideally, it would be great if there was something that could do multiple find and replaces in one go:

(e.g.

You have layers like this Car, Dog, Bat

You enter: car(Option1), dog(Option2), Bat(Option3)

Your layers then become: Option1, Option2, Option3).

)

Giving Opacity the same value as fill color (Inverting Opacity/Fill)

$
0
0

I am looking to add a script that would take the fill value of swatches in my art file, and apply those values to the opacity of each swatch.  I would also like to be able to adjust the fill value to be 100% when finished.  I have a javascript that I thought would work, but it has no effect on any of the objects in the file.

 

Example:

Original Art: Object 1: Fill 50%, Opacity 100% // Object 2: Fill 60%, Opacity 100%

Desired Result: Object 1: Fill 100%, Opacity 50% // Object 2: Fill 100%, Opacity 60%

 

Any help would be much appreciated.

Anti-aliasing Type Optimized/Art Optimized on PNG export

$
0
0

Hello there,

 

I'm modifying a javascript that makes an export of each layer contained in an Illustrator document and I want to specify the method used for anti-aliasing (either Type Optimized or Art Optimized). Similarly to the option under the "Image size" tab in the "Save for the Web" panel.

 

I didn't find any antiAliasingMethod property in the ExportOptionsPNG24 properties (only an antiAliasing property that accepts boolean). So I wonder if it is actually possible to do it through scripting?

 

Many thanks,

D

VBS - selecting loaded Dataset

$
0
0

Hello Everyone,

 

I been long time reader of this forum, you guys are great.

 

I created a little script that loads Dataset in to a chart, but I have to go then and manually pick the Datset from drop down menu.

 

Is there a simple command to set DATASET to XXXX and refresh chart in VBS ?

 

All the help is appreciated.

Javascript to determine named fill/stroke color of pathItem[index]?

$
0
0

I'm attempting to build a preflight of sorts for my Illustrator workflow (since for some reason.. preflight in illustrator doesn't exist...).

 

Essentially i need to loop through the pathItems on each artboard looking for a specific spot color (first verifying that the spot color does NOT exist as a fill color in any of the artwork, then checking for the presence of any pathItem that contains the spot color as a stroke).

 

This seemed to be a really straightforward task, but it seems as though pathItems.fillColor or pathItems.strokeColor is not a valid property? That confuses me because it works to apply a color to a pathItem.. It seems to me if you can apply a color via pathItems.fillColor, you should also be able to create an if clause that determines whether pathItems.fillColor == (some color). However, while testing this in the simplest of documents wherein i know what the result of the if clause should be, it doesn't work. is there something I'm missing here about the property fillColor/strokeColor??

 

Here's the code I'm working with. Thanks, all.

 

#target Illustrator




var docRef = app.activeDocument;
var aB = docRef.artboards;
var swatchList = docRef.swatches;
var tC = swatchList.getByName("Thru-cut");
var tCCount = 0; //how many artboards/top level groups contain at least 1 Thru-cut stroke?
var artLayers = docRef.layers;
var groups = artLayers[0].groupItems;
var aBtCCount = 0; // how many artboards have
var aBnoTC = []; //  which artboards/top level groups (by index) do not contain at least 1 Thru-cut stroke?


for (a = 0; a < aB.length; a++){    aBtCCount = 0    var items = groups[a].pathItems;    for (b = 0; b < items.length; b ++){        if (items[b].fillColor == swatchList.getByName("Thru-cut")){            alert("You have Thru-cut fills in your document!!");            break;            } //end if // thru-cut is fill        else if (items[b].strokeColor == swatchList.getByName("Thru-cut")){            tCCount++;            break;            } //end if // thru-cut is stroke        else{            tCCount = 0;            } //end else // set counter to 0        }//end for loop B // checking items on each artboard    if(tCCount == 0){        aBnoTC.push(" " + a);        }//end if // artboard has no cut line    else{        aBtCCount++;        }//end else // add to counter for total artboards w/ thru-cut    alert(tCCount);           }//end for loop A


if (aBtCCount < aB.length){    alert("Artboard/s " + aBnoTC + " are missing Thru-cut lines");    }//end if // not enough cut lines   

Open multi-page PDF in Illustrator

$
0
0

Does anyone know of a script that would allow Illustrator CS4 to open all pages of a PDF, instead of opening one page of the PDF at a time?

How to reflect in script?

$
0
0
Hi,

I want the equivalent of choosing Object > Transform > Reflect, across the Vertical axis. How would I do this with JavaScript?

Thanks,

Max

Need script to batch convert vector .eps to .png images with scale

$
0
0

Hi,

 

I'm looking for a script/program that if you run it, all the .eps files in a folder will batch convert to a png-24 with 250% scale.

 

Erdem

XMP - Add keywords with script

$
0
0

Hallo Forum,

 

I would create a script to have keyword standards.

 

In EXCEL i create a controlled namespace trougth comboboxes to save the files in an controlled way. The Metadata should be a controlled way to avoid "phantasie"-names. Having this values I would insert this strings in the XMP:KEYWORD field. In this way with the bridge I can retrive the information.

 

xmp.string = word1, word2, word3, ...

 

I use VBA and at the moment I have this but it doesn't work.

 

Sub meta_add ()

dim w1 as string

w1 = "hallo world"

document.xmpString.add.w1

end sub

 

Somebody can help me with the basic? JAVA would be welcomed too !!!

Thank you

Form.JPG

finding the matrix info on a text frame?

$
0
0

I wanted to understand the matrix values and methods so I could make a script to select or not select textframes that are angled.

Can anyone explain this matrix stuff to me?

 

This script is the only example I have found so far.

if ( app.documents.length > 0 ) {

var moveMatrix = app.getIdentityMatrix( 0.5, 1.5 );

var totalMatrix = concatenateRotationMatrix( moveMatrix, 10 );

var doc = app.activeDocument.activeLayer;

for ( i = 0; i < doc.pageItems.length; i++ ) {

doc.pageItems[i].transform( totalMatrix );

}

}

 

Im thinking I need to use getRotationMatrix([angle])

any help would be greatly appreciated,

Duane

Viewing all 12845 articles
Browse latest View live