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

Change origin of artboard rulers

$
0
0

Hi everybody !

 

First, I am a beginner in javascript, so I'm sorry if I ask stupid questions

 

I set myself a goal for my first script : changing the origin of artboard rulers. After reading a million posts about this, I managed to change globals rulers but I still haven't succeeded to change artboard rulers. I need help for this first mission because I have no idea how to change the rulers.

 

Thank you very much !

 

Have a nice day


how to change gray scale color mode export jpeg in illustrator scripting

$
0
0

export to jpeg how to change color mode and resolution pls suggest correct solution.pls find below attachment...

thanks in Advance

Export_menu.jpgExport_menu2.jpgExport_menu3.jpg

Image Resolution - Text

$
0
0

Hi,

 

     Is there is any difference in illustrator for the below cases.

 

     1. Open pdf file which resolution is 400 in illustrator with the resolution 120 when open.

 

     2. Open pdf file which resolution is 400 in illustrator with the same resolution when open and then change the resolution to 120.

 

     Any difference in quality/display image?

 

    

     3. Is there is any version issue in lower and higher for the same process (point 1)?

 

 

Thanks,

Sudha K

Change Folder.current to location of script (.jsx) file?

$
0
0

All,

 

I'm trying to use some images in my ScriptUI dialog, but I want to use a "relative" path name, and I can't seem to get it to work.

For example, this myScript.jsx works just fine, but as you can see, I'm using an "absolute" path name to transparencyGrid.jpg:

 

var w = new Window ("dialog");
var f = new File ('~/Desktop/transparencyGrid.jpg');
w.add ("image", undefined, f); 
w.show ();

 

However, I want to be able to use a relative (to myScript.jsx) path to point at transparencyGrid.jpg, like this:

 

var w = new Window ("dialog");
var f = new File ('../../../transparencyGrid.jpg');
w.add ("image", undefined, f); 
w.show ();

 

But, I can't seem to get this to work because relative paths seem to be relative to the current folder, Folder.current, not the location of the currently executing script.

I say that because when I do this:

 

alert(Folder.current);

 

The only thing the alert message shows is a backslash (/), indicating to me that the current folder is the root of my OS, but I thought it would be the folder where myScript.jsx resides.

 

So, is there a way of setting Folder.current to the location of the actual script?

Send to back/front of other selected object by script?

$
0
0

Is there a way to do a script to send to back/front of other selected object, or to target the command send to back/front in relation to another object in the file? Even in different layers?

Ordering objects by size

$
0
0

Is there any way or method to order objects by size?  I have a bunch of closed, filled shapes (random circles and squares) and I would like to order them by area.  If there isn't a way to do it just in illustrator, could I export them to another program and do it there and then return them to illustrator?

ScriptUI Palette autocloses

$
0
0

In case when palette is created in included script, it autocloses on call.

Maybe someone could explain why and how to solve it?

When it's used not from external file, than it's working fine. So the issue and the target to make it work from external script as #include "PaletteDialog.jsx"

 

 

`include/PaletteDialog.jsx`

 

#target Illustrator
#targetengine 'main'

var PaletteDialog = function (name, components, options) {
   var window;   this.showTest = function() {   window = new Window("palette", "sample", undefined, {});   window.add("button", undefined, "test");   window.show();  };
};

 

 

 

`script.jsx`

#target Illustrator
#targetengine 'main'

#includepath "./include"
#include "PaletteDialog.jsx"

var PaletteDialog = PaletteDialog;

var paletteDlg = new PaletteDialog("Title", {}, {resizeable:true, closeButton:true});
paletteDlg.showTest();

ExtendScript Illustrator - Change color of text one character at a time.

$
0
0

I'm trying to write code for ExtendScript ToolKit to target Illustrator. I've been writing in JavaScript, but am open to switching to AppleScript if needed. The goal of the code is to change the characters in a text box one by one to the color of the image behind that letter. The end goal is to have the color of the text create the image.

 

