Skip to main content
New Participant
January 29, 2024
Answered

Scripts / JavaScript

  • January 29, 2024
  • 3 replies
  • 950 views

Bonjours à vous mes amis graphiste et developpeurs, j'aurais besoin d'aide pour créer un Script dans Illustrator je m'explique : 

J'ai 500 fichiers à ouvrir -> Modifier la taille du plans de travail -> Save Exit 

J'ai cherché quelques scripts qui pourrait m'être utile afin d'automatisé tout ca, bémole je n'arrive pas à récupérer la taille de mon plan de travail avec la console JS : 

var doc = app.activeDocument;

var artboard = doc.artboards[0];

artboard.artboardRect = [0, 0, 300, 200];

 

> var doc = app.activeDocument;
var artboard = doc.artboards[0];
artboard.artboardRect = [0, 0, 300, 200];
Erreur: an Illustrator error occurred: 1346458189 ('PARM')
 
Connaissez vous une technique qui me permettrai de modifié ce "artboard" ? 
Les scripts d'actions ne reconnais pas les actions éffectué sur les plans de travails. 
Si quelqu'un à une idée ou la solution je suis preneur ! 
Bonne fin de journée à vous ! 
 
 

Hello, my friends in graphic design and development! I need help creating a script in Illustrator. Here's what I'm trying to achieve:

I have 500 files to open -> Modify the artboard size -> Save and close

I've searched for some scripts that could be useful to automate this, but I'm having trouble retrieving the artboard size with the JS console:

var doc = app.activeDocument;

var artboard = doc.artboards[0];

artboard.artboardRect = [0, 0, 300, 200];

 

> var doc = app.activeDocument;
var artboard = doc.artboards[0];
artboard.artboardRect = [0, 0, 300, 200];
Erreur: an Illustrator error occurred: 1346458189 ('PARM')
 

I'm getting an error: "An Illustrator error occurred: 1346458189 ('PARM')".

Do you know a technique that would allow me to modify this "artboard"? Action scripts don't seem to recognize actions performed on artboards.

If anyone has an idea or a solution, I would greatly appreciate it! Have a great day!

 

 

 

This topic has been closed for replies.
Correct answer RobOctopus

change the last number to be negative. My brain isn't remembering the reasons why, and I dont want to give you wrong information, but if you change the 200 in your rectangle coordinates to be -200 it should work.

app.activeDocument.artboards[0].artboardRect = [0, 0, 300, -200];

3 replies

femkeblanco
Brainiac
January 29, 2024

Back in CS5, the origin was changed from the left bottom to the left top.  So y values should be negative, as in the examples above. 

 

New Participant
January 30, 2024

Thank you guy for u'r answer ! 

GerssonDelgado
Inspiring
January 29, 2024

try this

function modificarTamaño(ancho, alto) {
  var mainArtb = app.activeDocument.artboards[0];
  var rect = mainArtb.artboardRect;
  var x = rect[0] + (rect[2] - rect[0]) / 2;
  var y = rect[1] + (rect[3] - rect[1]) / 2;
  mainArtb.artboardRect = [
    x - ancho / 2,
    y + alto / 2,
    x + ancho / 2,
    y - alto / 2,
  ];
}

modificarTamaño(300, 200);
New Participant
January 30, 2024

U'r function works but, the first answers by RobOctopus was more easy ahah 

RobOctopus
RobOctopusCorrect answer
Inspiring
January 29, 2024

change the last number to be negative. My brain isn't remembering the reasons why, and I dont want to give you wrong information, but if you change the 200 in your rectangle coordinates to be -200 it should work.

app.activeDocument.artboards[0].artboardRect = [0, 0, 300, -200];
New Participant
January 30, 2024

That's it ! Thank u so much 🙂