• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Illustrator Script

New Here ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

I'm brand new to scripting, and have been trying to work my way through a problem.  I have imported a pdf into Illustrator.  It contains numerous objects located in 8 specific areas.  I need to move the data to different locations on the art board.  What I have been doing, is selecting all the objects in each area, making a group of that data (to preserve it's layout), and then moving it to a new specific area (basically, it's outside of the page margins and I'm moving it within the page margins).  This is getting old doing it by hand, as I have over 200 pages of data modify.

I've figured out how to select each artboard in turn (usually 5 to 7 pages).  Now I'm trying to figure out how to select everything in a specified range of coordinates and then group them together, move the group the a new set of coordinates, and then move onto the next selection.

Any hints would be great,

Thanks,

Steve Ford

TOPICS
Scripting

Views

728

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
May 04, 2016 May 04, 2016

Copy link to clipboard

Copied

does this give you a place to start

// SELECTION

// these are pt values

var x = 1300;

var y = 200;

var w = 500;

var h = 1000;

// NEW POSITION

var X = 0;

var Y = 0;

// now put in array

var box = new Array(x,y,w+x,y-h);

var pos = new Array(X,Y);

var doc = app.activeDocument;

doc.selection = null;

var abs = doc.artboards;

var newPage = abs.add(box);

newPage.name = "temp_page";

doc.selectObjectsOnActiveArtboard(); 

app.executeMenuCommand ('group')

var sel = doc.selection

sel[0].position = pos;

newPage.remove();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

First off, this has helped a lot.  I've been playing around with it and have some pretty basic questions.  What do the coordinates correspond too?  I assumed the x and y would be the top left corner, but after playing around with it, it looks like it's the bottom left corner.  I was wondering why the box array had y-h instead of y+h, but when I tried changing it things broke.  Going on the assumption of bottom left, I was able to get one group positioned correctly.

I'm trying to center each group in a box, and the groups are different sizes.  Is there any way to do that?  I assume if I can get the selection size, I can do some simple math to make it work.

Just so I've got it straight in my head, The script starts by defining the selection and position variables, Creates an array defining the selection box and an array defining the new location.

I get kind of lost in the next part, I think it selects the active document, clears any active selections, not sure about the next two line, but I think it makes a new artboard the same size as the selection and calls it temp page.

selects objects, and groups them, moves them and removes the temp page.

What is the purpose of the temp page?

I know this is pretty basic stuff, I haven't done any programming in about a decade.  Is their a Illustrator scripting book for dummies or something you would recommend?

Thanks,

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 05, 2016 May 05, 2016

Copy link to clipboard

Copied

var box = new Array(x,y+h,w+x,y);

this should fix the position, let me know if it still seems out, I did not want to mess with coordinate systems for a simple script.

quick run through.

x,y,w,h variables are the selection zone.

    you could get these via script, a dialog, or hard code them if every document has the wanted items in the same location

X,Y is the top left corner of the new location EDIT: Bottom Left... but now I'm confusing myself

    if you want it centered to an object that can be done, but we can do that when I get more info

box is just an array of the selection zone (this has just a smige of math, And I stuffed it up...)

pos is also just an array, both of these are just preparing the data for use. makes things cleaner.

now we clear any selection as we will be working with selected items and don't want to effect other random object that may have been selected before the script was run.

now I should be clear that this next section is a little bit of a hack in an effort to reduce the amount of code and make it feel simple and logical.

a more correct method would be to loop all objects testing each location, if it falls within the selection zone move it.

but as there is a built in function to select everything on an artboard I am making use of that by turning the selection zone into an artboard.

so thats the next stage, make an artboard, give it size and pos, name it (just in case script is stopped half way, we can recognize the added artboard with ease)

now the built in function to select artboard contents

next we group, again I have used a built in command for group, this again could be done with a more pure javascript approach, but this one liner dose the job and makes the code simple to follow

now all thats left is to move the selection and delete the temp page. Done.

this last stage is where you want to make a few changes. if we give the script X,Y as the center coordinates of the box you want to center to, then if we do a little math to the pos variable we can get our selection centered to the X, and Y,

lets keep X,Y both at 0 to start,

concider:

var sel = doc.selection

var Sh = sel[0].height;

var Sw = sel[0].width;

var pos = new Array(X-(Sw/2),Y+(Sh/2));

try this one...

// SELECTION 

// these are pt values 

var x = 700; 

var y = 0; 

var w = 500; 

var h = 850; 

 

// NEW POSITION 

var X = 0; 

var Y = 0; 

 

// now put in array 

var box = new Array(x,y+h,w+x,y); 

 

var doc = app.activeDocument; 

doc.selection = null; 

var abs = doc.artboards; 

var newPage = abs.add(box); 

newPage.name = "temp_page"; 

 

doc.selectObjectsOnActiveArtboard();   

 

app.executeMenuCommand ('group') 

var sel = doc.selection

var Sh = sel[0].height;

var Sw = sel[0].width;

var pos = new Array(X-(Sw/2),Y+(Sh/2));

sel[0].position = pos; 

newPage.remove(); 

as for reference material for scripting, I use (and I'll try to keep most used to least)

http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/CC/Illustrator%20Sc...

this is the official doc, sorely lacking.

then I go to google, this form tends to come up trumps in most searches, but sites like w3 and the like have craploads of info on javascript,

as you get used to the illustrator dom you will get a better understanding of the differences between JS for web, and JS run localy.

and Use the ESTK. the data browser is a must and it's object model viewer is also very important.

to get to where I am I just spent time here in the forums answering questions, if I don't know the answer I look for one. test it out, and post if I can get it to work.

this is good real world experience, and gives a great overview of what you can and can't do.

I have also met some great folk here in the forums that have been a great source of info, inspiration, and ideas.
stick at it, ask any questions you have, and post any snippets you find interesting and/or useful, and in no time you will be churning out little time savers.

wow, what a rant, Sorry...

EDIT: the coordinate system in this does not seem 100%.

I think adding the extra page may change it somehow.

I'll think on it, not that I think it will have any detrimental effects, all it need to do is "the correct thing", as long as it does that who cares... LOL

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2016 May 06, 2016

Copy link to clipboard

Copied

LATEST

Thanks a lot for your help.  I've got an idea of what I want to do, but not knowing the exact term to google is a real pain. 

Ok, I've got it pretty much working.  I have eight areas on a 8.5 x 11 artboard that need to be moved in slightly to print correctly.  Each area will will eventually be cut into roughly name tag size cards after printing.  So I've got it setup with nested loops to first properly arrange the four rows in the first column, and then repeat it for the second column.  That's all working great now.  I had to do some tweaking to the initial selection box size and finally got it all working last night.  Cleaned up the code this morning, and it's still working!

The last operation on this is to repeat the process on each artboard in the file (usually between 5 and 8 artboards.  I should be able to create another loop to do that.  I thought I had this working, but not quite.  I'm going to be traveling for a week, and so I might not be able to check this, but thanks again for all your help.

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines