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

Ungroup text frame

$
0
0

Hello everyone,

i need to ungroup textframe inside so many groups present

 

first Layer1

inside layer1 Group Item is present

inside Group item AAA group present

Inside AAA group Group Item Present

inside Group Item if Textframe is present i have to place textframe before (Ungroup)

 

Program code:

var sourceDoc=app.activeDocument;

ungroup();

function ungroup()

{

      layer_file = sourceDoc.layers;

       for(layer_iteration=0;layer_iteration<layer_file.length;layer_iteration++)

    {

          if(layer_file[layer_iteration].name=="Layer 1")

  

    {

       

        var theGrp =layer_file[layer_iteration].groupItems;

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

               var count=0;

                  var count2=0;

    count++;

        var allGrp = 0;

   theObj = theGrp[i].pageItems;

        for(var k= theObj.length-1; k>=0; k--) {

                

       

  

        if (theObj[k].typename == "GroupItem") {

            count++;

              theObj2 = theObj[k].pageItems;

            for(var kk = theObj2.length-1; kk>=0; kk--) {

         

 

         if(theObj2[kk].typename == "GroupItem"){

             count++;

              theObj3 = theObj2[kk].pageItems;

            for(var kkk = theObj3.length-1; kkk>=0; kkk--) {

      

 

           if(theObj3[kkk].typename == "GroupItem"){

             count++;

              theObj4 = theObj3[kkk].pageItems;

            for(var kkkk = theObj4.length-1; kkkk>=0; kkkk--) {

                if(theObj4[kkkk].typename == "GroupItem"){

             count++;

              theObj5 = theObj4[kkkk].pageItems;

            for(var kkkkk = theObj5.length-1; kkkkk>=0; kkkkk--) {

             

              

              if ((theObj5[kkkkk].typename == 'TextFrame')){

                   theObj5[kkkkk].move(theObj4[kkkk],ElementPlacement.PLACEBEFORE); 

            

                }

           

            }}}}}}}}}}}}}

But this code not at all working for me can anybody modify it please it is urgent.

i have tried so many times.

with regards,

yogi                 


call/run applescript from javascript

$
0
0

Hi,

How to call applescript code from javascript..

I want to run some applescript code via javascript in illustrator

 

pls help

Multiple artboards to multiple PDF's

$
0
0

I have over 300 different ai files with about 50 artboards in each one and need to export each artboard to a separate PDF file.  I'm on a windows machine so the script would have to be JavaScript.  Is this possible?

 

I found the following script on the forums, which is close, but I really need actual PDF files (not just "PDF compatible" ai files):

 

Thanks so much!

Tim



//splits the activeDocument Artboards into individual files

 

var doc = app.activeDocument;

 

var docName = doc.name;
var docPath = doc.path;
var fullName = docPath + "/" + docName;
var abRange = ""

 

for (i=1; i<=doc.artboards.length;i++)
    {
        abRange = abRange + i + ","
     }
IllustratorSaveOptions.saveMultipleArtboards = true;
IllustratorSaveOptions.artboardRange = abRange;

var newFile = new File(fullName);
app.activeDocument.saveAs (newFile, IllustratorSaveOptions);

alert ("Artboards Saved to current document's Folder", "Split Arboards");

Data Merge in Illustrator?

$
0
0

Hi there, anyone knows if Illustrator has Data Merge function?

or InDesign Data Merge 'alike' function in Illustrator?

 

Thank you.

CS6 64bit Illustrator - win, where to place scripts

$
0
0

HI all,

 

I just got CS6,  and I can't figure out where to place all of my scripts.  In CS4 version, once the scripts where in the correct folder, they would show up in the the scripts list,.  In CS6, I have to keep finding them.  Any help would be great.

Return code 1073807364 (0x40010004) on Windows when using COM to script Illustrator and Photoshop

$
0
0

Hi,

 

I'm using python via COM to run Illustrator and Photoshop on a Windows machine and I occasionally get this return code in python from the subprocess: 1073807364 (0x40010004). I've done some googling and it seems to indicate that that's a Windows return code for "the process is still running". Is it safe for me to let the process continue when I see that return code? Or does that indicate something else?

 

Thanks.

Script: "No such Element" error when looking for a specific paragraph

$
0
0

Hello,

 

