Skip navigation
Currently Being Moderated

copy/paste testframe from a master page ?

Mar 23, 2012 3:05 AM

Tags: #cs5 #javascript #paste #master #copy #textframe

Hi,

 

A layout has been made by a designer. He uses a lot of properties (rotation, odd corner, gradient ...) for each of his elements (textFrame).

From this layout, I have to create an automatic layout from his work (I'm using InDesign CS5). That mean I should recreate the properties in Javascript for several elements.

 

I was wondering if it would be better to use a Master page with all of those elements in it and then using of the "copy/paste" to call my elements.

According to you, is it a good way to proceed ?

 

 

By the way, I have some problems to select a textframe in my master page...

Here is what I use to access to my textFrame element :

 

myDocument.masterSpreads.item("A-MyName").pages.item(0).textFrames.item("MyBlocName")

 

What's wrong ?

 

 

 

 

Thank you very much.

 
Replies
  • Currently Being Moderated
    Mar 23, 2012 4:02 AM   in reply to Boitaumail

    How did you get the name of the text frame? I mean how do you know that your text frame you want to duplicate has the name "MyBlocName"?

     

    What would you do if several text frames have an identical name?


    You could loop through all page items on your master page, single out the text frames and looking for a name:

     

    //In case you gave a name by using the layers palette in the UI (CS5 and CS5.5):
    for(var n=0;n<myMasterPage.allPageItems.length;n++){
        if(myMasterPage.allPageItems[n].constructor.name == "TextFrame" && myMasterPage.allPageItems[n].name == "MyBlocName"){
            //Do something
            };
    };
    

     

    //In case you gave a name by using the labels palette in the UI (CS4, CS5 and CS5.5):
    for(var n=0;n<myMasterPage.allPageItems.length;n++){
        if(myMasterPage.allPageItems[n].constructor.name == "TextFrame" && myMasterPage.allPageItems[n].label == "MyBlocName"){
            //Do something
            };
    };
    

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 5:39 AM   in reply to Boitaumail

    (Only as an aside:

     

    This

     

    if(myMasterPage.allPageItems[n].constructor.name == ..

     

    does not work. If you access your page items by asking for "pageItem", you will get the name "pageItem" -- not "TextFrame".)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 6:09 AM   in reply to [Jongware]

    @Jongware –

    hm, strange, just tested and it does work. (InDesign CS5.5 v7.5.2 on Mac OSX 10.6.8)

     

    Alternatively one could use "instanceof TextFrame" instead of "constructor.name == "TextFrame"".

     


    @Boitaumail – could you provide a reduced sample of your InDesign file (IDML) we can download somewhere?
    I just tested my code with the script label and all went right…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2012 1:27 AM   in reply to Boitaumail

    @Boitaumail – downloaded your file and tested (InDesign CS5, CS5.5). No problem on my side with the following code:

     

    var myPage = app.documents[0].masterSpreads.itemByName("B-right").pages[0];
    var allPageItemsMyPage = myPage.allPageItems;
     
    for(var n=0;n<allPageItemsMyPage.length;n++){
     
        if(allPageItemsMyPage[n].constructor.name == "TextFrame" && allPageItemsMyPage[n].label == "COLLECTION"){
            $.writeln("HIT TARGET");
            /*
                Do something useful here
            */
            //After that we could break the for-loop; 
            //there should be only ONE instance of text frames with label "COLLECTION" on the page. That will speed up operation a bit.
            break;
            };
     
        };
    

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2012 6:23 AM   in reply to Boitaumail

    @Boitaumail – My code will work for InDesign CS4, CS5 and CS5.5. I cannot test for  Windows OS, but it should work there as well.

     

    The difference to my approach is: if you change the object's name in the layers palette, you define the "name" property of your text frame (CS5) which initially is "undefined". What you see in the layers palette of the UI after adding a new text frame is something more generic and you should not mix that up with "name" or "label". The "label" property is a totally different beast.

     

    Apart from defining "label" and "name" properties you could use the insertLabel() and extractLabel() methods to "pin point" a text frame. Downside (more often a bonus if you mind user interaction): you cannot see the contents of an inserted label in the UI and only define it and read it out by scripting.


    There is a (long) thread about the differences between CS4 and CS5. See:

     

    With CS5, some things have changed

     

    http://forums.adobe.com/message/2728529#2728529

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points