Highlighted

Want to to create automatic textframe using java script

New Here ,
Apr 22, 2020

Copy link to clipboard

Copied

Hello all,

I am trying to create a script for textframe which i can used everytime, because  most of content is similar for every document.

i tried this one 

var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["12p", "35p", "10p", "10p"];
myTextFrame.contents = "®/™ ©2020. All rights reserved.";
myTextFrame.parentStory.appliedFont = "Helvetica NeueLT Std 55 Roman"//Change with the name of the font you want

 

 

but  error occured that font family is not available , actually its available in system.

please help me to sort out this issue

TOPICS
Scripting

Views

143

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

Want to to create automatic textframe using java script

New Here ,
Apr 22, 2020

Copy link to clipboard

Copied

Hello all,

I am trying to create a script for textframe which i can used everytime, because  most of content is similar for every document.

i tried this one 

var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["12p", "35p", "10p", "10p"];
myTextFrame.contents = "®/™ ©2020. All rights reserved.";
myTextFrame.parentStory.appliedFont = "Helvetica NeueLT Std 55 Roman"//Change with the name of the font you want

 

 

but  error occured that font family is not available , actually its available in system.

please help me to sort out this issue

TOPICS
Scripting

Views

144

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
Apr 22, 2020 0
Explorer ,
Apr 22, 2020

Copy link to clipboard

Copied

Hi,

Try with only the font family name. 

myTextFrame.parentStory.appliedFont = "Helvetica NeueLT Std"

Worked here with Arial.

If you need to specify the font style, you can write

myTextFrame.parentStory.fontStyle = "55 Roman"

or

myTextFrame.parentStory.paragraphs [i].fontStyle = "55 Roman"

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...
Apr 22, 2020 0
New Here ,
Apr 22, 2020

Copy link to clipboard

Copied

yes i tried with Helvetica LT Std and was working but not for Helvetica Neue LT Std

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...
Apr 22, 2020 0
Adobe Community Professional ,
Apr 22, 2020

Copy link to clipboard

Copied

The createMissingFontObject method should work:

 

 

var myDocument = app.documents.add();

//parameters fontFamily, fontStyleName, postscriptName
var myMF = myDocument.createMissingFontObject ("Helvetica NeueLT Std 55 Roman", "Roman", "Helvetica NeueLT Std 55-Roman")


var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["12p", "35p", "10p", "10p"];
myTextFrame.contents = "®/™ ©2020. All rights reserved.";
myTextFrame.parentStory.appliedFont = myMF

 

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...
Apr 22, 2020 0
Explorer ,
Apr 22, 2020

Copy link to clipboard

Copied

Nice function. Where did you unearth that from?

Here works the following code.

 

var myMF = myDocument.createMissingFontObject ("Helvetica Neue LT Std", "55 Roman", "Helvetica Neue LT Std 55-Roman")

 

 

 

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...
Apr 22, 2020 0
Adobe Community Professional ,
Apr 22, 2020

Copy link to clipboard

Copied

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...
Apr 22, 2020 0
Adobe Community Professional ,
Apr 22, 2020

Copy link to clipboard

Copied

Hi bgfrhlp,

believe it or not, document method createMissingFontObject() is in InDesign CC 2015 version 11 or above.

 

Regards,
Uwe Laubender

( ACP )

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...
Apr 22, 2020 0
bgfrhlp LATEST
Explorer ,
Apr 22, 2020

Copy link to clipboard

Copied

Thanks for the link! I've been reading an old object model reference, I believe. 🙂

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...
Apr 22, 2020 0
Adobe Community Professional ,
Apr 22, 2020

Copy link to clipboard

Copied

Hi patilg5,

then troubleshoot it the following way:

 

Set some text with the desired font.

Select some text with the desired font.

Run the following code:

var textFrame = app.documents[0].pages[0].textFrames.add();
textFrame.properties =
{
geometricBounds : ["12p", "35p", "10p", "10p"] ,
contents : "®/™ ©2020. All rights reserved."
};
textFrame.parentStory.texts[0].appliedFont = 
app.selection[0].appliedFont ;

 

If that is working as expected find the appropriate string for the applied font's name:

var textFrame = app.documents[0].pages[0].textFrames.add();
textFrame.properties =
{
geometricBounds : ["12p", "35p", "10p", "10p"] ,
contents : app.selection[0].appliedFont.name
};
textFrame.parentStory.texts[0].appliedFont = 
app.selection[0].appliedFont ;

 

I would guess there is somewhere a tab in the name where you currently think there is a blank.

 

Regards,
Uwe Laubender

( ACP )

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...
Apr 22, 2020 0
Enthusiast ,
Apr 22, 2020

Copy link to clipboard

Copied

Yes, the font name requires a tab. In AppleScript we define it as:

set fontStr to familyName & " " & fontSttyle //tab is between quotes

if status of font fontSttr = installed then ...  //to check if the font is installed

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...
Apr 22, 2020 0
Adobe Community Professional ,
Apr 22, 2020

Copy link to clipboard

Copied

The JS createMissingFontObject works whether or not the font is installed. Its fontFamily parameter doesn’t include a tab—its just the name with no style. Style is the 2nd parameter.

 

I don’t think the equivalent is available in the AS dictionary.

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...
Apr 22, 2020 0