I've searched an answer to this everywhere, but in vain... My script looks for a specific paragraph in a textframe, based on its index in TextFrame.Paragraphs. So far so good, but in one of the files I ran my script on, it keeps blocking on a specific textframe when looking for the second paragraph in it.

 

I tried testing first that the index of the paragraph was within the TextFrame.Paragraphs.Count, but even so, it doesn't work : it confirms the textframe hold 2 paragraphs (TextFrame.Paragrephs.Count=2), but insists that TextFrame.Paragraphs(2) doesn't exist.

 

I twisted and turned my code around, trying to figure out why, in vain so far. And when looking at the textframe with the hidden characters shown, it shows clearly the two paragraphs, so I don't understand what happens here...

 

Here's a snippet of my code, where the error occurs:

 

paraNb = Cint(Para)

paraCnt = docTF.Paragraphs.Count

If paraNb > 1 Then

     If paraNb = paraCnt Then

          test = True

     End If

End If

Set docPar = docTF.Paragraphs(paraNb) 'This is where the error occurs

Installing Scripts in latest Illustrator CC release (V 22.0.1)

$
0
0

Hi all,

 

I have been trying to find the location for installing scripts so that they appear directly under File > Scripts (instead of having to navigate to them via File > Scripts > Other Scripts). However, i can't find a folder for them.

 

In AI CC 2017 the folder was (on Windows) "C:\Program Files\Adobe\Adobe Illustrator CC 2017\Presets\de_DE\Skripten"

There seems to be no similar folder in the CC 2018 install. I tried "C:\Program Files\Adobe\Adobe Illustrator CC 2018\Support Files\Contents\Windows\Scripts"

and also "C:\Program Files\Adobe\Adobe Illustrator CC 2018\Scripting"

But scripts placed in either of these folders do not show up under File > Scripts, even after restarting Illustrator.

 

I couldn't find any official documentation regarding installing scripts in AI CC 2018. Does anyone have an idea where scripts go in the new release?

Thanks in advance!


Unable to export last asset as PNG out of a selection!

$
0
0

Hi

 

I had wrote a script to export my selection as PNG through asset export. But the last selection is not exporting as PNG throwing an error. When it comes to SVG in the same script its working fine. Ill paste the sample script here, please correct me if I had committed some mistake.

 

I reiterate SVG export working fine in below script its only problem with PNG.

 

 

var doc = app.activeDocument;

var selectedObjects = doc.selection;

 

 

//remove all assets

if (doc.assets.length>0){

doc.assets.removeAll();

}

 

//Adding selection to assets panel

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

     var currentObject = selectedObjects[i];

     doc.selection = currentObject;

     var currentAsset = doc.assets.addFromSelection ();

     currentAsset.assetName = currentObject.name;

}

 

//Collecting new assets

var assets = doc.assets;

 

//Query Asset ID's

var assetArray = [];

for (var z=0; z<assets.length; z++){

    assetArray[z]=assets[z].assetID;

    }

 

//Creation of destination folder

var destFolder = Folder("C:/Users/Xxxxx/Desktop/script/export/Icon_01");

if(!destFolder.exists) destFolder.create();

 

//Defining assets to export

var whatToExport = new ExportForScreensItemToExport();

whatToExport.assets = assetArray;

whatToExport.artboards ="";

 

//As SVG

var svgParams = new ExportForScreensOptionsWebOptimizedSVG();

doc.exportForScreens(destFolder, ExportForScreensType.SE_SVG, svgParams, whatToExport);

 

//As PNG

var pngParams = new ExportForScreensOptionsPNG24();

doc.exportForScreens(destFolder, ExportForScreensType.SE_PNG24, pngParams, whatToExport);

 

alert('done');

[Javascript] How to trim/crop an image for export

$
0
0

Hey folks,

 

Got lucky with an answer the first time, thought I'd try again.  In Illustrator CS5+, I'm looping through the objects in a document, exporting each of them to an image using exportArtBoardasImage().  They need to be trimmed afterwards, as they generally have a tonne of whitespace.  Normally, I run an ImageMagick shell script (mogrify -trim).  It'd be awesome if I could reproduce this functionality from within illustrator.  I've seen people handle this by copy-and-pasting each object into a new file, sizing the artboard to that object, exporting, then closing the file.  I'd rather not do this, as it's *way* too slow.  Any other suggestions?

 

