• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Want to to create automatic textframe using java script

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

369

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
community guidelines
Explorer ,
Apr 22, 2020 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"

Votes

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
community guidelines
New Here ,
Apr 22, 2020 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

Votes

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
community guidelines
Community Expert ,
Apr 22, 2020 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

 

Votes

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
community guidelines
Explorer ,
Apr 22, 2020 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")

 

 

 

Votes

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
community guidelines
Community Expert ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

Votes

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
community guidelines
Community Expert ,
Apr 22, 2020 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 )

Votes

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

Copy link to clipboard

Copied

LATEST

Thanks for the link! I've been reading an old object model reference, I believe. šŸ™‚

Votes

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
community guidelines
Community Expert ,
Apr 22, 2020 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 )

Votes

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
community guidelines
Enthusiast ,
Apr 22, 2020 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

Votes

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
community guidelines
Community Expert ,
Apr 22, 2020 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.

Votes

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
community guidelines