Quantcast
Channel: Adobe Community : Discussion List - Illustrator Scripting
Viewing all 3671 articles
Browse latest View live

If Action Exsits

$
0
0

I'm trying to write a script to run an action but need to make sure the action exists first.  This is what I came up with so far, and it does work when there is nothing in the prompt but if I spell the action wrong it gives me an illustrator error that the action is not there.  Should I use catch for this instead?

 

function ActionTool() {

var action = prompt('Enter Action Name', '');

var set = "MyActionSet";

 

 

    if (action == false) {

            alert("This Action does not exist.  Please try again", false);

             }

         else{ doScript( action , set ); }

}

ActionTool();


How can I get current Mouse position via Javascript?

$
0
0

I'm trying to build a javascript tool in ExtendScript Toolkit CC to work with Illustrator CC (2015) but have run into a snag.

 

The script will create an object (a small circle in this case) at the mouse's current position within the document's active layer. But I can't seem to find a call in the library to retrieve the location info. I know that the data is tracked because if I open the "Window > Info" tool it shows the cursor's X and Y position in relation to the document bounds.

 

Is there a call anywhere in the javascript library that gives me access to these data points?

How to post a question with a script inserted?

$
0
0

I see threads where the poster has included script with the line item numbers.  How does one do that?  I see nothing in the FAQ or an option to perform this?

 

thx

VBS How to select all items in a layer?

$
0
0

I wish to select all the items (PageItems?) in a layer and then set the StrokeWidth to whatever I prefer (10, 20, etc.).  When I open my .dxf file it will have two layers; 'Unknown_Area_Type' and 'Unknown_Line_Type'.  I am successful up to line 14 in the script below but after that all I could fine was a JavaScript that I was trying to convert to vbs but no luck.  Any help would be great. (please excuse for my horrible formatting  - still learning).

 

On another note, why is there no selection for VBscript when selecting Syntex Highlighting for posting code here?

 

Set App = CreateObject("Illustrator.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")

doJavaScript = "var fileRef = File.openDialog ('Select the Road DXF file to open:', '*.DXF', false); if(fileRef) filePath = fileRef.fsName;"
FileRef = App.DoJavaScript(doJavaScript)
If (FSO.FileExists(fileRef)) Then
    Set AutoCADOpenOptions = App.Preferences.AutoCADFileOptions    autoCADOpenOptions.MergeLayers = false    CurrentInteractionLevel = App.UserInteractionLevel    App.UserInteractionLevel = -1 ' aiDontDisplayAlerts    App.Open fileRef, 2 ' aiCMYK    App.UserInteractionLevel = CurrentInteractionLevel        App.ActiveDocument.Layers.GetByName( "Unknown_Area_Type" ).Delete()       Set docRef = app.activeDocument     Set layers = docRef.layers     Set myLayer = layers ("Unknown_Line_Type") ' this defines the layer that you want to get the selection from          docRef.selection = null ' ensure there is nothing in the document selected already. this way you only get the selection you want.        for(Set a=0;a<myLayer.pageItems.length;a++){ ' here we are looping through each pageItem of myLayer.          var currentItem = myLayer.pageItems[a];          currentItem.selected = true;          currentItem.selected.StrokeWidth = 20  'this is also what I wish to add    } 
End if

Ungroup previous created groups

$
0
0

Hi,

 

For a new script I group all objects within layers before processing them. After processing I like to ungroup these objects again. Making the groups is not the problem and works fine, however I can't figure out how to ungroup them again.

 

So what I need is a function (script example) that uses a documentname and layername for input. That layer only contains one group and that group needs to be ungrouped to its original objects (text, paths, groups, etc.).

function ungroup( documentid, layerid ) 

  {

 

   // some code to ungroup a single group in this document and layer

 

  }

 

 

Any help is appreciated

Michel.

How create outline text of a Character in Illustrator by Script?

$
0
0

I want add a Rectangle around Characters.

With indesign : i can create outline of Characters,: ex:   Dim oaPols = oRange.CreateOutlines(False)

But with Illustrator only can create outline of TextFrame.

 

How create outline text of a Character in Illustrator by Script?

Thanks all.

Illustrator scripting bug list.

$
0
0

Hello dear friends, the time has come... to assemble a list of bugs we want to have eliminated.

I've come into contact with an engineer on LinkedIn and he has this to say in a private email exchange:

 

Me: "I have a variety of issues I can provide you with, including cases provided by other scripters around the world. Would you want to focus on any specific issue at first, or do you wish to get the entire catalog of reports?"


Him: "Entire catalog in a prioritized list will be great. I can then get into a conversation with developers with this doc. Also, anything you can do to help me explain why fixing something “non obvious” is important will also help me."

 

Okay, so let's put some list together to send him and hopefully it can start some ball rolling.
I think we should come up with a format to document each "situation" , as these bugs are not typical user bugs and are sometimes more elusive.