Cheers!

 

-macdonaldshall

How to link with any function to any Script UI (user interface) using javascript

$
0
0

How to link with any function to any Script UI (user interface) using javascript

How Can I See Javascript Script Debugging In Adobe Illustrator CC 2015.0.0?

$
0
0

I have written a Javascript script to run in Illustrator so that it can create particular irregular polygon paths for me when I need it. Some of the lines being drawn are not what I was expecting and it's at this point that I would usually add some debugging lines into my code to see what's what. As far as I can tell, in Adobe Illustrator, I need to add the lines

 

$.write(myValue);

$.writeln(myValue);

 

In the past, when using previous version of Adobe Illustrator, I can recall a window appearing with my debugging in it. On this current version:

 

v2015.0.0

 

I cannot seem to find it anywhere. I have googled this question a bit and I have only come away more confused. How can I see my debugging for my simple script? Do I need a plugin? Can anyone recommend one?

 

Thanks,

Phedg1

app.executeMenuCommand() problems

$
0
0

I'm using AI CC 2017 and it has been brought to my attention that my app.executeMenuCommand("doc-color-cmyk"); doesn't work some times when my script is ran.

 

#target illustrator

function test(){

    var doc = app.activeDocument;

    app.executeMenuCommand("doc-color-rgb");

    app.redraw();

};

test();

 

I tested the above snippet and sure enough, nothing happens.

Then, I went to the menu item and hovered over it to reveal the CMYK/RGB menu items in the document color space (without choosing one even), and it now works.

 

Is this the same thing that's happening with the Actions not registering the recorded scripts menu items?

It is not acceptable when they have to show this item, however rare it might be!

 

I went by with actions for this purpose, but having this come up was a rather unwelcome 'surprise'.

How add trim marks and bleed to PDF MultiExporter.jsx

$
0
0

I am using MultiExporter.jsx

 

An Illustrator script for exporting layers and/or artboards into separate files (PNG8 / PNG24 / EPS / PDF / SVG / JPG / …

 

I would like to add this options when saving multiple artboards to separate PDFs:

- trim marks

- bleed: always 3 mm or: use document bleed settings

 

I managed to add trim marks but it makes bleed bigger than the desired 3mm

 

else if ( this.format == 'PDF' ) {

            options = new PDFSaveOptions();

            options.compatibility = PDFCompatibility.ACROBAT5;

            options.generateThumbnails = true;

            options.preserveEditability = false;

            options.trimMarks = true;

 

Any ideas?

Thank you so much,

Move placedItem in Illustrator CS4 js

$
0
0

Hi,

 

I need to move placed Item to new location. This what I have so far  and moving doesn't work:

 

 

var myTemplate = myDoc.placedItems.add();
myTemplate.move(5, 5);

 

Your help is highly appreciated.

 

Yulia


How do I script a new position for an entire layer?

$
0
0

I have an 8x10 template but the artboard needs to be larger than the template's page size. I can open the template and resize the artboard to the larger size but the contents of the original template still need to be centered on the new artboard. The artboard is the right position, all of the original template's objects need to be repositioned.

 

With the GUI it's easy, just select the entire layer with the template contents and enter a new x,y position. In Javascript there is no position setting for an entire layer as a single unit.

 

Other alternatives I've tried:

 

  1. Create a new doc with the right size and use groupItems.createFromFile() for the template - centers the template: strips off the names of all objects and basically makes a hash of the original template. No good since I need those path and group names intact. Why couldn't it just work like Corel's import?
  2. Create a new doc, open the template, use copy and paste to copy template layers into the new document. Slow and uses up lots of memory. It works ok if there's a border around the template page that makes the centering work.It also works for multiple layers and centers the contents of all layers as a single unit.

 

One thing I can think of is that groupItems can be positioned so I could put everything in the layer into a single group and move that new group and then move everything back out of the group. This doesn't work for multiple layers unless I want to merge them (which I don't).

 

Any other suggestions on positioning the contents of one or more layers to be centered on the page? Multiple layers would need to keep their original relative positions.

Script to Sort Artboard List Alphabetically

$
0
0

I'm on the lookout for a simple script to sort an Illustrator artboard list alphabetically. (I don't need the artboards themselves rearranged on the canvas, just the order of the artboards in the list.)

 

