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

Finger joints

$
0
0

Hello,

i am looking for a script to create a simple box with Finger Joints for laser cutting, any suggestions?

Input box, Width, Height, Depth, Finger width, Material thickness , Units

(My scripting knowledge  is not so good yet... The screenshot is from a plugin available  only for Corel)

Thanks a lot!

simple-box-finger-joints2.jpg


Batch Rename Everything

$
0
0

Hello, I want to batch rename everything.

What I want to do is similar to this script:

GitHub - shspage/illustrator-scripts: JavaScript scripts for Adobe Illustrator CSx.

This script collects every textframe to a pop-up window and let you modify the text and replace it.

 

What I want to do is you run a script in a document, open a pop-up window, and it contains the document's tree.

Something like this:

 

  • Layer 1
  • Layer 2
    • PathItem 1
    • PathItem 2
    • GroupItem 1
      • PathItem 3
      • PathItem 4
    • PathItem 5
  • Layer 3

 

And you can modify them like this:

 

layer 1

mainLayer

--rect

--circle

--mainGroup

----icon 1

----icon 2

--stuff

lastLayer

 

Here is some code I go so far:

(function() {  var allLayersName = "";  //store document's tree  var level = 0;  //store item's order  for (var i = 0; i < app.activeDocument.layers.length; i++) {  //loop throught all top layers    loopThroughAllItems(app.activeDocument.layers[i], level);  //go into layers, this is a recursive function  }  alert(allLayersName); //display document's tree  function loopThroughAllItems(elem, level) {    if(elem.typename == "GroupItem" || elem.typename == "Layer") {      allLayersName += Array(level).join("--") + elem.name + "\n";  //Array(level).join("--") means repeat "--" string level times, level = 2 you get "----"      level++;      for (var i = 0; i < elem.length; i++) {  //this line is where I stuck because illustrator doesn't have this kind of api        return loopThroughAllItems(elem.index(i), level);  //I think this line is also not gonna work XDD      }    } else {      if(elem.parent.index(elem.pareent.length-1) == elem) {  //detect if it is last element inside a group or layer        allLayersName += "--".repeat(level) + elem.name + "\n";        level--;  //decrease level so you get proper order      } else {        allLayersName += "--".repeat(level) + elem.name + "\n";  //there is still some items inside the group or layer      }    }  }})();

 

I stuck at line 12, 13 because illustrator doesn't have that api.

I don't know how to get a groupItem or layer's child in proper order.

 

Please Help~

script to align selected objects to artboard

$
0
0

Hello, I was wondering if anyone had a simple solution to aligning selected items to the artboard. I was going to create an action but then realized it would be more convenient for me to include it in my script file....I have a script to align objects with each other but they dont align to the artboard. Any suggestions?

How to add a custom color in the sample via script

$
0
0

Hello! I'm looking for a script that will add a sample named "CutContour" and color type "Process Color" This is important because creating vector files that contain cut boundaries added in strokes to a Roland Printer. Thank you!

roland.png

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

Is it possible to get the items on a specific artboard with script?

how to delete active artboard using illustrator cs6 javascript

$
0
0

Hi this hariprasad,

 

 

var myDoc = app.open(inputFile);

var ab = myDoc.artboards.getActiveArtboardIndex();   

myDoc.artboards[ab].remove();

 

i am using the above code to delete active artboard using javascript

but i am getting an illustrator error occured 1128549443 ('CDLC') error

 

any please help me how to delete active artboard using javascript in illustrator cs6

Action to remove all unused swatches nearly works...

$
0
0

I've been using the default Action to remove fluff (unused swatches, symbols, brushes, etc.) but it has a funny quirk. I have a spot black color (named black) that always escapes the purge, even if it not used in the document. It is not set as the default stroke/fill, and there are no styles that use this swatch. Even if I run the Action twice the swatch remains. Even if I rename the swatch to something other than black it remains. Even if I rename the swatch and give it a different CMYK mix it remains. As a kludge, I've been using a combo of the default action and John Wundes' Delete Fluff script to get everything, but it is not an ideal solution. Wundes' script, which is unable to delete used brushes, roots out the offending swatch. It is unable to delete unused brushes, so following up with the default action clears those out. Also, Wundes' script is very slow and will often beach-ball the application, requiring a force-quit occasionally.

 

Two questions:

============

Can anyone think of other places that might harbor this rogue spot color and make the default action not find/delete it?

Is there a simple script that could check specifically for the use of this color in the document and delete it?


Cheers and thanks!!


-G-




Illustrator Sublime Extension Woes

$
0
0

I installed this package for sublime and it installed successfully, except; there is no Illustrator listing within Tools > Build System  ?

I asked on the Sublime forum, after a day, no replyThere as well is no way to contact the author of this sublime extension on his GitHub page.

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

How to sort objects alphabetically (inside of a layer)?

$
0
0

How to sort objects alphabetically (inside of a layer) on layer list?

I have already tried scripts for Layer sorting. They work indeed for the layers, but not the objects themselves packed inside.

Advanced "Save as PDF" script that saves 2 PDF presets with 2 different names.

$
0
0

Hi Everyone,

 

I am looking to improve a save as pdf workflow and was hoping to get some direction. Here is the background...

 

I routinely have to save numerous files as 2 separate PDFs with different settings (a high res printable version and a low res email version). Each file has to be renamed as follows...

 

Original filename = MikesPDF.ai

High Res PDF Filename = MikesPDF_HR.pdf

Low Res PDF Filename = MikesPDF_LR.pdf

 

I was able to alter the default "SaveAsPDF" script to save the files to my desired settings and to add the suffix to the name. So with these scripts here is how the workflow operates...

 

1. Open all files I wish to save as pdfs

2. Select script to save files as high res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator adds the appropriate suffix and saves each file as a pdf to my desired setting. ("Save As" not "Save a Copy").

5. Now all of the open windows are the new pdfs, not the original ai files.

6. Now I have to close each window. For some reason Illustrator asks me if I want to save each document when I tell it to close window, even though the file was just saved. I tell it to not save and everything seems to be fine.

7. Reopen all the files I just saved as high res pdfs.

8. Repeat the entire process except I run the script specifically designed for the low res pdfs.

 

What I would like to do is to combine these two processes so that there will be one script that saves both pdfs. From what I understand, the script can't support "Save A Copy" so the workflow would go as follows...

 

1. Open all files I wish to save as pdfs

2. Select single script to save files as both high res and low res pdfs

3. Illustrator asks me to choose a destination.

4. Illustrator saves each file as a High Res PDF and adds the the "_HR" suffix.

5. Illustrator then re-saves the open windows as a Low Res PDF and replaces the "_HR" suffix with "_LR".

 

Here is the code for the High Res script, The Low Res script is pretty much the same except for a different preset name and different suffix. Any pointer that anyone could give me would be most appreciated. I am pretty much a noob to this stuff so please keep that in mind.

 

Thanks!

Mike

 

---------------------------CODE----------------------------

 

/** Saves every document open in Illustrator

  as a PDF file in a user specified folder.

*/

 

 

// Main Code [Execution of script begins here]

 

 

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 destFolder = null;

  destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );

 

 

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

 

  // Get the PDF options to be used

  options = this.getOptions();

  // You can tune these by changing the code in the getOptions() function.

 

  for ( i = 0; i < app.documents.length; i++ ) {

  sourceDoc = app.documents[i]; // returns the document object

 

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);

 

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  alert( 'Documents saved as PDF' );

  }

  }

  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. --------------------CHANGE PDF PRESET BELOW, var NamePreset = ----------------

  @return PDFSaveOptions object

