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

How to access XML elements by name in Extendscript??

$
0
0

I'm almost done the script that I've been working on, but something has been nagging me since I started. When I did start, I looked at the JS Tools Guide CS5 that comes with the extendscript ide to check how to access XML elements, children, attributes etc. It says this:

 

The XML object represents an XML element node in an XML tree. The topmost XML object for an XML file

represents the root node. It acts as a list, which contains additional XML objects for each element. These in

turn contain XML objects for their own member elements, and so on.

The child elements of an element tree are available as properties of the XML object for the parent. The

name of the property corresponds to the name of the element. Each property contains an array of XML

objects, each of which represents one element of the named type.

 

So basically it converts the XML into JSON. And you can access the properties like so:

 

<book category="COOKING">

     <title lang="en">The Boston Cooking-School Cookbook</title>

     <author>Fannie Merrit Farmer</author>

     <year>1896</year>

     <price>49.99</price>

</book>

 

The Javascript statement bookstoreXML.book; returns the entire list of books.

The statement bookstoreXML.book[0]; returns the XML object for the first book.

The statement bookstoreXML.book[0].author; returns all authors of the first book.

 

A couple pages down it talks about Retrieving contained elements using children(), elements(), descendants().

 

So now I look through the XML Object properties and I see that I can use:

 

xmlObj.child (which) which A String, the element name, or a Number, a 0-based index into this node’s child array.

 

or

 

xmlObj.descendants ([name])

name Optional. A String, the element name to match. If not provided, matches all

elements.

 

or

 

xmlObj.elements (name);

name Optional. A String, the element name to match. If not provided, matches all

elements.

 

This is an excerpt of an XML I was working with:

 

<ROW xmlns="http://www.filemaker.com/fmpdsoresult"

     MODID="16"

     RECORDID="11128">

   <Sign_Type>251.dr</Sign_Type>

   <fm:Location xmlns:fm="http://www.filemaker.com/fmpdsoresult" xmlns="">5-5024</fm:Location>

   <Line1>Zone

Floor

3

Patient Rooms

R532 - R436 even

Patient Rooms

R522 - R446 even

Xavier Elevators

Zone

Patient Rooms

R537 - 5757 odd

Main Elevators

Zone</Line1>

</ROW>

 

Extendscript will not give me an anything when I try to access elements by name. Instead I have to access by index, which works, but I'd rather search for names!

 

Actually the console log returns: <![CDATA[]]>

 

What am I doing wrong!?


Create a rectangle around object?

Pg Number, File path and date automatically printed?

$
0
0

Is there a way to automatically print the page number, complete file path and date at bottom of each  page (set to landscape)?

 

Thanks!

Sorting Layers

$
0
0

I have a map of the US that is broken down into counties.  Each state has its own layer and the counties are sublayers.  I am currently going through and naming all of the counties, but I need to be able to alphabetize them.  Is there a way to do this?

 

Thanks

Script for Selecting Open Paths in Illustrator CS6

$
0
0

I have created this script for selecting open paths in illustrator cs6 as the graffix plugin is not working under CS6.

 

Just save the following text in /Applications/Adobe Illustrator CS6/Presets/en_US/Scripts/Select Open Paths.js

 

 

if (documents.length > 0 && activeDocument.pathItems.length > 0){
 
          var allPaths = activeDocument.pathItems;
          var allPathsCount = allPaths.length;
          var openPathsAreLocked = false;
          var lockedOpenPaths = 0;
          var locked = false;
          for (var i=0; i < allPathsCount; i++){
                    allPaths[ i ].selected = false;
 
                    if( ! allPaths[ i ].closed){
 
                              try{
                                        allPaths[ i ].selected = true;
                              } catch (e) {
                                        openPathsAreLocked = true;
                                        lockedOpenPaths++;
                              }
 
                    }
          }
          if (openPathsAreLocked) alert (lockedOpenPaths + " open paths are locked or hidden (or their layer is locked or hidden) and cannot be selected");
}

[ANN] New Extension in beta test.

$
0
0

Script Slot, It makes custom menu in Illustrators window menu and make some slot that you can set Javascript(Extendscript) and Applescript(application) file and add shortcut key combination like below.

スクリーンショット 2015-11-28 17.54.34.png

 

This beta test version supports Illustrator CC 2014/2015, OSX10.9 and later.

 

You can download it: https://goo.gl/HZ05VE

Illustrator CC Book Color vs Spot Color PANTONE+

$
0
0

