: How do I position an InDesign object using Javascript? I'm working on a calendar in InDesign and I have a circle object (oval) that I want to position over the day of the month: I'm pretty
I'm working on a calendar in InDesign and I have a circle object (oval) that I want to position over the day of the month:
I'm pretty sure it should be possible to write a script that sets the x,y position properties of the oval object on each page to the proper values. I've already got the seven x values and the 6 y values that make up the month-grid, but I'm very new to JavaScript so I don't know how to get started. The sample scripts I saw were very involved, and I think what I want to do is much simpler, albeit with some iterations, etc.
If anyone can help me script the basics to get me started I would greatly appreciate it.
More posts by @Steve758
2 Comments
Sorted by latest first Latest Oldest Best
Here is a proposal:
var main = function() {
var doc = app.properties.activeDocument,
today = (new Date()).getDate(),
found, x1, x2, y1, y2;
if ( !doc ) return;
app.findGrepPreferences = null;
app.findGrepPreferences.properties = {
findWhat : "^"+today+"$",
pointSize:24
};
found = doc.findGrep();
if ( !found.length ) {
alert("Nothing found");
return;
}
found = found[0];
if ( !found.parentTextFrames.length ) {
alert( "The text may be overriding. Script can't continue" );
return;
}
x1 = found.horizontalOffset;
x2 = found.endHorizontalOffset;
y1 = found.baseline;
y2 = y1-found.ascent;
pz = found.pointSize;
xc = (x1+x2)/2;
yc = (y1+y2)/2;
var p = found.parentTextFrames[0].parentPage;
var dateLayer = doc.layers.item ( "dateLayer");
dateLayer.isValid && dateLayer.remove ();
dateLayer = doc.layers.add ( {name:"dateLayer"} );
dateLayer.move ( LocationOptions.AT_BEGINNING );
var o = p.ovals.add ( {
geometricBounds:[yc-pz/3, xc-pz/3,yc+pz/3, xc+pz/3],
strokeColor:"Black",
strokeWeight:2,
itemLayer:dateLayer
});
}
var u;
app.doScript ( "main();",u,u,UndoModes.ENTIRE_SCRIPT, "Mark date" );
Yes, it is possible to position an InDesign object via scripting.
First you need to somehow adress the oval, so you can later move it. If it is the only oval on the spread you can use
var myOval = app.activeWindow.activeSpread.ovals.firstItem();
to save the oval in the variable myOval.
Afterwards you can just use
myOval.move([x, y]);
to move the oval into its position. Is this enough info to get you started?
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.