In the example (image) below, the artboard list reads:

 

1. life-ring

2. wheelchair-alt

3. wheelchair

4. information

...

30. blind-walking

 

The desired result would be for the artboard list itself to be sorted to read:

 

1. assistive-listening

2. assistive-listening-telecoil

3. blind-walking

4. braille

...

30. wheelchair-alt

 

Screenshot 2017-11-15 09.02.45.png

 

I've scoured the forums for solutions to this. The closest I could find is here: Sort artboards by name, but it doesn't seem to work in Illustrator CC. Also found this (How to sort objects alphabetically (inside of a layer)?), but it is layer-specific, not artboard.

 

Thanks so much for any help!

Creating a dynamic action to use with app.doScript() method.

$
0
0

Since building dynamic actions is a topic unto itself, we often search for a reference thread to show somebody how to do this - and we often do so while trying to discuss work which is already involved and has nothing to do with actions or loading and playing them. Therefore I'm creating this thread to show an example and I'll paste the url to it when such questions arise.

 

Sometimes in Illustrator scripting we need to accomplish tasks which (sometimes counterintuitively) do not have scripting access via the DOM.

Fortunately since Illustrator CS6, they gave us the ability to play an action from a script with the app.doScript() command - which is not at all the same as Indesign's function of the same name. This one lets you play an action that exists inside the Actions panel. Immediately this may seem disappointing as users cannot be counted on to have specific actions at any given time.

However, they also gave the ability to load and remove actions from .aia action files. Your .aia file just needs to be somewhere and app.loadAction() can read it right into the Actions panel. Same with app.unloadAction(setName, actionName) - where (thanks to qwertyfly) using (setName, "") an empty string argument for the action name will remove the entire set. And when you try to remove an action that does not exist, well, it throws an error - which is how you can check for making absolutely sure that an action set is completely removed.

This may seem like a lot of work - to write a file, read it, play it and then discard it, often to do something that you'd think scripting should do in the first place.

 

Sometimes the action alone is enough to satisfy an objective - such as changing the document color mode. Other times it is necessary to alter actions in order to get use out of them - such as when you try to create a routine for saving a high-resolution "Export" JPG that is different in output and options form the "Save for Web" JPG. You may want to change some of the parameters such as resolution or the actual destination of the file.

Here is how you can do this.

 

First, record your action as you would normally: record a new set with a new action, call them what you need and then in the Actions flyout menu, save out a .aia file where you can find it. You can open the file in a text editor and read the contents - they are lines of special Actions 'code' which contains some cryptic text.

There are lines which look like a bunch of gibberish characters, they are hex-encoded strings for some parameter item which are strings, and they contain above them a number to signify the amount of characters inside the encoded string. (this is important later because this number also needs to be set properly when you put your own value in there) Other parameter items are simple numbers, but their keys are still obscured.

The truth is, while the string parameters are hexadecimal-encoded, the keys are both hexadecimal and decimal encoded! So if you wanted to know the special 4-letter keys, you'll have to run those through two decoder routines.

 

Next, you will need to put this entire string into your script and use some string-replacement or string-building to put your own data in those places of the action string where they matter. For example, putting your own file path into a save action.

 

And, after that you need to write a procedure for writing this new altered string to the file system and loading it into your Actions panel. Mind you, to leave things "as they were" you would need to remove the .aia file and the action that you have loaded.

 

Let's try with the save-a-jpeg workaround!

Here is the .aia string which is recorded from an Export JPEG action.

 

Screen Shot 2017-02-10 at 3.04.33 PM.png

/version 3

/name [ 8

  5475746f7269616c

]

/isOpen 1

/actionCount 1