Help with script: export to Live and Outlined versions

$
0
0

Hi All,

 

I am currently working on a script (editing one we currently use) that will allow me to export Outlined and Live version at the same time (using Illustrator CS4 and CS6). I've basic knowledge about scripting.

 

See screenshot below, what I am trying to achieve:

Screen Shot 2016-03-30 at 12.37.08.png 

 

Here's what I've done so far:

// Main Code [Execution of script begins here]
var modUI = 'D';


try {
  // uncomment to suppress Illustrator warning dialogs  // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  if (app.documents.length > 0 ) {  // Get the folder to save the files into  var options, i, sourceDoc, targetFile;  // Get the PDF options to be used  options = this.getOptions();  if (options != null) {  // You can tune these by changing the code in the getOptions() function.  sourceDoc = app.activeDocument; // returns the document object  var fullName = sourceDoc.fullName;  fullName = fullName.toString();  var destFolder = fullName.slice(0,fullName.lastIndexOf("/"))  // Get the file to save the document as pdf into  targetFile = this.getTargetFile(sourceDoc.name, '_Live.pdf', destFolder);  OLtargetFile = this.getTargetFile(sourceDoc.name, '_Outlined.pdf', destFolder);  sourceDoc.save();  // Save as pdf  sourceDoc.saveAs( targetFile, options );  for(q=0; q<sourceDoc.layers.length;q++){  sourceDoc.layers[q].locked = false  }  for(q=0; q<sourceDoc.pageItems.length;q++){  try {  sourceDoc.pageItems[q].createOutline();  }  catch(e){}  }  sourceDoc.saveAs( OLtargetFile, options)  alert( 'Documents saved as PDF' );  }  else {  alert('User aborted')  }  }  else{  throw new Error('There are no document open!');  }
}
catch(e) {  alert( e.message, "Script Alert", true);
}


/** Returns the options to be used for the generated files.
  @return PDFSaveOptions object
*/
function getOptions()
{  var dlg = new Window('dialog', 'Script Information',[90,50,300,175]);  dlg.include = dlg.add('radiobutton',[50,5,295,30], 'PDF 1.3 (Default)');  dlg.include = dlg.add('radiobutton',[50,30,320,40], 'PDF 1.6 (Advanced)');  dlg.buildBtn = dlg.add('button',[10,95,90,27], 'Create PDF', {name:'ok'})  dlg.cancelBtn = dlg.add('button',[105,95,190,47], 'Cancel', {name:'cancel'})  dlg.include.onClick = radioSwitch;  dlg.cancelBtn.onClick = abortFunction;  dlg.center();  dlg.show();  // Create the required options object  var options = new PDFSaveOptions();  // See PDFSaveOptions in the JavaScript Reference for available options  // Set the options you want below:  if (modUI == 'D'){  options.pDFPreset = "Default"  }  else if (modUI == 'I'){  options.pDFPreset = "Advanced"  }  else {  options = null;  }  // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)  // options.compatibility = PDFCompatibility.ACROBAT7;  // For example, uncomment to view the pdfs in Acrobat after conversion  // options.viewAfterSaving = true;  return options;
}


function radioSwitch(){
  if (modUI == 'D') {  modUI = 'I'  }  else {  modUI = 'D'  }

}
function abortFunction(){

  modUI = null;  dlg.hide();  return null;  }
/** Returns the file to save or export the document into.  @param docName the name of the document  @param ext the extension the file extension to be applied  @param destFolder the output folder  @return File object
*/
function getTargetFile(docName, ext, destFolder) {  var newName = "";  // if name has no dot (and hence no extension),  // just append the extension  if (docName.indexOf('.') < 0) {  newName = docName + ext;  } else {  var dot = docName.lastIndexOf('.');  newName += docName.substring(0, dot);  newName += ext;  }  // Create the file object to save to  var myFile = new File( destFolder + '/' + newName );  // Preflight access rights  if (myFile.open("w")) {  myFile.close();  }  else {  throw new Error('Access is denied');  }  return myFile;
}

 

 

Any help appreciated!

 

Pete


Looking for solution to read/write Excel data...

$
0
0

   I've been using CSV to import excel data into AI - but I need to be able to import and export the excel data directly, without using ActiveX, direct reads and writes to the XLS file.  This is because CSV loses the formatting and I need to retain that.  Does anyone know of a third party javascript library for working with excel files?

 

   I've also thought of using Excel XML instead of the typical excel format as this will retain the formatting.  However, I know nothing about XML so if there is likewise an easy way to read/write excel XML files or a library somewhere for this, please let me know.

Why can't turn off hyphenation by Script?

$
0
0

If hyphenation =false , set hyphenation =true , it is ok.

But hyphenation =true, can't set hyphenation = false.

My code: oTF.textRange.paragraphAttributes.hyphenation = false;

Why can't turn off hyphenation  by Script?

Intermittent Javascript MRAP error

$
0
0

I have a for loop which moves all elements of an "Artwork" layer to a "working" layer so that I can edit the elemets without a chance of affecting the original layer:

 

for (var i=app.documents[0].layers['Artwork'].pageItems.length-1; i>=0; i--)

{

          try

          {

                    app.documents[0].layers['Artwork'].pageItems[r].duplicate(app.documents[0].layers['workin g'], ElementPlacement.PLACEATEND);

          }

          catch(e)

          {

                    alert(e);

          }

}

 

This seems to work fine for three or four documents, and then begins to return the following error:

 

Error: an Illustrator error occurred: 1346458189 ('MRAP')

 

Action on every document then returns this error, even ones on which it has previously worked. The only solution is to quit Illustrator and relaunch.

 

Am I missing something obvious?

 

Thanks in advance.

Getting 1346458189 ('PARM') error

$
0
0

From the readme:

"An Illustrator error occurred: 1346458189 ('PARM')" alert (1459349)    Affects: JavaScript    Problem:     This alert may be popped when badly written scripts are repeatedly      run in Illustrator from the ExtendScript Toolkit      Scripters need to be very careful about variable initialization and      namespace conflict when repeatedly pushing a batch of Illustrator scripts     for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a      single Illustrator session. Each script run is executed within the same      persistent ExtendScript engine within Illustrator. The ESTK debugger      uses BridgeTalk to communicate with Illustrator. One global, persistent      ExtendScript engine inside Illustrator handles all BridgeTalk      communications. The net effect is that the state of the ExtendScript      engine is cumulative across all scripts that ran previously.      The following issues with script code can cause this problem:        - Reading uninitialized variables.        - Global namespace conflicts, like when two globals from different         scripts clobber each other.    Workaround:     Initialize variables before using them, and consider the scope of      your variables carefully. For example, isolate your variables by      wrapping them within systematically named functions. Instead of:             var myDoc = app.documents.add();       // Add code to process myDoc           Wrap myDoc in a function that follows a systematic naming scheme:             function myFeatureNameProcessDoc() {      var myDoc = app.documents.add();      // Add code to process myDoc      }      myFeatureNameProcessDoc();

 

 

This makes zero sense to me. If javascript variables are being reused or 'clobbered' or your javascript is 'poorly written' (this is not defined) it should have no effect on the scripting engine. Errors should cause exceptions to be thrown, which can be caught by the script.  I'm getting these errors when I try to evaluate properties of valid objects, for instance trying to access pathItem.fillColor. It's happening in various (almost random) lines in my script. Javascript doesn't have namespaces so I don't know what a 'namespace confilct' would be. Accessing variables from nested functions also seems to be a problem.

 

Edit - this seems to be related to accessing global variables or variables defined in containing functions. For now, adding var to the first use in subfunction seems to have fixed the problem. What is strange is you don't get an undefined variable error, it just crashes when it tries to access the properties.

 

Edit - still not fixed. I'm guessing it has something to do with memory allocation, because I am processing a lot of big raster images in todays batch of files.

 

Edit - processed 84 files today with no errors the pattern I'm using is to use a bach file that loops

 

"(Path)/Extend Script Toolkit.exe" -run script

sleep 10

 

The script opens a group of files (in my case JSON files), processes one file, exports an ai file, deletes the JSON file, then exits.

Adjust dashes to corner and path ends InDesign CC 2015

$
0
0

Hello,

 

I am using Illustrator CC 2015.1.0 with Scripting. I have dashed lines in my drawing and want to align dashes to corners and path ends.

No problem in the Illustrator stroke menu. There are two buttons with dashed lines on it. There I can select this option:

dashes.jpg

 

Since I cannot find the script command to do this, I use this script

s.h's page : Adjust Dashes

 

But this script does no longer work in CC 2015.1.0. So what can I do?

Is the option in InDesign now available as script command?

Or has someone an update of the script?

 

Best regards

 

Harald

Create a report or log file

$
0
0
#target illustrator
var doc = app.activeDocument;
var allText = doc.textFrames;
var boldText = app.textFonts.getByName("Arial-Black")


var d = new Date();
var currentYear = d.getFullYear();
var currentMonth = ("0"+(d.getMonth()+1)).slice(-2);
var currentDay = ("0" + (d.getDate())).slice(-2)


for (var i = 0; i < allText.length; i++) {    //alert(allText[i].contents.substr(0,4));    if (allText[i].contents == "Electrical System") {        //alert("This is an Electrical Schematic");        var mediaType = allText[i].contents;    }    if (allText[i].contents.substr(0, 4) == "UENR") {        //alert("Media Number " + allText[i].contents);        var mediaNumber = allText[i].contents;    }    var textFieldRange = allText[i].textRange;    var textProps = textFieldRange.characterAttributes;    if (allText[i].contents != "Electrical System" && textProps.textFont == "[TextFont Arial-Black]") {        //alert("Your Title is: " + allText[i].contents);        var mediaTitle = allText[i].contents;    }
}


