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

App Stop responding while looping duplicate to newDoc

$
0
0

I need some help of figuring why Illustrator CC hangs with my loops

This is a loop copying and exporting a list of GroupItems to SVG (workaround the limitation of artboards or slices)

And i have a progressbar for the process. But but....

After 2-3 successful progress window updates, a blue circle will start spinning and both App and my progress window will stop responding.

Script will continue working and console outputs shows ok as well. everything recovers after exporting finishes.

Anything wrong below? of course this is not a biggy since everything still works in background, but kinda of scary even though i am used to it with this App

   

function save2svg(){//export all found icons to svg,       var d=confirm("Export "+ allIcons.length + " icons to svg format? ");    if (d==true){        var newSpot = new File(docPath+"/svg/icons");        var tgtFolder = newSpot.saveDlg("Select the folder for exporting:")        docPath =(tgtFolder.path!=null)? tgtFolder.path:docPath;        var newDoc;        var icon;        var iconCopy;        var fileSpec;        var type = ExportType.SVG;        var exportOptions = new ExportOptionsSVG();        exportOptions.embedRasterImages = false;        exportOptions.embedAllFonts = false;               //progress UI start        var w = new Window ('palette','Exporting please wait!');        w.pbar = w.add ('progressbar', {x:20, y:12, width:300, height:12}, 0, allIcons.length);        w.pbar.preferredSize = [300,20];         w.prompt = w.add("statictext",{x:10, y:0, width:320, height:20}, '');        w.prompt.justify = 'center';        w.show();         //progress UI end               for ( var i = 0 ; i < allIcons.length ; i++){            //progress updating            w.pbar.value = i+1;            w.prompt.text = i+1+': '+ icon.iname;            w.update();             //progress updating end            icon = allIcons[i]; //each icon here is an object from list[content:groupItem, w:int, h:int, iname:string ]            icon.iname = (icon.iname=="")? "icon"+i:icon.iname;            newDoc=app.documents.add(DocumentColorSpace.RGB, icon.w, icon.h, 1);            newDoc.title = icon.iname;            iconCopy=icon.content.duplicate (newDoc, ElementPlacement.PLACEATEND);            iconCopy.top =icon.h; iconCopy.left =0;            filePath = new File(docPath+"/"+icon.iname);            newDoc.exportFile( filePath, type, exportOptions );            newDoc.close (SaveOptions.DONOTSAVECHANGES);            $.writeln("file exported: "+icon.iname);            newDoc = null;            }        w.close();        }
}

Move layers to new artboard

$
0
0

Hi everybody,

 

I'm trying to create a script via javascript for Illustrator.

 

My problem is :

I have a AI file with multiple layers, i want to create one artboard per layer, in order to export a multipage PDF ( each page contain 1 layer ).

 

The layers represents the differents type of print ( vernish, color, hot gold, pressure ... ) and/or color type ( Pantone, CMYK, cut, kisscut ... ).

My client want a PDF for see each type of print or color type per page.

 

I'm trying 2 ways :

 

1st solution : Create new artboards, and duplicate ( or move ) layers content on the new artboad, but the function move/duplicate don't work to move content on another artboard.

 

2nd solution : Create new document with the same number of layers as artboard and duplicate layer to the new artboard on the new document.

 

Can you help me to realize this script ?

 

Excuse me if my english is not good.

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)?

ungroup all groups on an active layer(JavaScript).

$
0
0

Does anyone know how one would go about ungrouping all groups on an active layer with JavaScript?

Alert message need to be added?

$
0
0

Hi All,

 

I need  to add alert message of number of unlock items in the following script.

 

#target illustrator

var myDoc = app.activeDocument;

var myPageItems = myDoc.pageItems;

var count = myPageItems.length;

for ( var i = count-1; i >= 0; i-- ) {if ( ! myPageItems[i].locked){ myPageItems[i].selected = true; }

{myPageItems[i].locked = false;{ myPageItems[i].selected = true;}}};

 

 

this script unlock the items, but i need the information of lock items.

 

Any help.

 

Regards,

Vinoth

Illustrator Macros/Scripting

$
0
0
Hey guys is it possible to create macros in illustrator, or how would this be achieved via the scripting.

Basically i have a c# application that contains alot of pictureboxes all with images in them. i want to be able to right click an image and select vectorise. Which will send the image to illustrator live trace the image, resize it, then copy the resulting image back into my c# app.

How would this be best done

thanks
r

Script to apply a random CMYK swatches from a group of swatches to selected objects.

$
0
0

I would like to write some scripts for randomising the allocation of swatches to adjacent object.

 

Example:

Imagine a map of Europe and all her nation states/territories. I have a User Defined Swatch Library. I can open the AI document it was made from as I understand from this thread that having the swatches as objects on the page makes them easier to be referenced in a script. 

 

I want to iterate through the selected objects and randomly assign one of the colours in the swatch document as a fill to each object. It would be great if hidden swatches (they are all small rectangular 'colour chip' filled paths) on page were not included in the reference swatches randomly choosen from.

 

