Skip to main content
levi23
Known Participant
August 13, 2016
Answered

change the position of a artboard using javascript

  • August 13, 2016
  • 3 replies
  • 2657 views

Hello such. I will see a silly question to which I have not found solution

You can change the position of a artboard using javascript?

Something like: it does not work.

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

abActive = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];

alert("abActive: "+abActive+"\n\n"+

"abActive.position[0]: "+abActive.position[0]+"\n\n"+

"abActive.position[1]: "+abActive.position[1]+"\n\n"

)

abActive.position = [500, 1000];

I searched for information and I have not found.

Thank you very much in advance.

a greeting

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi levi23​,

if I understand  you right – you want to move (only) the artboard without the page items?

You have to go the „long way“:

// artboardMove.jsx

// https://forums.adobe.com/thread/2194906

//        change the position of a artboard using javascript?

// regards pixxxelschubser

var aDoc = app.activeDocument;

//var abSrc = aDoc.artboards[0];

var abIdx = aDoc.artboards.getActiveArtboardIndex ();

var abSrc = aDoc.artboards[abIdx];

var moveX = 500;

var moveY = 1000;

var abSrc_L = abSrc.artboardRect[0] + moveX;

var abSrc_T = abSrc.artboardRect[1] - moveY;

var abSrc_R = abSrc.artboardRect[2] + moveX;

var abSrc_B = abSrc.artboardRect[3] - moveY;

abSrc.artboardRect = [abSrc_L, abSrc_T, abSrc_R, abSrc_B];

But be careful. Have always a look to the max artboard size/position.

Have fun

3 replies

levi23
levi23Author
Known Participant
August 16, 2016

It is done. sorry

thanks

levi23
levi23Author
Known Participant
August 15, 2016

Thank you very much for your help

it works great

regards

Silly-V
Legend
August 15, 2016

A two-part answer, if only they could each be marked as correct

pixxxelschubser
Community Expert
Community Expert
August 15, 2016

Hi Silly-V​,

yes, only the TO levi23​ can mark the correct answer.

But everyone else can mark a good answer as helpful answer.

Regards

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
August 13, 2016

Hi levi23​,

if I understand  you right – you want to move (only) the artboard without the page items?

You have to go the „long way“:

// artboardMove.jsx

// https://forums.adobe.com/thread/2194906

//        change the position of a artboard using javascript?

// regards pixxxelschubser

var aDoc = app.activeDocument;

//var abSrc = aDoc.artboards[0];

var abIdx = aDoc.artboards.getActiveArtboardIndex ();

var abSrc = aDoc.artboards[abIdx];

var moveX = 500;

var moveY = 1000;

var abSrc_L = abSrc.artboardRect[0] + moveX;

var abSrc_T = abSrc.artboardRect[1] - moveY;

var abSrc_R = abSrc.artboardRect[2] + moveX;

var abSrc_B = abSrc.artboardRect[3] - moveY;

abSrc.artboardRect = [abSrc_L, abSrc_T, abSrc_R, abSrc_B];

But be careful. Have always a look to the max artboard size/position.

Have fun

levi23
levi23Author
Known Participant
August 13, 2016

First of all many thanks for your answer, but I do not express well ... I meant to move the artboard and its contents. So it is trying to use the position property.

There is that possibility without using rearrange?

Thank you very much again.

Sorry my english. I am spanish.

a greeting.

Inspiring
August 13, 2016

To move all of the elements, you need should be able to just loop through all of the layers and just move them as well. Instead of moving them all individually, this code should group them, use the GroupItem Translate function, and then ungroup them.

// Get a reference to the layers and loop through them

var layers = aDoc.layers;

for( var i = 0, ii = layers.length; i < ii; i++ ) {

    // clear any current selection

    doc.selection = null;

   

    // select all elements in the current layer and group them

    layers.hasSelectedArtwork = true;

    app.executeMenuCommand( "group" );

   

    // translate them using the moveX and moveY variables

    var curGroup = layers.groupItems[0];

    curGroup.translate( moveX, -moveY );

   

    // ungroup them

    app.executeMenuCommand( "ungroup" );

}

Good luck!