Basically, I select a character. And lets say that character is at 720x648 (in pixels) in a 24x36 in image. Then I detect the color in the image layer at that location. Then turn the selected character to that color.

 

I have encountered two problems, finding a way to have the script detect the color of the picture at a given location (ideally in pixels) and then change that one character to that color.

 

So far my code is this, with a color hard coded in for testing purposes since I haven't figured out the detection part yet.

 

if ( app.documents.length > 0 ) {

var doc = app.activeDocument;

 

//get text from textbox

var numChars = 0;

textArtRange = doc.textFrames[0].contents;

numChars += textArtRange.length;

 

//loop through to select characters one at a time

for (x=0; x<numChars; x++){

     var selectChar=textArtRange.charAt(x)

     doc.characterStyles.removeAll();

     var charStyle=doc.characterStyles.add("NewOne");

     var charAttr=charStyle.characterAttributes;

     var detectedColor = new RGBColor();   //ideally the detected color would go here. But for now it is hard coded.

         detectedColor.red = 242;

         detectedColor.green = 51;

         detectedColor.blue = 51;

     charAttr.fillColor = detectedColor;

     charStyle.applyTo(selectChar); // I got an error here: "Object expected".

}//end for loop

 

 

To detect the color, I tried using the following code, but it only works in Photoshop and even there I can't find a way to store that color the way I need to.

 

app.activeDocument.colorSamplers.removeAll();

var pixelLoc = [UnitValue(16) , UnitValue(16)];

var myColorSampler = app.activeDocument.colorSamplers.add(pixelLoc);



I have put in so many hours into this and just want to rip my hair out. Any help or guidance anyone can give would be SO appreciated! Thanks in advance!!!



Align to bottom selection?

$
0
0

I edited a script from this forum (I think originally written by williamadowling) to align selection to bottom object. I want to modify it to add the "Bottom Object" to the selection by name so the user does not need to manually select it. The modification works… if I run the script twice. What am I doing wrong?

 

The starting selection is the "fingerprint" group. Here's a simplified AI file if it's helpful.

 

Thanks for your help.

 

var docRef = app.activeDocument;      var sel = docRef.selection;    var AlignObj = docRef.pageItems.getByName("PrintAlign");    AlignObj.selected = true;        function alignToObj()  
{      var keyCenter = getCenterPoint(AlignObj);     var curItem,curCenter;     const ALIGNMENT_PREFERENCE_VERTICAL = true;      const ALIGNMENT_PREFERENCE_HORIZONTAL = true;        for(var x=0, len = sel.length-1; x < len; x++)      {          curItem = sel[x];          if(ALIGNMENT_PREFERENCE_HORIZONTAL)          {              //align the object horizontally              curItem.left = keyCenter.h - curItem.width/2;          }          if(ALIGNMENT_PREFERENCE_VERTICAL)          {              //align the object vertically              curItem.top = keyCenter.v + curItem.height/2;          }      }      function getCenterPoint(item)      {          return {"h":item.left + item.width/2, "v":item.top - item.height/2};      }  
}  
alignToObj();  

Remove selected items on active artboard

$
0
0

I have written the below javascript for the below actions. Remove command is not working.

1) select the objects on active artboard

2) remove the selected objects

 

var doc = app.activeDocument;

doc.selectObjectsOnActiveArtboard()

removeAll();

Automation with scripts

$
0
0

Hi Community,

 

i tried my best with the actions panel in Illustrator, but could not compete how to jump to the layer i needed.

I started a conversation about it and was pointed to the scripting community. Link here if you are interested.

I read a bunch, copy pasted a bit, got stuck at a point and developed more needs on the way. Now i am desperate and ask you for advice.


Here is the situation. I have over 1000 files that are all structured in the same way.
Each contain 7 Layers:

- Info

- Arrows and Highlights

- Text

- Outlines

- Special interest

- Illustration

- Background

 

My task is to delete the layers "Info" and "Background".
Then i need to duplicate the layer "Text" - name this new layer "Text-font" and make it invisible and not printable.
Then jump to the original "Text" layer, select everything (there is only text there) and create outlines of the text.
Then rename this layer to "Text-vector".

 

This is how far i came.

//Delete the layer - "Background"
app.activeDocument.layers.getByName('Background').remove();  
//Delete the layer - "Info"
app.activeDocument.layers.getByName('Info').remove();  
//Go to Layer Text and select all the Text (just in case something else was in there
var docRef = app.activeDocument;  
var layers = docRef.layers;  
var myLayer = layers["Text"];  
docRef.selection = null;  
for(var a=0;a<myLayer.pageItems.length;a++){       var currentItem = myLayer.pageItems[a];       if(currentItem.typename == "TextFrame" || currentItem.typename == "GroupItem"){            currentItem.selected = true;       }  
}  
//Duplicate the active layer and name this layer "Text-vector"
var docRef = app.activeDocument;      
with(docRef) {          var ll = docRef.activeLayer ;       var n=docRef.layers.length;      x=ll.zOrderPosition;      var ln=ll.name;        var ol = layers.getByName(ln);          ll.visible = false;          var nl = layers.add();          nl.name = 'Text-vector';          for (var a = ol.pageItems.length-1; a >= 0; a--) {              ol.pageItems[a].duplicate(nl, ElementPlacement.PLACEATBEGINNING);              nl.visible = true;                     }      
}  
//Select "Text-vector"
app.activeDocument.layers["Text-vector"].hasSelectedArtwork = true;
//Create outlines
app.executeMenuCommand("outline");  

 

So far it works.

 

Now the only thing left was to save the file as AI with ICC Profile to a folder.

(Best case scenario: Same name with additional three letters on the back of the name.)
...and i am stuck.

 

Now i figured - scripting is a very powerful tool - there is another thing i could implement!
I could also create a greyscale version automaticly here.

But first i need to figure out how to save the file...

 

Could you please help me?

Batch relinking broken filelinks in .ai files

$
0
0

     Hi, am wondering if it's possible to relink files in batch , my gut is saying no as all scripts ive found for relinking files references internal functions such as "app.documents". Aim is to update lots of broken links in a company fileshare (some files are 300+ links). Are there any other options?

 

Files are hosted on a windows server, but published as an apple fileshare using some software. This works fine, but I had to rename a folder and its broken lots of filelinks as a result.

 

I want to essentially find and replace a broken link path for all .ai files in the directory and all subdirectories with the new amended path.

 

The loop in red is giving me an "undefined is not an object" error. I'm guessing app.documents.length is undefined.  I presume this should be where an input box appears when run from the scripts menu in the application. What am I missing?

 

Is there a way to relink files via script outside of illustrator? if there are xml files I can find and replace manually, this would be easier for me!

 

Any suggestions welcome!

 

The script is below:

 

var i, j, searchfolder;   

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

    doc = app.documents[j];   

   

    imgs = doc.links;   

    path = "afp://COMPANY-FP01 IP._afpovertcp._tcp.local/IllustratorScriptTest/";  //

    searchfolder = new Folder(path);   

 

   for (i=0; i<imgs.length; i++)   

    {   

        // Missing?   

    $.writeln("Image "+i);   

        if (imgs[i].status == LinkStatus.LINK_MISSING)   

        {   

        $.writeln("Missing: "+imgs[i].name+" lookign in "+searchfolder);   

            // Do we have a file?   

            imglist = findAnyFileDownThere(imgs[i].name, searchfolder);   

        $.writeln("Found "+imglist.length+" possible replacements.");   

            if (imglist.length == 1)   

            {   

                // Oh yeah   

                imgs[i].relink(imglist[0]);   

        $.writeln("Relinked to "+imglist[0]);   

            }   

        }   

    }   

}   

