Highlighted

Javascript create text frame and apply object style on active document

New Here ,
Jul 27, 2020

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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

53

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Javascript create text frame and apply object style on active document

New Here ,
Jul 27, 2020

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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

54

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 27, 2020 0
Adobe Community Professional ,
Jul 27, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 27, 2020 1
cfebvre LATEST
New Here ,
Jul 28, 2020

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 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 28, 2020 0