Hi! Here's a question about a little detail regarding PANTONE+ spot colors.
I've got a script that makes PANTONE+ colors inside a document using the available scripting methods, which produce a spot color with the desired Lab color values, but when double-clicking and bringing up the swatch dialog it does not default to the grayed-out "Book Color" option in the Color Mode dropdown.

However, it does have the Book Color option in that dropdown and if it's selected and applied, the next time this swatch is double-clicked and dialog appears, the proper Book Color mode is selected and appropriate fields are grayed out.

 

My question is: considering the functions of spot colors in Illustrator, ink plating and appearance and anything else, does my script-made swatch bear any effect on the document that would make it in any way different than a regular document where the Book Color is shown as default in the swatch options dialog?

 

In Mordy Golding's explanation of Book Color mode for Pre-CS6 versions, he states that Book Colors came with hidden information which displays PANTONE-listed Lab values which relate to the Pre-CS6 CMYK-based PANTONE swatches. Now that we have PANTONE+, and Lab is the default base for the book swatches, I wonder if there is any other property that may not be considered by some function of the application if the swatch has the correct name and Lab values while not having the Book Color mode explicitly selected.

Also, if there's an undocumented property for setting the other Color Modes which can appear in this dropdown, that would also be useful information. Our current available options for SpotColorKind are just SPOTCMYK, SPOTLAB and SPOTRGB
Screen Shot 2015-10-04 at 6.57.46 PM.png

Lab-VS-Book.png

Exporting X,Y coordinate of the center point of objects (Ai)

$
0
0

Hello all,

 

I have an illustrator document (Illustrator CC) with thousands of objects. I would like to export the X,Y coordinate of the center point of each objects --> either one by one or as one. Would you have any guidelines what os the best way doing this?

The aim is to use these objects in XML based format ( SVG) and manipulate them individually within HTML5.

 

If you have any suggestions for existing scripts would be delighted to learn where I can find them.

 

Look forward to your suggestions.

artg


illustrator Spiral Shrinking/Growin text, scaling down/up on spiral path

$
0
0

First of all thanks in advance for anyone who may assist, or make this even possible...... (please contanct me ADAM    razo.ad1985     --->G.mail)

 

In dire need of expertise assistante. Years ago I DLded this script and got this working and older illustrator. NOW i have Illustrator CS6. I would love/like to TYpe text on a spiral path, then have the abitly for "user input(entering custom values)" as far as

Font Start Size/Pt = 80

Font End Size/Pt = 12

 

Just a concept......(maybe someone can do this)

 

desired spiral script.jpg

 

 

Then have illustrator(script) perform action and make my spiral big(80pt) at beggning of text and end at small(12pt) there for looking as FONT/TEXT Gradually shrinks in size from beggining(80pt) unitl end of font/text(12pt)

 

   similar to this(end result after srcipt ran and values entered)

spiralText Concept.jpg

 

I know there is an older script out there..... but if someone can perhaps undate this and modernize it with prompt for user input/customization interaction

         ChangeSizesOfTextSelection.js  ----->    http://forums.adobe.com/thread/447657

Extract text from illustrator for translation then replace with translated text

$
0
0

I am trying to find a way to expedite translations of our drawings.  Each drawing has a series of callouts showing what that piece of the drawing is via text.  I would need to do 100's of drawings for each book.

 

Questions:

 

1. Can I write something to batch a folder and extract the name of the file, and the text from each textbox so that when I get the translation back, I can automate the reinsertion of the translated text to its correct field (i.e. TextField1 = "Translate this" then repopulate that same exact field with "Translation")?  In order to do this I would think each text field would have to be tagged with some unique identifier so that it would know which translation goes where in the drawing.  Keep in mind, I'm ok with manually tagging each textbox if necessary.

 

2. Assuming the above is possible, what would be the best program to write the extracted text to so that reading and writing the translated text back into the drawing is as easy as possible (i.e. Word, Excel, PDF)?

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

Script for Selecting Open Paths in Illustrator CS6

$
0
0

I have created this script for selecting open paths in illustrator cs6 as the graffix plugin is not working under CS6.

 

Just save the following text in /Applications/Adobe Illustrator CS6/Presets/en_US/Scripts/Select Open Paths.js

 

 

