Copy link to clipboard
Copied
Dear All,
I am trying to set the ruler origin to the top left in Artboard by using below javascript. But it is set on the bottom left.
Can you please guide me?
var doc = app.activeDocument;
app.activeDocument.rulerOrigin = [0,0];
1 Correct answer
Salut,
Si c'est pour l'origine globale (règles globales):
var doc = activeDocument;
doc.rulerOrigin = [0,doc.height]
Pour l'origine des règles du plan de travail, c'est différent: (réponse de Lumenn )
Explore related tutorials & articles
Copy link to clipboard
Copied
Does it change, when you select other artboards?
For me it's by default on top left of the artboards.
Try setting the coordinate system to artboard based:
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
Application — Illustrator Scripting Guide 0.0.1 documentation
Copy link to clipboard
Copied
Thanks for your reply Lumenn.
Normally it will come on the top left of the artboards.
By mistakenly, if i changed the ruler origin, how to make it to zero point by using javascript?
Copy link to clipboard
Copied
Then as i've found here:
Change origin of artboard rulers
Rulers are per artboard, you have to set the origin for each arboard, for example:
app.activeDocument.artboards[0].rulerOrigin = [0,0];
Will set the ruler to top left corner of 1st - [0] - artboard in the document
Copy link to clipboard
Copied
Thanks for your reply.
It is not working.
Copy link to clipboard
Copied
I can't find any scripting way to change ruler type from document to artboard.
When you change ruler type to artboard, then above code will work.
Maybe someone else have an indea how to change ruler type from script.
Coordinate system doesn't seem to have any ifnluence on this.
Copy link to clipboard
Copied
Salut,
Si c'est pour l'origine globale (règles globales):
var doc = activeDocument;
doc.rulerOrigin = [0,doc.height]
Pour l'origine des règles du plan de travail, c'est différent: (réponse de Lumenn )
Copy link to clipboard
Copied
Thank you so much. You are always excellent.
Copy link to clipboard
Copied
Is it possible to add this rule to my script? Not sure where this would be added. The script below uses a CSV file with W x H dimensions to create a new artboard from each entry. There is an issue when the dimensions are over 114 since each artboard is being created from the center. When you exceed half the distance of Ai's file area the artboard falls outside the working area. I need a soltion to change the starting point from the center to the X,Y 0 [top left] point of the file when creating a new artboard.
#target illustrator
function test () {
var COL_NAME = 0;
var COL_WIDTH = 1;
var COL_HEIGHT = 2;
var COL_CHAR = 3;
var OUTPUT_DIR = "~/Desktop/Artboards";
Folder(OUTPUT_DIR).create();
var csvFile = File.openDialog("Choose CSV file.", "*.csv");
var csvContents = "";
if (csvFile) {
csvFile.open('r');
csvContents = csvFile.read();
csvFile.close();
}
var csvData = csvContents.split(/[\r\n]+/g);
var thisRow;
for (var i = 0; i < csvData.length; i++) {
thisRow = csvData[i];
csvData[i] = thisRow.split(",");
}
var workDoc = app.documents.add();
var thisRecord, w, h, name, newRect, c;
var opts = new PDFSaveOptions();
var tframe = workDoc.textFrames.add();
for (var i = 1; i < csvData.length; i++) {
thisRecord = csvData[i];
name = thisRecord[COL_NAME];
w = thisRecord[COL_WIDTH] * 72;
h = thisRecord[COL_HEIGHT] * 72;
c = thisRecord[COL_CHAR];
newRect = workDoc.pathItems.rectangle(0, 0, w, h);
newRect.move(tframe, ElementPlacement.PLACEAFTER);
newRect.selected = true;
workDoc.fitArtboardToSelectedArt(0);
newRect.stroked = false;
tframe.contents = c;
tframe.textRange.characterAttributes.size = 120;
tframe.textRange.characterAttributes.fillColor = workDoc.swatches.getByName("White").color;
tframe.position = [newRect.left + newRect.width/2 - tframe.width/2, newRect.top - newRect.height/2 + tframe.height/2];
newRect.fillColor = workDoc.swatches.getByName("Black").color;
workDoc.saveAs(File(OUTPUT_DIR + "/" + name + ".pdf"), opts);
workDoc.pathItems[0].remove();
}
workDoc.close(SaveOptions.DONOTSAVECHANGES);
};
test();