/action-1 {

  /name [ 11

  4578706f7274204a504547

  ]

  /keyIndex 0

  /colorIndex 0

  /isOpen 1

  /eventCount 1

  /event-1 {

  /useRulersIn1stQuadrant 0

  /internalName (adobe_exportDocument)

  /localizedName [ 9

  4578706f7274204173

  ]

  /isOpen 1

  /isOn 1

  /hasDialog 1

  /showDialog 0

  /parameterCount 7

  /parameter-1 {

  /key 1885434477

  /showInPalette 0

  /type (raw)

  /value < 100

  0a00000001000000030000000200000000002c01020000000000000001000000

  69006d006100670065006d006100700000006f00630000000000000000000000

  0000000000000000000000000000000000000000000000000000000000000000

  00000100

  >

  /size 100

  }

  /parameter-2 {

  /key 1851878757

  /showInPalette 4294967295

  /type (ustring)

  /value [ 25

  2f55736572732f566173696c7948616c6c2f4465736b746f70

  ]

  }

  /parameter-3 {

  /key 1718775156

  /showInPalette 4294967295

  /type (ustring)

  /value [ 16

  4a5045472066696c6520666f726d6174

  ]

  }

  /parameter-4 {

  /key 1702392942

  /showInPalette 4294967295

  /type (ustring)

  /value [ 12

  6a70672c6a70652c6a706567

  ]

  }

  /parameter-5 {

  /key 1936548194

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-6 {

  /key 1935764588

  /showInPalette 4294967295

  /type (boolean)

  /value 1

  }

  /parameter-7 {

  /key 1936875886

  /showInPalette 4294967295

  /type (ustring)

  /value [ 1

  32

  ]

  }

  }

}

 

We can see many parameters and their various cryptic blocks, but what you want to do is decode as many /type (ustring) elements as possible to get a sense of what the action is doing. At this website, you can do this fairly easily although tediously: Convert Hexadecimal To String Online

For example: "4a5045472066696c6520666f726d6174" turns into "JPEG file format".

In this action example, I am not worried about changing the other parameters dynamically - I'm assuming the settings used in my action are suitable for my purposes such as resolution being 300 for all time. The part I'd like to change is my file path so that my JPEG goes to the right place.

/value [ 25
2f55736572732f566173696c7948616c6c2f4465736b746f70
]

This line yields: "/Users/VasilyHall/Desktop"

So this is the line I'll need to replace.

 

Before anything else - here is how I'd embed the action string with ease. Using a text editor like Sublime text which lets you put many cursors down at one time, I can paste the action string in and find every nextline character. Then it's easy to highlight each line and put quotes around it as well as a comma in the end, or plusses - depending if you want to store the string as an array or a plain string in the script.

Screen Shot 2017-02-10 at 3.16.48 PM.png

I find the plusses a little cluttering so I opt to use this format:
var actionString = [     "string",

     "string"

].join("\n");

 

So my dynamic portion of the string which will be used with string replacement would look like this:

 

"  /value [ {{number_of_characters}}",

"  {{hex_encoded_path}}",

"  ]",

 

When the action is ready to be dispatched, a string replacement would look like this:

var myNewPath = Folder.myDocuments.toString() + "/Destination";

var myNewPathEncoded = hexEncode(myNewPath); // find a hex encode function via google
var thisActionString = actionString.replace("{{hex_encoded_path}}", myNewPathEncoded).replace("{{number_of_characters}}", myNewPath.length);

 

Now it's time to write the file.

var f = File(actionFileLocation);

f.open('w');

f.write(thisActionString);

f.close();

 

And now it's time to load the action.

app.loadAction(actionFileLocation);

 

Now we can play the action.

app.doScript("Export JPEG", "Tutorial");

 

This should save your jpeg, and as of this writing, this is the only way to get the JPEG export which isn't the Save-for-Web variety.

But, let us not forget the cleanup.

 

Remove the .aia file:

f.remove();

 

Remove the single-use dynamic action:

app.unloadAction("Tutorial", "");

 

There you have it: building dynamic actions to do simple and non-simple things, which regular scripting just can't do.

ActionScript for getting the name of an artboard?

$
0
0

I'm getting errors when I try this:

 

 

for (var artboardIndex:int=0; artboardIndex<app.activeDocument.artboards.length; artboardIndex++)

{

    var thisArtboard:Artboard = app.activeDocument.artboards.index(artboardIndex);

    var thisArtboardName:String = thisArtboard.name;     // compiler complains here

    ...

}

 

And when I'm debugging, I don't see a "name" property for an artboard, though I can get at "artboardRect."

 

What am I doing wrong here?  The Illustrator Scripting Reference shows a "name" property.

 

Thanks for any help,

 

- Rich

Data Merge in Illustrator?

$
0
0

Hi there, anyone knows if Illustrator has Data Merge function?

or InDesign Data Merge 'alike' function in Illustrator?

 

Thank you.

Viewing all 12845 articles
Browse latest View live


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