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

How to duplicate artboard and move it relative to original?

$
0
0

Basically, I have an open AI document and would like to duplicate its artboard and then move it to a new position(X axis, 50pixels away from the original). Doesn't seem too hard, but I can't figure it out. This is for CS5.

 

 

 

var docRef = app.activeDocument;

 

var abSrc = docRef.artboards[0];

var abSrcX = abSrc.artboardRect[0];

var abSrcY = abSrc.artboardRect[1];

var abSrcW = abSrc.artboardRect[2];

var abSrcH = abSrc.artboardRect[3];

abSrcX = abSrcX + 1221;

var abSrcRect = [abSrcX, abSrcY, abSrcW, abSrcH];

 

 

var dupAB = docRef.artboards.add(abSrcRect);

 

The above works somewhat. Original artboard is 17" x 11" (1224px x 792px) and when I set abSrcX to anything above 1221, extendscript throws a PARM error. During one of my trial and error sessions, i decided to see what the geometricBounds of the document was:

 

$.writeln(docRef.geometricBounds); = 45,-12,1221.154296875,-780

 

So now I kinda see where I can't go over 1221, but why can't I?

 

I moved the artboard to the very top left of the document and i got the geometricBounds again and they were -6754.5,7038.5,-6463.5,6736.5, but still can't set abSrcX to anything over 1221.

 

the error is "an Illustrator error occurred: 1246458189 ('PARM')"

 

I've been trying to figure this out every which way that I can think of, but nothings working. Any help or input would be GREATLY appreciated!

 

EDIT:

 

So I tried this for the hell of it:

 

var abSrcX = 0;

var abSrcY = 1224;

var abSrcW = 1224;

var abSrcH = 792; (for some reason 792 translates to 6" inside illustrator, so i set this 432 to make it 11")

var abSrcRect = [abSrcX, abSrcY, abSrcW, abSrcH];

 

var dupAB = docRef.artboards.add(abSrcRect);

 

and it adds a new artboard and moves it to X, Y as designated. Not exactly what I want, but narrowing down the issue.

 

I try

 

var abSrcX = 1224;

var abSrcY = 0;

var abSrcW = 1224;

var abSrcH = 792;

var abSrcRect = [abSrcX, abSrcY, abSrcW, abSrcH];

 

var dupAB = docRef.artboards.add(abSrcRect);

 

and it throws that PARM error again, so now it really makes no sense!

 

EDIT2: i changed abSrcY to 10000 and now the artboard's height is really long, which makes even no more sense....unless I have the artboardRect(x, y, width, height) down wrong?

 

EDIT3: So after searching google some more, I found out what the problem is. artboardRect is TOP, LEFT, BOTTOM, RIGHT; and when I do:

 

var abSrcX = 1368;

var abSrcY = 0;

var abSrcW = 2592;

var abSrcH = -792;

   

var abSrcRect = [abSrcX, abSrcY, abSrcW, abSrcH];

//top left right bottom;

   

var dupAB = docRef.artboards.add(abSrcRect);

 

It works. BUT, I have no idea what the numbers are in relation to. The center of the artboard? Center of the document? And if I run it again and change...oh dear.

I think I just figured it out.

 

abSrcX is LEFT;

abSrcY is TOP;

abSrcW is RIGHT;

abSrcH is BOTTOM;

 

Taking that into account if I add (1224 + 144) to abSrcX and abSrxW it creates another artboard 2" away from the previous at 17" x 11". If I want to run it again, I just to add (1224 + 144) to abSrcX and abSrxW again. Now to figure out how to do this dynamically on the fly.

 

I would still like to hear some input on whether this is right or wrong and how I can improve it!


Viewing all articles
Browse latest Browse all 3671


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