*/

function getOptions()

{var NamePreset = 'Proof High Res PDF';

  // Create the required options object

  var options = new PDFSaveOptions();

     options.pDFPreset="High Res PDF";

  // See PDFSaveOptions in the JavaScript Reference for available options

 

  // Set the options you want below:

 

 

  // 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;

}

 

 

/** Returns the file to save or export the document into.----------------CHANGE FILE SUFFIX ON LINE BELOW, var newName = ------------------

  @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 = "_HR";

 

 

  // 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;

  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;

}

SVG and JS problem

$
0
0

i am making a world map in SVG and i have to make such dialog boxes with some contact info and stuff... the text in the boxes are typography elements and every country has its own dialog box

 

for instance norway: dialog-no

 

and they are all grouped

 

 

 

then i go into javascript

 

and use this code

 

$("#norway").click(function(){

 

 

    $("#dialog-no").show(); 

 

 

    });

 

to show the boxes, but when i click inspect it says that the id of the norway country is something with polygon #norway .st7

 

so i tried type that inside the click function, but still nothing appears! what the heck is wrong here?

Delete Multiple Layers via Script

$
0
0

This should be fairly easy, I have tried to make one myself, but haven't gotten it right yet.

 

What I need to accomplish:

Have a script delete Layers by name, even if locked / hidden / have sublayers with art.

 

Example Layers:

Anchor Point

Center guides

Original

 

Also something not case sensitive would be preferable.

 

I started by just repeating this "app.activeDocument.layers.getByName('Anchor Point').remove();" with the different layers typed in, but it errors out when it tries to remove a layer that's not there in the specific file.

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!


Adding enter or return key to an action

$
0
0

Hi all thanks for viewing this and thanks in advance for any help you can provide.  This might an easy thing to do but I've searched all over and haven't found an answer.  I'm running some variable data and I would like to print each piece once it's complete.  The problem I'm encountering is in my "batch" I add the action "Print" and it gets to the print script which I have to manually hit enter.  I've tried to find away to automate this by seeing if there's away to automate the "enter" key but unfortunately I have no luck thus far.  Does anyone know a work around for this?  I would like to do this in illustrator.  Please no recommendations to do this in other programs.  Thank you so much in advance!

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 multiple artboards to individual PDFs... All artboards still exist in AI

$
0
0

I'm rewriting some export scripts of mine and I've just come across something strange...

 

Part of my multi-export script saves a PDF for each artboard. The code looks something like this:

 

  for ( var i = starting_artboard; i < num_artboards; i++ ) {    starting_artboard = doc.artboards.setActiveArtboardIndex(i);    var saveOptions = new PDFSaveOptions();    saveOptions.compatibility = PDFCompatibility.ACROBAT6;    saveOptions.generateThumbnails = true;    saveOptions.preserveEditability = true;    saveOptions.artboardRange = i+1;    doc.saveAs( dest, saveOptions );  }

 

Now, this works perfectly, and I get a PDF for each artboard... until I open one of those PDFs back up in Illustrator and all the artboards are still there. So each PDF has all the artboards (not just the content of the artboards, but the actual artboards, still named and placed as they were). Weirdly the artboards don't exist *anywhere* else. They don't exist if I open the PDFs in Acrobat, Photoshop, any random PDF viewer, anywhere; only in Illustrator.

 

Any idea why and how I can fix this? I'm hoping I'm missing something obvious and I don't have to copy the artboard to a new temp doc and save that, but I can't find anything in PDFSaveOptions that should be causing this.

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");

Add Margins in Illustrator

$
0
0

I have made this little script to quickly add margins to an illustrator document and am posting it here to anyone that might find this helpful.

 

The script will bring up a dialog where you can enter the sizes. Checking the equal box makes all sizes the same as the first.

You have the option of using Millimetres, Inches or Pixels for your units and a last option to apply to all artboards or just the active one.

 

The script then adds the guides to a locked layer called 'Margins' for convenience.

 

There are two versions for your taste- The first creates 4 seperate guidelines. The second creates one rectangle guide.

 

#target illustrator
var docRef = app.activeDocument;
var artboardRef = docRef.artboards;
var workingLayer = docRef.activeLayer;

//window
var win = new Window('dialog', "Add Margins");
this.windowRef = win;

//panels
win.fieldpanel = win.add("panel", undefined, "");
win.radiopanel = win.add("panel", undefined, "");
win.radiopanel2 = win.add("panel", undefined, "");

//panel orientation
win.fieldpanel.orientation='row';
win.radiopanel.orientation='row';
win.radiopanel2.orientation='row';

//fieldpanel
win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");
win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");
win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");
win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");
win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");
win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");
win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

win.fieldpanel.panel1.left_input.characters = 5;
win.fieldpanel.panel2.right_input.characters = 5;
win.fieldpanel.panel3.top_input.characters = 5;
win.fieldpanel.panel4.bottom_input.characters = 5;

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

//radiopanel
win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");
win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");
win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

//radiopanel2
win.radiopanel2.radio1 = win.radiopanel2.add('radiobutton',undefined, "All Artboards");
win.radiopanel2.radio2 = win.radiopanel2.add('radiobutton',undefined, "Active Artboard");

//select first radio buttons
win.radiopanel.radio1.value = true;
win.radiopanel2.radio1.value = true;

//ok button
win.okbutton = win.add('button', undefined, "Ok");

//disable fields with checkbox and equal values
win.fieldpanel.check1.onClick = function() {
  if(win.fieldpanel.check1.value){    var leftvalue = win.fieldpanel.panel1.left_input.text;    win.fieldpanel.panel2.right_input.text = leftvalue;    win.fieldpanel.panel3.top_input.text = leftvalue;    win.fieldpanel.panel4.bottom_input.text = leftvalue;       win.fieldpanel.panel2.right_input.enabled = false;    win.fieldpanel.panel3.top_input.enabled = false;    win.fieldpanel.panel4.bottom_input.enabled = false;  } else {    win.fieldpanel.panel2.right_input.enabled = true;    win.fieldpanel.panel3.top_input.enabled = true;    win.fieldpanel.panel4.bottom_input.enabled = true;  }
};

//sync values while checked
win.fieldpanel.panel1.left_input.onChanging = function (){
  if(win.fieldpanel.check1.value){    var leftvalue = win.fieldpanel.panel1.left_input.text;    win.fieldpanel.panel2.right_input.text = leftvalue;    win.fieldpanel.panel3.top_input.text = leftvalue;    win.fieldpanel.panel4.bottom_input.text = leftvalue;  }
};

//event listener for ok button
win.okbutton.onClick = function(){
  var leftvalue = win.fieldpanel.panel1.left_input.text;  var rightvalue = win.fieldpanel.panel2.right_input.text;  var topvalue = win.fieldpanel.panel3.top_input.text;  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;   if(win.radiopanel.radio1.value) {    var multiplier = 2.834645669291339  }  if(win.radiopanel.radio2.value) {    var multiplier = 72  }  if(win.radiopanel.radio3.value) {    var multiplier = 1  }  //close window  win.close();   //make a margins layer  var guideLayer = docRef.layers.add();  guideLayer.name = "Margins";    if(win.radiopanel2.radio1.value) {      //repeat for each artboard    for(i=0;i<artboardRef.length;i++){      //get artboard size      var left=artboardRef[i].artboardRect[0];      var top=artboardRef[i].artboardRect[1] ;      var right=artboardRef[i].artboardRect[2] ;      var bottom=artboardRef[i].artboardRect[3] ;      //create lines      var lineLeft = docRef.pathItems.add();      var lineRight = docRef.pathItems.add();      var lineTop = docRef.pathItems.add();      var lineBottom = docRef.pathItems.add();      //set line points      var leftmargin = (leftvalue * multiplier);      var rightmargin = (rightvalue * multiplier);      var topmargin = (topvalue * multiplier);      var bottommargin = (bottomvalue * multiplier);           //set line points      lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);      lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);      lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);      lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);           //make lines guides      lineLeft.guides = true;      lineRight.guides = true;      lineTop.guides = true;      lineBottom.guides = true;    };  } else {    //get artboard size    var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB    var left = activeAB.artboardRect[0];    var top = activeAB.artboardRect[1] ;    var right = activeAB.artboardRect[2] ;    var bottom = activeAB.artboardRect[3] ;    //create lines    var lineLeft = docRef.pathItems.add();    var lineRight = docRef.pathItems.add();    var lineTop = docRef.pathItems.add();    var lineBottom = docRef.pathItems.add();    //set line points    var leftmargin = (leftvalue * multiplier);    var rightmargin = (rightvalue * multiplier);    var topmargin = (topvalue * multiplier);    var bottommargin = (bottomvalue * multiplier);    //set line points    lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);    lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);    lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);    lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);    //make lines guides    lineLeft.guides = true;    lineRight.guides = true;    lineTop.guides = true;    lineBottom.guides = true;  };   //lock margins layer and activate original layer  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);  guideLayer.locked = true;  docRef.activeLayer = workingLayer; 
 };

win.show();

 

 

Box Margin Version:

#target illustrator
var docRef = app.activeDocument;
var artboardRef = docRef.artboards;
var workingLayer = docRef.activeLayer;

//window
var win = new Window('dialog', "Add Margins");
this.windowRef = win;

//panels
win.fieldpanel = win.add("panel", undefined, "");
win.radiopanel = win.add("panel", undefined, "");
win.radiopanel2 = win.add("panel", undefined, "");

//panel orientation
win.fieldpanel.orientation='row';
win.radiopanel.orientation='row';
win.radiopanel2.orientation='row';

//fieldpanel
win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");
win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");
win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");
win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");
win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");
win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");
win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

win.fieldpanel.panel1.left_input.characters = 5;
win.fieldpanel.panel2.right_input.characters = 5;
win.fieldpanel.panel3.top_input.characters = 5;
win.fieldpanel.panel4.bottom_input.characters = 5;

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

//radiopanel
win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");
win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");
win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

//radiopanel2
win.radiopanel2.radio1 = win.radiopanel2.add('radiobutton',undefined, "All Artboards");
win.radiopanel2.radio2 = win.radiopanel2.add('radiobutton',undefined, "Active Artboard");

//select first radio buttons
win.radiopanel.radio1.value = true;
win.radiopanel2.radio1.value = true;

//ok button
win.okbutton = win.add('button', undefined, "Ok");

//disable fields with checkbox and equal values
win.fieldpanel.check1.onClick = function() {
  if(win.fieldpanel.check1.value){    var leftvalue = win.fieldpanel.panel1.left_input.text;    win.fieldpanel.panel2.right_input.text = leftvalue;    win.fieldpanel.panel3.top_input.text = leftvalue;    win.fieldpanel.panel4.bottom_input.text = leftvalue;       win.fieldpanel.panel2.right_input.enabled = false;    win.fieldpanel.panel3.top_input.enabled = false;    win.fieldpanel.panel4.bottom_input.enabled = false;  } else {    win.fieldpanel.panel2.right_input.enabled = true;    win.fieldpanel.panel3.top_input.enabled = true;    win.fieldpanel.panel4.bottom_input.enabled = true;  }
};

//sync values while checked
win.fieldpanel.panel1.left_input.onChanging = function (){
  if(win.fieldpanel.check1.value){    var leftvalue = win.fieldpanel.panel1.left_input.text;    win.fieldpanel.panel2.right_input.text = leftvalue;    win.fieldpanel.panel3.top_input.text = leftvalue;    win.fieldpanel.panel4.bottom_input.text = leftvalue;  }
};

//event listener for ok button
win.okbutton.onClick = function(){
  var leftvalue = win.fieldpanel.panel1.left_input.text;  var rightvalue = win.fieldpanel.panel2.right_input.text;  var topvalue = win.fieldpanel.panel3.top_input.text;  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;   if(win.radiopanel.radio1.value) {    var multiplier = 2.834645669291339  }  if(win.radiopanel.radio2.value) {    var multiplier = 72  }  if(win.radiopanel.radio3.value) {    var multiplier = 1  }  //close window  win.close();   //make a margins layer  var guideLayer = docRef.layers.add();  guideLayer.name = "Margins";    if(win.radiopanel2.radio1.value) {      //repeat for each artboard    for(i=0;i<artboardRef.length;i++){      //get artboard size      var top=artboardRef[i].artboardRect[1] ;      var left=artboardRef[i].artboardRect[0];      var width=artboardRef[i].artboardRect[2]-artboardRef[i].artboardRect[0];      var height=artboardRef[i].artboardRect[1]-artboardRef[i].artboardRect[3];           //set margin sizes      var leftmargin = (leftvalue * multiplier);      var rightmargin = (rightvalue * multiplier);      var topmargin = (topvalue * multiplier);      var bottommargin = (bottomvalue * multiplier);           //create box      var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);      box.fillColor = box.strokeColor = new NoColor();      //make box guides      box.guides = true;    };  } else {    //get artboard size    var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB    var left = activeAB.artboardRect[0];    var top = activeAB.artboardRect[1] ;    var width = activeAB.artboardRect[2]-activeAB.artboardRect[0];    var height = activeAB.artboardRect[1]-activeAB.artboardRect[3];       //set margin sizes    var leftmargin = (leftvalue * multiplier);    var rightmargin = (rightvalue * multiplier);    var topmargin = (topvalue * multiplier);    var bottommargin = (bottomvalue * multiplier);       //create box    var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);    box.fillColor = box.strokeColor = new NoColor();    //make box guides    box.guides = true;  };   //lock margins layer and activate original layer  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);  guideLayer.locked = true;  docRef.activeLayer = workingLayer; 
 };

win.show();

Viewing all 12845 articles
Browse latest View live


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