Iterating the selected objects I can do, but not sure what references I need to use to create an array of swatches to randomly choose from.

 

I see I can make an array of swatches using the general swatch group from Adobe's CreateSwatchGroup scripts:

JS

var docRef = app.documents.add(DocumentColorSpace.CMYK)

 

// Create a new SwatchGroup

var swatchGroup = docRef.swatchGroups.add();

swatchGroup.name = "CreateSwatchGroup";

 

// Get list of swatches in general swatch group

var genSwatchGroup = docRef.swatchGroups[0];

 

// Collect 5 random swatches from general swatch group and move to new group

var i = 0;

while (i < 5) {

          var swatches = genSwatchGroup.getAllSwatches();

          swatchCount = swatches.length;

          var swatchIndex = Math.round(Math.random() * (swatchCount - 1)); // 0-based index

 

          // New swatch group does not allow patterns or gradients

          if (swatches[swatchIndex].color.typename != "PatternColor" && swatches[swatchIndex].color.typename != "GradientColor") {

                    swatchGroup.addSwatch(swatches[swatchIndex]);

                    i++;

          }

}

// Updates swatch list with swatches moved to new swatch group

swatches = swatchGroup.getAllSwatches();

// [… etc etc]

 

AS

tellapplication "Adobe Illustrator"

activate

          setdocReftomakenewdocumentwith properties {color space:CMYK}

 

-- Create a new SwatchGroup

          setswatchGroupReftomakenewswatchgroupincurrent documentwith properties {name:"CreateSwatchGroup"}

 

-- Get list of swatches in general swatch group

          setgenSwatchGrouptoswatchgroup 1 ofdocRef

 

-- Collect 5 random swatches from the general swatch group and move to new group

          setito 0

          repeatuntiliis 5

                    setswatchesReftoget all swatchesgenSwatchGroup

                    setswatchCounttocounteveryiteminswatchesRef

                    setswatchIndextorandom numberfrom 1 toswatchCount

                    setcurrentSwatchtoitemswatchIndexofswatchesRef

 

  -- New swatch group does not allow patterns or gradients

                    ifclassofcolorofcurrentSwatchisnotpattern color infoandclassofcolorofcurrentSwatchisnotgradient color infothen

  add swatchswatchGroupRefswatchcurrentSwatch

                              setitoi + 1

                    endif

          endrepeat

-- [… etc etc]

 

 

If someone can help me to create the Swatch Array object of swatches loaded from a seperate document (or unique layer) then I think I can work my way to changing the fill on the existing paths (the nations in my map of Europe example).

 

Would be very cool if I could detect neighbooring paths (nieghbooring nations in my map of Europe example) make sure the colour being assigned is not within a certain hue/CMYK range of the random colour and if it is rechoose random colour. I have no idea how to perform the logic of determining neighbooring paths in an Illustartor script. Anybody?!

 

I'd prefer Applescript for sake of readiblity and also I'm learning AS ATM. Plus I'm using Script Debugger.app (which is excellent) to work with AS and I can't seem to run JSX scripts from within Extend Script Toolkit 2 (perhaps I need to make my scripts point to Illustrator?)

 

But Javascript is okay if someone has this covered already :-)

Document preset & New document - Illustrator - Applescript

$
0
0

Hi !

Here is the problem i would like to resolve with appelscript.
I want to make a new file with units (millimeters)

I know i need to make a preset before making a new document ; but i don't know how to do !

 

Here is a part of the code i tried to do :

 

tellapplication "Adobe Illustrator"

 

activate

setdocument unitsofdocument presettomillimeters

makenewdocumentwith properties {width:297, height:210}

endtell

 

Thanks for your help !


Show color picker dialog JSX / CSAW

$
0
0

Can someone guide me on how to show the color picker dialog in Illustrator programmatically?

In photoshop that's really easy, just:

 

     app.showColorPicker(true);

 

In Illustrator I couldn't find any reference to such a method or other possibility to show the dialog programmatically, that you would normally get when double clicking on the fill color square within Illustrator.

 

Is that possible by using app.executeMenuCommand or some other method?

 

I am writing a script that opens the color picker dialog in reaction to a click on a button. I want to be able to get the chosen color and use it within the script.

 

thanks for the help!

Dominik

All Group to Ungroup Script

Drawing a rectangle of exact size of the artboard?

$
0
0

Has anybody written a JS script to to draw a rectangle on an active document which would be exact size as the document's artboard?

I find it very inaccurate and cumbersome trying to draw such rectangle by hand.

 

Please let me know where such JS code can be found. I have not done any Illustrator scripting beyond the "Hello world".

 

Thanks

franK

Save All?

$
0
0

This may be a stupid question, but is an existing to Save All open documents? If not, is there a way to script this? I often make a bunch of changes in documents at once and it would save a lot of time if I could just hit one save instead of 5 or 6.

 

Thanks!

Create adobe illustrator rectangle script?

$
0
0