if (documents.length > 0 && activeDocument.pathItems.length > 0){
 
          var allPaths = activeDocument.pathItems;
          var allPathsCount = allPaths.length;
          var openPathsAreLocked = false;
          var lockedOpenPaths = 0;
          var locked = false;
          for (var i=0; i < allPathsCount; i++){
                    allPaths[ i ].selected = false;
 
                    if( ! allPaths[ i ].closed){
 
                              try{
                                        allPaths[ i ].selected = true;
                              } catch (e) {
                                        openPathsAreLocked = true;
                                        lockedOpenPaths++;
                              }
 
                    }
          }
          if (openPathsAreLocked) alert (lockedOpenPaths + " open paths are locked or hidden (or their layer is locked or hidden) and cannot be selected");
}

Exporting X,Y coordinate of the center point of objects (Ai)

$
0
0

Hello all,

 

I have an illustrator document (Illustrator CC) with thousands of objects. I would like to export the X,Y coordinate of the center point of each objects --> either one by one or as one. Would you have any guidelines what os the best way doing this?

The aim is to use these objects in XML based format ( SVG) and manipulate them individually within HTML5.

 

Look forward to your suggestions.

artg

Resize Artboard

$
0
0
Unsure if Im asking in the right spot but is it possible to automate the resizing of the artboard say from A0 down to A1

Passing 'constant' to .jsx script via action

$
0
0

I have a script that opens one of a number of template files so the contents can be pasted into one of many files. I'm batching these files with actions (one for each template), but I'd like to be able to pass the specific template required to the script without requiring user input.

 

This might require some clarification.

 

Say I have three folders of images, 'red', 'blue' and 'green', each containing 1000 images.

 

I want to run the 'red' actions on all the images in 'red', the 'blue' actions on all the images in 'blue', and the 'green' actions on all the images in 'green'. In all the actions, I want to open up the respective template, so in 'red' I want to open the 'red' template, in 'blue' the 'blue' one etc. I appreciate in this simple example, I could just write three scripts with the paths hardcoded, but I actually have twelve actions currently, and the potential for this to grow.

 

My original idea was for the relevant action to enter some text, eg a textbox with the word 'red', which can then be picked up within the script as a variable, but unfortunately the actions won't allow text entry.

I've looked into variables, but I don't see how I can make that applicable here.

I've also looked at using pre-generated text strings as symbols, but I've had real trouble getting the action to choose the correct string.

 

I also wondered about having another document open in the background containing the textbox I need, but I can't get the action to select an object from a different document.

 

Using the clipboard is impractical because it's used for other things within the action.

 

Is there a solution to this, or am I resigned to writing multiple scripts? For infor I'm currently using CS5.


copy, move and paste into different layer

$
0
0

I have a script that measures the repeat interval and gap between print impressions printed using a print cylinder (for the production team to know which print cylinders to use, and what to expect once it prints, when looking at the proof sheet). Basically it just measures the distance from the beginning of one print impression to the beginning of the next (these are printed with a cylinder, so every time the cylinder rotates a new print impression happens) as well as the distance in between prints. That part works great.

 

In order to get these meaurements, Illustrator is measuring the distance from a zero point on the artboard to the left side of a marker I made called "repeat", and it is assigned a variable called rawRepeat. What I'd like to do is have the script take that rawRepeat value and use it to move a copy of the print impression to the right by exactly that variable amount and paste it beneath the marker called "repeat". I have been doing this part manually, but haven't been able to figure out how to get illustrator to do this for me.

 

Any help would be greatly appreciated.

 

Here's the script I am using:

 

 

var myDocument = app.activeDocument;

var selectedObject = myDocument.selection;

var activeLayer = app.activeDocument.activeLayer;

var layerName = activeLayer.name;

activeLayer.name = "plate";

 

 

//Identify left edge of repeat

var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds;

var r1 = repeatBounds[0];

 

 

// Get position of selection bounds

var myBounds = selectedObject[0].geometricBounds;

var x1 = myBounds[0];

var x2 = myBounds[2];

 

 

 

 

// Set up vars for the Measurements

var rawPrintWidth = myBounds[2] - myBounds[0];

var tmpPrintWidth = (rawPrintWidth / 72);

var finalPrintWidth = tmpPrintWidth.toFixed(2);

var rawGap = (r1 - x2);

var rawRepeat = (r1 - x1);

var Repeat = (rawRepeat / 72) + 0.25;

var Gap = (rawGap / rawRepeat) * Repeat;

 

 

//set up fraction calculations for Repeat

var Factor = 16;

var repeatFraction = Math.round(Factor*Repeat) % Factor;

if (repeatFraction)

{

    while (~(repeatFraction | Factor) & 1)

        repeatFraction >>= 1, Factor >>= 1;

    if (Math.floor(Repeat) == 0)

        Repeat = String(repeatFraction)+'/'+String(Factor);

    else

        Repeat = String(Math.floor(Repeat))+' '+String(repeatFraction)+'/'+String(Factor);

} else

