Copy link to clipboard
Copied
Hi all,
I'm hoping someone can point me in the right direction to learn some basic scripting.
I've followed the indesign scripting basics tutorial pdf to create the basic Helloworld text frame script. (javascript)
What I'd like to know is, how do I apply an object style to said text frame within that script (for my purposes, the object style will already exist on the active document).
Any guidance is much appreciated.
Regards,
Chris
Hi Chris,
Try the following
To run the code make a selection of a the textframe over which you want to apply the object style. If you already have the object then you can replace tf with the object instance that you have. Change the name Obj_Style_To_Apply to whatever is the name of your style
var tf = app.selection[0]
var os = app.documents[0].objectStyles.itemByName("Obj_Style_To_Apply")
if(os.isValid)
tf.applyObjectStyle(os)
To learn about the properties and methods available use the fol
...Copy link to clipboard
Copied
Hi Chris,
Try the following
To run the code make a selection of a the textframe over which you want to apply the object style. If you already have the object then you can replace tf with the object instance that you have. Change the name Obj_Style_To_Apply to whatever is the name of your style
var tf = app.selection[0]
var os = app.documents[0].objectStyles.itemByName("Obj_Style_To_Apply")
if(os.isValid)
tf.applyObjectStyle(os)
To learn about the properties and methods available use the following link
https://www.indesignjs.de/extendscriptAPI/indesign-latest/
-Manan
Copy link to clipboard
Copied
Hi Manan,
Thanks so much for your reply. With your help I was able to figure it out (sorry was on my mobile before and probably didn't explain myself very well. I actually needed the object style to be applied to the text frame in the same script, so:
var doc = app.activeDocument;
var textFrame = doc.pages[0].textFrames.add();
var objectStyle = app.documents[0].objectStyles.itemByName("BodyCopy")
textFrame.properties =
{
geometricBounds : [ 10 , 10 , 100 , 100],
strokeWidth : 0,
fillColor : "None",
contents : "Hello World!"
};
if(objectStyle.isValid)
textFrame.applyObjectStyle(objectStyle)
With this, I'll be able to do exactly what I need. Thanks so much 🙂