hi, this is a vba script that works in corel draw. I want it to work in illustrator instead but I don't know how to ammend it into javascript and adobe scripting language! Can anybody help??


what it does:

with an object selected
I run script
it creates
around the selected object a thin rectangle with a margin from the object of 0.05cm
then groups the object and rectangle togeather


thats it


Martin



Sub makeRect()

    Dim s As Shape, sRect As Shape
    Dim x As Double, y#, h#, w#
    Dim dMarg#
    Dim sr As New ShapeRange
  
    dMarg = 0.05
    ActiveDocument.Unit = cdrCentimeter
  
  
  
    Set s = ActiveShape
    If s Is Nothing Then Exit Sub
  
    s.GetBoundingBox x, y, w, h
  
    Set sRect = ActiveLayer.CreateRectangle2(x - dMarg, y - dMarg, w + (dMarg * 2), h + (dMarg * 2))
    sRect.Outline.Width = 0.001
  
  
  
    sRect.CreateSelection

    sr.Add sRect
    sr.Add s
    sr.Group
  
End Sub

Illustrator CC ExternalObject load failing but works in CS5

$
0
0

I have a script that loads an external library as follows:

 

if(typeof PCDesEO == 'undefined' ) {

    var libFilename = "/Library/Frameworks/PCDesEO.framework";

    PCDesEO = new ExternalObject("lib:" + libFilename);

};

 

It works fine in CS5, but when I upgraded to CC, the "new ExternalObject" line fails with an I/O Error (error 52).

 

Any thoughts?

 

Thanks,

 

Anurag.

Resize artboard to content - works in Mac (CS6), not Win (CC)

$
0
0

Hello!

This code works perfectly in Illustrator CS6 for Mac:

 

function resizeArtboard() {

            app.redraw();

            app.activeDocument.artboards[0].artboardRect = app.activeDocument.visibleBounds;

            app.redraw();

}

 

It works like the menu option "Shrink artboard to fit content".

 

However, running this script in Illustrator CC for Windows, the result is different: the content is enlarged to fit the artboard instead.

 

How can I solve this?

 

Thanks in advance!

 

/Måns


Shortcut for js script with CS4 ?

$
0
0

hi all,

with my old version of illustrator (CS), i might affect a shortcut to a specific scipt .

Now i have CS4 version, and i  don't find similar possibility.

 

how can affect in this new version ?

 

Thanks for futur answer.

Script access to dataset variables

$
0
0

Hello,

 

I've added some dynamic text variables to an illustrator file (CC), captured the dataset and I'm trying to access these variable values through scripting.

Is this possible with the Dataset method or do I need to parse the XML to retrieve info between <Book></Book> etc?

I've hacked together a perl script to do this, but it's not ideal as I need to then use javascript to call applescript to run the shell script with administrator privileges!

I'm sure there must be an easier way – any help would be much appreciated. Exported XML file is as follows...

 

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"    "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd" [

     <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">

     <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">

     <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">

     <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">

      <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">

<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">

]>

<svg>

<variableSets  xmlns="&ns_vars;">

      <variableSet  locked="none" varSetName="binding1">

          <variables>

               <variable  trait="textcontent" category="&ns_flows;" varName="Book"></variable>

               <variable  trait="textcontent" category="&ns_flows;" varName="Author"></variable>

               <variable  trait="textcontent" category="&ns_flows;" varName="Year"></variable>

          </variables>

          <v:sampleDataSets  xmlns:v="&ns_vars;" xmlns="&ns_custom;">

               <v:sampleDataSet  dataSetName="Data Set 1">

                    <Book>

                         <p>Catch-22</p>

                    </Book>

                    <Author>

                         <p>Joseph Heller</p>

                    </Author>

                    <Year>

                         <p>1961</p>

                     </Year>

                </v:sampleDataSet>

          </v:sampleDataSets>

     </variableSet>

</variableSets>

</svg>

Simple dashed stroke in illustrator with javascript?

$
0
0

I just need to get started understanding the dashed stroke portion in path drawing in illustrator.

Any clues? Thanks in advance.

Mail merge using illustrator

$
0
0

Hi There,

 

I'm trying to find a way to automatically populate data into Illustrator and InDesign.  I was thinking of doing it using Applescript and importing an excel file into an illustrator graph object.  My boss suggested i look into using Xtags as a means to do a data merge with the illustrator/indesign files.  Is this possible? it seems that xtag is a format used with Quark.  is it also available in Adobe products?

 

Thanks,

 

(sorry if my terminology is off, i'm a programmer so my knowledge of adobe design products is limited)

Color Change to various types

$
0
0

I am trying to change the color of all items on and under a specific layer.

 

I have been successful changing the color of specific types of objects (paths), but I need to accommodate all the types on the layer and sub layers.

 

I can recurse to as many sub layers as I expect, but how do I accommodate the page Items, path Items, group Items, compound Path Items, etc.

 

I was thinking of pushing everything to an array, but I have no experience with arrays...

 

Thanks for your help.

Viewing all 12845 articles
Browse latest View live


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