{

    Repeat = String(Math.round(Repeat));

}

 

 

//set up fraction calculations for Gap

var gapFactor = 8

var gapFraction = Math.round(gapFactor*Gap) % gapFactor;

if (gapFraction)

{

    while (~(gapFraction | gapFactor) & 1)

        gapFraction >>= 1, gapFactor >>= 1;

    if (Math.floor(Gap) == 0)

        Gap = String(gapFraction)+'/'+String(gapFactor);

    else

        Gap = String(Math.floor(Gap))+' '+String(gapFraction)+'/'+String(gapFactor);

} else

{

    Gap = String(Math.round(Gap));

}

 

 

// Find specs swatch

var origSwatches = myDocument.swatches;

var swatchesLength = origSwatches.length;

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

          if (origSwatches[i].name == "specs" || origSwatches[i].name == "Specs") {

                    var specsSwatch = origSwatches[i];

                    }

          }

 

 

// Check if specs swatch is defined

if (specsSwatch == undefined) {

          alert("Please create a specs swatch");

          }

else {

          makeDimensions();

          releaseLayer();

}

 

 

 

 

function makeDimensions() {

 

 

// Lock the active layer to prevent color change

activeLayer.locked = true;

 

 

// Create Measurements Layer

mLayerCreate();

 

 

// Set Document colors to specs

myDocument.defaultFillColor = specsSwatch.color;

myDocument.defaultStrokeColor = specsSwatch.color;

 

// Create groups for measurements

var xMeasure = mLayer.groupItems.add();

xMeasure.name = "Width";

 

 

// Create Text for Repeat Measurement

var repeatText = xMeasure.textFrames.add();

repeatText.contents = "Will repeat every "+Repeat+"\" " + "with approximately "+Gap+"\" between prints";

repeatText.top = -327;

repeatText.left = 275;

repeatText.paragraphs[0].paragraphAttributes.justification = Justification.LEFT;

for (i=0;i<repeatText.textRange.characters.length;i++) {

          repeatText.characters[i].characterAttributes.fillColor = specsSwatch.color;

}

}

// Create Text for Ink Colors

 

 

var inkList = [];

 

 

 

 

 

 

function mLayerCreate() {

 

          var mLayerNotExists = true;

 

 

//Delete existing Measurements layer to make way for new measurements

try {

    app.activeDocument.layers.getByName("Measurements").remove();

} catch (e) {};

 

 

 

 

// Create Measurements Layer

if(mLayerNotExists){

mLayer = myDocument.layers.add();// not using var to declare makes it global

mLayer.name = "Measurements";

}

}

 

 

function releaseLayer(){

          for(i = 0; i < activeDocument.layers.length; i++) {

                    if(activeDocument.layers[i].name == "plate") {

                              activeDocument.layers[i].name = layerName;

                              activeDocument.layers[i].locked = false;

                              activeDocument.activeLayer = activeDocument.layers[i];

                              }

                    }

 

          }

How to Clean up Stray points in JS?

$
0
0

Although there is a function in Illustrator to select stray points and delete or clean up stray points in paths, I want to find a way to make it in JavaScript.

It seems that no specific details mentioned in JavaScript Reference of Illustrator, I think it is related to "pathPoints.length == 1" and "textFrame".contents==0, or something esle. But I am not so sure.

Could anyone give me a script to clean up all stray points in a document?

 

p.s. what's the differences between "select stray points =>delete" and "path =>clean up stray points" in illustrator, I heard that one could delete brushes or something...

 

 

Thank you in advance,

Ai Packaging Script

$
0
0

Ok.. I'm sure this has been posted before (already searched, didn't find however), but does a file packaging script exist for AI? (one that collects all linked images and fonts and places them in one place) This would be IMMENSELY helpful to me if anyone can post a link to one or even be willing to write it.

 

OS: W7

AI Version: CS5

 

Thanks in advance!

Cutting a circle

$
0
0

Hi all,

 

I need to make shapes like this based on a value for graph purposes - usually I would just create a cutting shape based on trig (this shape representing around 60%) and subtract it from the path - I have about 30 graphs to do and I need to base it on a variable, and I want to use script - I'm sure there must be a better way, and I'm hoping you guys have the answer.

 

Thanks in advance

 

Dave

cut.png

How to get the angle of an object ?

$
0
0

How to get the angle of an object ?

234.png

Viewing all 12845 articles
Browse latest View live


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