function findAnyFileDownThere (filename, path)   

{   

var result, folderList, fl;   

result = Folder(path).getFiles (filename+".*");   

if (result.length > 0)   

  return result;   

folderList = Folder(path).getFiles(function(item) { return item instanceof Folder && !item.hidden; });   

   

for (fl=0; fl<folderList.length; fl++)   

{   

        $.writeln("Looking in: "+path+"/"+folderList[fl].name);   

  result = findAnyFileDownThere (filename, path+"/"+folderList[fl].name);   

  if (result.length > 0)   

   return result;   

}   

return [];   

}   

UI palette to display status messages

$
0
0

Hi,

 

I have learned to create palettes and use bridgetalk to invoke actions in illustrator or retrieve values.

But how could I use a palette to display information coming from illustrator, e.g a status display that shows number of objects already processed by script.

It seems that I should use Bridgetalk.onReceive, but what would be the target to send to?

placeFiles.file Error 1230 file folder expected

$
0
0

I'm not sure what I'm doing wrong with this.  According to the documentation this should work no?

 

var placeFiles = aDoc.placedItems.add();

placeFiles.file = ("/Users/ohms/Dropbox/printing/file.ai");

 

I've also tried:

placeFiles.file = "/Users/ohms/Dropbox/printing/file.ai";

 

