17 Replies Latest reply on Mar 2, 2015 10:11 AM by xtremevette2

    Textvariable page size?

    en#up_screen Level 1

      Hello,

      I was wondering if there is a way to define a variable in ID CS 6, that displays the actual pagesize?

      (I have one document with a lot of different pages and sizes.)

       

      Any help is highly appreciated. Maybe a script will work?

       

      Thx a lot

      Ronald

        • 1. Re: Textvariable page size?
          Peter Spier Most Valuable Participant (Moderator)

          Ther's no variable currently that can do that, so I've moved your question int the scripting forum to see if they have any ideas.

          • 2. Re: Textvariable page size?
            -hans- Level 4

            Hi,

             

            you could work with a eventListener which fills predefined (labeled) textFrames with the pageSize.

            For example "afterSave" or 'onIdle' ...

             

            Hans-Gerd Claßen

            • 3. Re: Textvariable page size?
              vincent 1982 Level 1
              var pages:Pages = app.activeDocument.pages;
              for (var i = 0 ; i < pages.length ; i++) {             
                   console.log("the width of page " + i + " is: " + (pages[i].bounds[3] - pages[i].bounds[1]));
                   console.log("the height of page " + i + " is: " + (pages[i].bounds[2] - pages[i].bounds[0]));     
              }
              

               

              This should give you the width and height of the pages.

              • 4. Re: Textvariable page size?
                Jump_Over Level 5

                Hi,

                 

                You could try this:

                 

                myDoc = app.activeDocument;
                myPages = myDoc.pages.everyItem().getElements();
                mhV = myDoc.viewPreferences.horizontalMeasurementUnits;
                mvV = myDoc.viewPreferences.verticalMeasurementUnits;
                myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                
                for (var k = 0; k < myPages.length; k++) {
                    resString = mySize(myPages[k]);
                    resFrame = myFrame(myPages[k]);
                    resFrame.contents = resString;
                    }
                
                myDoc.viewPreferences.horizontalMeasurementUnits = mhV;
                myDoc.viewPreferences.verticalMeasurementUnits = mvV;
                
                function mySize (page) {
                    var Pbound = page.bounds;
                    var pH = Pbound[2] - Pbound[0];
                    var pW= Pbound[3] - Pbound[1];
                    var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";
                    return res;
                    }
                
                function myFrame (page) {
                    var mF = page.textFrames.add();
                    var arrSize = [62,30];
                    mF.resize(
                        CoordinateSpaces.INNER_COORDINATES,
                        AnchorPoint.TOP_LEFT_ANCHOR,
                        ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                        arrSize
                        );
                    mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};
                    mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});
                    return mF;
                    }
                

                 

                pages height and width should be shown in top left corner text frame;

                enjoy

                1 person found this helpful
                • 5. Re: Textvariable page size?
                  en#up_screen Level 1

                  Ah, wonderful! Thank you very much. Thats it.

                   

                  kind regards

                  ronald

                  • 6. Re: Textvariable page size?
                    -hans- Level 4

                    Hi,

                     

                    with admission of Jump_over (hope so ;-) ) and jusat to play around,  a on idle event (or any other ...) could simulate the functionality of the textvariable.

                     

                    Launched from startUp Scripts-Folder  it'll now prompt for set or refresh the textframes ...

                    Delete it from StartUp-Scripts-Folder and restart ID to stopp the script working

                     

                    #targetengine "session"
                    
                    main();
                    
                    function main()
                    {
                    var checkPageSize = app.idleTasks.add({name:"checkPageSize", sleep:50000});
                    checkPageSize.addEventListener(IdleEvent.ON_IDLE, onIdleCheckPageSize, false);
                    }
                    
                    
                    function onIdleCheckPageSize(myIdleEvent){
                    
                    if(app.documents.length == 0){exit();};
                    
                    if(!confirm('Add Textframes with Pagesize?')){exit();}
                    
                    
                    myDoc = app.activeDocument;
                    myPages = myDoc.pages.everyItem().getElements();
                    mhV = myDoc.viewPreferences.horizontalMeasurementUnits;
                    mvV = myDoc.viewPreferences.verticalMeasurementUnits;
                    myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                    
                    for (var k = 0; k < myPages.length; k++) {
                        resString = mySize(myPages[k]);
                        resFrame = myFrame(myPages[k]);
                        resFrame.contents = resString;
                        }
                    
                    
                    myDoc.viewPreferences.horizontalMeasurementUnits = mhV;
                    myDoc.viewPreferences.verticalMeasurementUnits = mvV;
                    
                    }
                    
                    
                    function mySize (page) {
                        var Pbound = page.bounds;
                        var pH = Pbound[2] - Pbound[0];
                        var pW= Pbound[3] - Pbound[1];
                        var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";
                        return res;
                        }
                    
                    function myFrame (page) {
                        var myAllPageItems = page.allPageItems;
                        l = myAllPageItems.length;
                        check = true;
                        while(l--) {
                            if(myAllPageItems[l].extractLabel('tfLabel') === 'pageSize'){
                                return myAllPageItems[l]; check = false;}
                            }
                          
                          if(check){
                        var mF = page.textFrames.add();
                        var arrSize = [62,30];
                        mF.resize(
                            CoordinateSpaces.INNER_COORDINATES,
                            AnchorPoint.TOP_LEFT_ANCHOR,
                            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                            arrSize
                            );
                        mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};
                        mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});
                        mF.insertLabel('tfLabel', 'pageSize')
                        return mF;
                        }
                        }
                    

                    Hans-Gerd Claßen

                    • 7. Re: Textvariable page size?
                      Henrik Lideberg Level 1

                      Can i get this script filling out a predefined textbox, using a tag och a script tag on the textbox?

                      • 8. Re: Textvariable page size?
                        Jump_Over Level 5

                        Hi,

                         

                        Only question is which way you predefine a textFrame.

                        I.e. by applying a specific name (let say "mFrame" using Levels Panel) ==> only change is this line:

                         

                        var mF = page.textFrames.item("mFrame");
                        

                         

                        a few next lines with resize and formats look like unnecessary as well

                         

                        Jarek

                        • 9. Re: Textvariable page size?
                          Henrik Lideberg Level 1

                          myDoc = app.activeDocument;

                          myPages = myDoc.pages.everyItem().getElements();

                          mhV = myDoc.viewPreferences.horizontalMeasurementUnits;

                          mvV = myDoc.viewPreferences.verticalMeasurementUnits;

                          myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

                           

                          for (var k = 0; k < myPages.length; k++) {

                              resString = mySize(myPages[k]);

                              resFrame = myFrame(myPages[k]);

                              resFrame.contents = resString;

                              }

                           

                          myDoc.viewPreferences.horizontalMeasurementUnits = mhV;

                          myDoc.viewPreferences.verticalMeasurementUnits = mvV;

                           

                          function mySize (page) {

                              var Pbound = page.bounds;

                              var pH = Pbound[2] - Pbound[0];

                              var pW= Pbound[3] - Pbound[1];

                              var res = "H:\t" + (Math.round(pH*100)/100).toString() + " mm\nW:\t" + (Math.round(pW*100)/100).toString() + " mm";

                              return res;

                              }

                           

                          function myFrame (page) {

                              var mF = page.textFrames.item("pagesize");

                              var arrSize = [62,30];

                              /*

                                              mF.resize(

                                  CoordinateSpaces.INNER_COORDINATES,

                                  AnchorPoint.TOP_LEFT_ANCHOR,

                                  ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

                                  arrSize

                                  );

                           

                              mF.texts[0].properties = {pointSize: 10, justification: Justification.LEFT_ALIGN};

                              mF.texts[0].tabStops.add({alignment: TabStopAlignment.RIGHT_ALIGN, position: 20});

                                    */

                              return mF;

                              }

                          Okey, i've tried this but get an error from InDesign "Object not valid", Source: resFrame.contents = resString;

                          Any clues?

                          Thanks.

                          • 10. Re: Textvariable page size?
                            Laubender Adobe Community Professional & MVP

                            @Henrik – I did not test it, but you could try the following in your myFrame(page) function:

                             

                            var mF = page.textFrames.itemByName("pagesize");
                            

                             

                            Or is this text frame anchored or otherwise nested into other objects?

                             

                            Uwe

                            • 11. Re: Textvariable page size?
                              Henrik Lideberg Level 1

                              Nope, no improvments. Still "Object not valid".

                              It's not anchored or nested.

                               

                              I've uploaded my indd here:

                              http://www.rekylx.se/henrik/InDesign/Check.indd

                               

                              It's the textframe under "Print size" i'm trying to get automated with pagesize.

                              • 12. Re: Textvariable page size?
                                Jump_Over Level 5

                                Hi Henrik,

                                 

                                Are you sure each page in your doc has textFrame named "pagesize"?

                                No more check needed than look at Level's Panel to ensure that.

                                 

                                Jarek

                                 

                                PS. Your .indd would be more accessible if exported to .idml (version conflict)

                                • 13. Re: Textvariable page size?
                                  Henrik Lideberg Level 1

                                  Hi!
                                  Can't find ant panel named Level's.
                                  Figure it have be renamed in my swedish version of ID.

                                  I've one called Structure, in which i have a textFrame named pagesize under Root.

                                   

                                  Skärmavbild 2014-02-26 kl. 16.29.21.png

                                   

                                  IDML version:

                                  www.rekylx.se/henrik/InDesign/Check.idml

                                   

                                  Message was edited by: Henrik Lideberg (Added screen shot)

                                  • 14. Re: Textvariable page size?
                                    Laubender Adobe Community Professional & MVP

                                    @Henrik – it's the Layers Panel where you can name or rename objects on the page.

                                     

                                    From my German InDesign CS5.5 ;-) :

                                     

                                    1. Unnamed empty text frame (generic name of object TextFrame in localized version = "<Textrahmen>") selected and visible in Layers Panel.

                                     

                                    Value of name property is empty: ""

                                     

                                    UnnamedEmptyTextFrame-Selected.png

                                     

                                     

                                    2. Unnamed NOT EMPTY text frame (generic name changed to some of the contents)

                                     

                                    Value of name property is still empty: ""

                                     

                                    UnnamedNOTemptyTextFrame-Selected.png

                                     

                                     

                                    3. Renaming process in the Layers Panel:

                                     

                                    RenamingProcessOfTextFrame-ThisTimeNotSelected.png

                                     

                                     

                                    4. Renamed text frame.

                                    Value of name property is "pagesize".

                                     

                                    RENAMED-TextFrame-Selected.png

                                     

                                     

                                    Don't do it the UI way, just select the text frame and execute this line of code:

                                     

                                    app.selection[0].name = "pagsize";
                                    

                                     

                                    Uwe

                                    • 15. Re: Textvariable page size?
                                      Jump_Over Level 5

                                      Hi,

                                       

                                      I mean the panel with keyboard shortcut F7 (Layer Panel, I wrote wrong name, sorry).

                                      You use "pagesize" as textFrame script label. Script is expecting a textFrame name.

                                      Currently your textFrame has no name. Double click it in Layer Panel and type the name.

                                       

                                      Jarek

                                      • 16. Re: Textvariable page size?
                                        Henrik Lideberg Level 1

                                        Hi @Jump_Over and @Laubender!

                                         

                                        When labeling it through the Layers Panel, it works like a charm.

                                        Thanks a lot!

                                         

                                        BR

                                        Henrik

                                        • 17. Re: Textvariable page size?
                                          xtremevette2 Level 1

                                          So can someone help me out. What are the steps to get this page size script to work so to form as a text variable to add to to my other text variables. I ultimately want something like this to appear in my slug area of all my documents. I would love it to be able to pull information of the document size and apply it as a text variable so that I don't have to manually input the size for each job. I tried copying and pasting the information to form a new script but it wouldn't work. I don't have any real experience creating scripts in InDesign but honestly don't have the time to review the entire scripting tutuorials our their. Can anybody assist in either creating me a script or show me what I need to do to create and apply one to be a text variable. Thanks

                                           

                                          Job: Example Indesign

                                          Size: 8.5x11

                                          Created: 02/12/15

                                          Modified: March 2, 2015 8:34 AM

                                          Output: 02/12/15

                                          Page: 1