• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how script create text frame ?

Community Beginner ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

hi .

i want script to create text frame into indesign.

TOPICS
Scripting

Views

11.0K

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 ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

Moving (again) to InDesign Scripting

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 ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

Hi shahriara7551080 ,

would you please tell us what should be the Scripting language you like to use.

Regards,
Uwe

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 Beginner ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

extendscript

java script

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 ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

Here an example where also a new document is added:

var doc = app.documents.add();

var textFrame = doc.textFrames.add();

textFrame.properties =

{

    geometricBounds : [ 0,0,100,100 ],

    strokeWidth : 0,

    fillColor : "None",

    contents : "Hello World!"

};

Another one that is working with the active document:

var doc = app.activeDocument;

var textFrame = doc.pages[0].textFrames.add();

textFrame.properties =

{

    geometricBounds : [ 0,0,100,100 ],

    strokeWidth : 0,

    fillColor : "None",

    contents : "Hello World!"

};

Yet another example that is working with an open document with the index 0 :

var doc = app.documents[0];

var textFrame = doc.spreads[0].pages[0].textFrames.add();

textFrame.properties =

{

    geometricBounds : [ 0,0,100,100 ],

    strokeWidth : 0,

    fillColor : "None",

    contents : "Hello World!"

};

Note, that you could address the document, a spread or a page for adding the text frame.

In case of document, the first spread is addressed automatically.

Properties could be also added when using method add() :

var doc = app.documents[0];

var textFrame = doc.spreads[0].textFrames.add

(

    {

        geometricBounds : [ 0,0,100,100 ],

        strokeWidth : 0,

        fillColor : "None",

        contents : "Hello World!"

       

        // Add other property/value pairs if you like.

        // To see what's available see DOM documentation.

        // e.g. here: http://www.jongware.com/idjshelp.html

        // or: https://www.indesignjs.de/extendscriptAPI/indesign13/#about.html

    }

);

Regards,
Uwe

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 ,
Mar 12, 2018 Mar 12, 2018

Copy link to clipboard

Copied

Oh I forgot: You could also add a text frame to an insertionPoint of a text object.

That would make it an anchored text frame.

Regards,
Uwe

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 ,
Dec 12, 2018 Dec 12, 2018

Copy link to clipboard

Copied

HI, I tried to set pointSize value, but it doesn't work. I googled for awhile, can't find the answer. Looked at the DOM.

It sets the point size to 12 pt, regardless what i do.

textFrame.properties = 

    geometricBounds : [ 0,0,100,100 ], 

    strokeWidth : 0

    fillColor : "None",

    pointSize: 38 

    contents : "Hello World!" 

 

};

Rgrds

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 ,
Dec 12, 2018 Dec 12, 2018

Copy link to clipboard

Copied

textFrame.texts[0].pointSize = "15pt"

The above line should work

-Manan

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Hi briann57175377 ,

and do not forget to set a , after a property : value pair if another property : value pair is following!

Regards,
Uwe

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

1. pointSize = "15pt" is not necessary because the default is 'points' (other than all other measurement units). "pointSize = 38" ought to work -- but it does not.

2. The missing comma cannot be the problem that @briann is facing because without it, the script would show an error.

The problem is much simpler than this: "pointSize" is not a property of TextFrame: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#TextFrame.html

("contents" is, but it is a plain unformatted text string and not the 'real' contents of the text frame).

So, create an empty text frame, set its InsertionPoints[0] formatting to what you want and only then set its text content.

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Hi,

yes, since textFrame is missing property pointSize we can use the appropriate property parentStory and use pointSize on this at creation time:

var doc = app.documents[0];

var textFrame = doc.spreads[0].textFrames.add

(

    {

        geometricBounds : [ 0,0,100,100 ],

        strokeWidth : 0,

        fillColor : "None",

        contents : "Hello World!" ,

        parentStory : { pointSize : 38 }

    

    // Add other property/value pairs if you like.

    // To see what's available see DOM documentation.

    // e.g. here: http://www.jongware.com/idjshelp.html

    // or: https://www.indesignjs.de/extendscriptAPI/indesign13/#about.html

    }

);

Regards,
Uwe

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

LATEST

you are both amazing, thank you!

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 ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

This is described in the InDesign Scripting Tutorial. You may want to start by reading that.

See p. 9 and onwards under "Your first InDesign script".

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