Skip to main content
Known Participant
March 29, 2019
Question

create a text frame into a used layer

  • March 29, 2019
  • 2 replies
  • 1189 views

Hi,

I'm a beginner of javascript. Can anyone know, how to do create a text frame into a used layer?

Please help me with this.

Regards,

KPS

This topic has been closed for replies.

2 replies

Community Expert
March 30, 2019

Hi KPS,

look closely into this code snippet:

var doc = app.documents[0];

var myPage = doc.pages[0];

var myLayer = doc.layers.itemByName( "Pictures" );

// One property defined with using add():

myPage.textFrames.add( myLayer );

// More properties defined with using add():

myPage.textFrames.add

(

    {

        itemLayer : myLayer ,

        geometricBounds : [ "10 mm" , "10 mm" , "50 mm" , "50 mm" ] ,

        contents : "New Text Frame 2"

    }

);

// Even properties that will not come along directly with a text frame:

myPage.textFrames.add

(

    {

        itemLayer : myLayer ,

        geometricBounds : [ "10 mm" , "60 mm" , "50 mm" , "100 mm" ] ,

        contents : "New Text Frame 3" ,

      

        parentStory : { pointSize : 20 }

    }

);

See into Gregor Fellenz' compilation:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

The DOM documentation sometimes often is very sparse with descriptions of methods, properties or possible values.

That's not Gregor's fault because the documentation above is based on Adobe files. Details here:

GitHub - grefel/extendscriptApiDocTransformations: Transformations for Adobe ExtendScript API Documentation

Regards,
Uwe

Inspiring
March 30, 2019

Hi,

    When we add the textframe, it will be added in active layer only.  If you want to change the layer of the item, you should assign the layer to the item.

var actLayer = app.activeDocument.activeLayer;               // To get the active layer of the document (ie., here default layer is Layer 3)

alert(actLayer.name)             

var tf = app.activeDocument.textFrames.add()                    // Add textframe.

tf.contents = "TEST"

tf.fit(FitOptions.FRAME_TO_CONTENT);

var lyr1 = app.activeDocument.layers.item("Layer 1");               // To change of the item layer (ie., Changed the layer of the tf from Layer 3 to Layer 1)

tf.itemLayer =  lyr1;

Hope this will be helpful.

Peter Kahrel
Community Expert
Community Expert
March 30, 2019

> it will be added in active layer only

No: you can add a frame straight on to a layer. With a reference myPage to a given page, to place a text frame on a layer 'Pictures', do this:

myPage.textFrames.add (app.documents[0].layers.item('Pictures'));

P.

Known Participant
March 31, 2019

Hi,

Thanks for providing the details more clearly.

Could you please anyone know, is there a possibility to send an email from Indesign to Outlook.

I've tried the below script details. But, it doesn't work properly.

var w = new Window ("dialog", "Checklist");

w.orientation = "column";

w.alignChildren = "left";

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

w.add ("checkbox", undefined, "\u00A0Prefer mixed fksldkflsdkfld miexed");

var b1 = w.add ("button", undefined, "OK", {name: "ok"});

var b2 = w.add ("button", undefined, "Cancel", {name: "cancel"});

b1.onClick = function sendEmail ( _name, _email, _subject, _message)

{

    mandrill('/messages/send',

    {

        message:

        {

            to: [{email: _email , name: _name}],

            from_email: 'noreply@yourdomain.com',

            subject: _subject,

            text: _message

        }

    },

        function(error, response)

        {

        if (error) console.log(error);

        else console.log(response);

    });

}

// define your own email api which points to your server.

//app.outlook( '/https://outlook.office.com/api/sendemail/', function(req, res){

    //var _name = req.body.name;

    //var _email = req.body.email;

    //var _subject = req.body.subject;

    //var _messsage = req.body.message;

    //implement your spam protection or checks.

    //sendEmail ( _name, _email, _subject, _message );

//});

w.show ();

Regards,

KPS.