var emailAddress = "someone@myemail.com";
var dateFormat = currentYear + "" + currentMonth + "" + currentDay;


//alert("Media #: " + mediaNumber + "\nMedia Type: " + mediaType + "\nTitle: " + mediaTitle + "\nEmail report to: " + emailAddress + "\nSubmitted on: " + dateFormat);










 

So I am wanting to take the information from the above script I wrote and have a text file of sorts in a certain format. For example I would like this format

<meta name="Internet E-Mail Address" content="emailAddress">

<meta name="Media No Rev" content="mediaNumber">

<meta name="Publication Date" content="dateFormat">

 

so a finished report would look like this for example:

 

<meta name="Internet E-Mail Address" content="someone@myemail.com">

<meta name="Media No Rev" content="UENR1234">

<meta name="Publication Date" content="20160226">

Script to Change Swatch layers in an Illustrator file.

$
0
0

I am looking for a script/way to change certain SWATCH layers to different names in an automated manner.  Thoughts?  Thanks.


Rasterize each sublayer

$
0
0

Having an issue with rasterizing in a loop.  I want to select a layer by name then rasterize each sublayer separately. I got the rasterization down but looping it to do each sublayer I am having issues with.

Remove clipping mask

$
0
0
I need to remove the clipping mask in illustrator file through programmatically(Visual Basic (or) Javascript). Kindly advice me.

Thanks,
Prabudass

Input Text Information Via Script

Precisely drop item from extension to AI document

$
0
0

HI,

 

I am using Illustrator version CC2015 (19.1) and mac Yosemite 10.10.3.

I have created one extension having colors swatches. When user drag a color from extension to AI document, I am creating rectangle and filling it with dragged color. This gives effect of dragging a color from extension panel to document.


So here is the deal, I can get this thing working but the location at which I am creating rectangle is not precisely where user has dropped color rectangle.


Extendscript code goes here,



 

var myDocument = app.activeDocument;         var artLayer = myDocument.layers.add();         var group = artLayer.groupItems.add();         var rect = group.pathItems.rectangle( 50, 50, 50, 50);         var x2=myDocument.activeView.bounds[0];         var y2=myDocument.activeView.bounds[1];         var zoom = myDocument.activeView.zoom;         var  y = ((dragDetails.mousePosition.mouseY/zoom)- 100/zoom); // mouseY  = event.screenY (event is drop event)         var  x = ((dragDetails.mousePosition.mouseX/zoom)- 95/zoom);  // mouseX  = event.screenX (event is drop event)         var newRGBColor = new RGBColor();         newRGBColor.red = dragDetails.RGBColor.Red;         newRGBColor.green = dragDetails.RGBColor.Green;         newRGBColor.blue = dragDetails.RGBColor.Blue;         rect.fillColor = newRGBColor; 

 

Note line no 9 and 10.

This works fine on windows. But on mac I am not getting exact X and Y co-ordinates.

When I debugged further I came to know this strange thing -

 

drag end co-ordinates = drag start co-ordinates

 

i.e. event.screenX of drag start event = event.screenX of drag end event.

     event.screenY of drag start event = event.screenY of drag end event.

 

Ideally I should get x and y co-ordinates diffrent for dragstart and dragend event. Seems a bug in cep.

 

Please help. I am badly stuck.

Applescript - Its not work well (can any one help me)

$
0
0

set OrderNo to text returned of (display dialog "OrderNo:" default answer "60000")
set CustomerPO to text returned of (display dialog "CustomerPO:" default answer "TBD")
set GarmentColor to text returned of (display dialog "GarmentColor" default answer "ASH GRAY")
set GarmentDescription to text returned of (display dialog "GarmentDescription" default answer "T-Shirt")
set DesignID to text returned of (display dialog "DesignID" default answer "TBD")
set DesignTitle to text returned of (display dialog "DesignTitle" default answer "TBD")
set Location to text returned of (display dialog "Location" default answer "TBD")
set InkColors1 to text returned of (display dialog "InkColors" default answer "WH")

tell application "Adobe Illustrator"
activate
end tell

on replace_chars(this_text, "AAA", OrderNo)
{this_text, "BBB", CustomerPO}
{this_text, "CCC", GarmentColor}
{this_text, "DDD", GarmentDescription}
{this_text, "EEE", DesignID}
{this_text, "FFF", DesignTitle}
{this_text, "GGG", Location}
{this_text, "HH", InkColors1}
t
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars

Viewing all 3671 articles
Browse latest View live


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