Both of these produce

Error 1230:File/Folder expected

Line: 26

placeFiles.file = same file path as above

 

I've seen a few suggestion on these errors but don't seem to be able to get it right on mine.

Script to import mysql data and use it as variable data

$
0
0

Is there any script to import data from mysql and use it as variable data?

Currently the option I'm looking at is getting data from mysql and using a json to csv converter and then using the csv in variable data.

However it seems like this is quite tiresome and can cause some errors if there's any invalid characters or problems int he json to csv.

I'm running cc2019 illustrator.  Any ideas how this can be accomplished?


Apply color of script before adding type

$
0
0

I'm trying to see if there's away to set the color of a textrange lines or characters.  For example:

 

Here is my script to input text

 

var text = doc.textFrames.add();

text.position = Array(900, 520);

textRange.size = 400;

text.contents = 'Scripting";

 

I would like to have a field like:

 

textRange.fillColor = (255, 255, 55); // these being RGB values or CMYK values.

I tried adding fillcolor and it didn't work.

 

Some resources I've read say that I'd have to loop through each character.  I'm not sure if that's correct.  I'm using illustrator cc2019.

Any ideas?

geometricsBounds of all selections

$
0
0

I just wonder if there is a  possibility get geometricBounds of all selection without using "app.executeMenuCommand("group")" ?

 

For example i have two separate rectangle and i want get geometricsBounds as if they were a group.

Now i use this method:

app.executeMenuCommand("group");
var groupBound  = doc.selection[0].geometricBounds;
app.executeMenuCommand("ungroup");

 

Can it be done better than through executeMenuCommand?

 

 

Relink AI files in AI document

$
0
0

Hello, there.

I'm trying to figure out how to relink AI files in my AI document even if this linked AI file is missing.

But, if it's missing, the ESTK gives me an error saying "there is no file associated with this item".

How the hell can I get even the missing linked (placed) files?

As my document has a lot of embedded items, I really don't know if the error is because of that embedded or the broken links.

 

Any help will be appreciated!

Batch Change Sub Layer Names with Top Layer Names

$
0
0

Hello,

 

I have two questions,

First Question;

In order to export illustrator files to software such as Cinema 4D with correct layer structure and name , there should only be the lowest sub layer (one path) but with the top layer's name. I could not find an exact script to do that. I have 1000 layers like this.

 

question_2.png

 

Second Question;I want to copy and paste the names of top layers for all layers.

question_1.png

 

Please help, I could not find an exact script to do that.

Thank you,

Best Regards.

Find and replace text SCRIPT

$
0
0

I have been trying to find a scrip that will help me replace a Hard return. This will not work with the menu action. Is any one able to help me. Im not the greatest at coding, I know a little but not enough to right this.

Viewing all 12845 articles
Browse latest View live