2 Replies Latest reply on Jul 19, 2011 2:05 PM by JoseAjáAjá

    InDesign: activeDocument.Pages.itemByRange(ini,end) --> What type? Methods?

    JoseAjáAjá Level 1

      [Writing extensions in Flash Builder 4 with Creative Suite SDK, without extension Builder]

       

       

      Hi,

       

      I'd love to have access to elements in a page range, say, for example, the TextFrames in pages from 5 to 10 in a 20 pages document.

       

      The element returned by "itemByRange()" method of the Pages element within the active document, is of type "Object" (according to the documentation), or, more exactly, a "CSHostObject".

       

      How do I use this element??

       

      Are they pages? If so, why can't I access all of their properties or methods?

       

      I've been trying to do it for four days, now, to no avail.

       

      If I write:

       

       

      var pagesRange     : Object     = InDesign.app.activeDocument.Pages.itemByRange(ini, end)
      

       

      I get a CSHostObject that I cannot use for anything.

       

      Any ideas?

       

      Thanks guys.

       

      PS. Sorry if this seems basic, but iI'm just learning to use the inDesign DOM and find it a little dificult to use from ActionScript.

        • 1. Re: InDesign: activeDocument.Pages.itemByRange(ini,end) --> What type? Methods?
          Ten A Adobe Community Professional

          Hi,
          I tested below function to check return what kind of Object.

           

          <?xml version="1.0" encoding="utf-8"?>

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">

           

              <mx:Script>
                  <![CDATA[
                      import com.adobe.csawlib.indesign.InDesign;
                      import com.adobe.indesign.*;
                     
                  public static function run():void
                  {
                      var app:Application = InDesign.app;
                      var document:com.adobe.indesign.Document = app.activeDocument
                      var pg:Object = document.pages.itemByRange(1,2);
                      document.pages.item(0).textFrames.item(0).contents = pg+"";
                  }
                  ]]>
              </mx:Script>
              <mx:Button label="Run ID code" click="run()" />
          </mx:Application>

           

           

          and I got [object Page], itemByRange method returns Page Object.

          next, I wrote below mxml file,

           

           

          <?xml version="1.0" encoding="utf-8"?>

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">

           

              <mx:Script>
                  <![CDATA[
                      import com.adobe.csawlib.indesign.InDesign;
                      import com.adobe.indesign.*;
                     
                      public static function run():void
                      {
                          var app:com.adobe.indesign.Application = InDesign.app;
                          var document:Document = app.activeDocument;
                          var pg:Object = document.pages.itemByRange(0,2);
                          var str:String = pg.documentOffset +"";
                          document.pages.item(0).textFrames.item(0).contents = str ;
                      }
                  ]]>
              </mx:Script>
              <mx:Button label="Run ID code" click="run()" />
          </mx:Application>

           

          "documentOffset" is Page Objects property, and I got an Array like below image.

           

          getArray.png

           

          I just learning CSSDK too. And I think Its poor informations hindrance to understanding.

           

          Ten

          1 person found this helpful
          • 2. Re: InDesign: activeDocument.Pages.itemByRange(ini,end) --> What type? Methods?
            JoseAjáAjá Level 1

            Hey, Ten A.

             

            Thx for taking the time to answer.

             

            Actually, I had made a little mistake, and was entering wrong numbers as the arguments for "itemByRange()", so the returned object seemed to be empty, and thus, nothing worked.

             

            Nonetheless, as soon as I discovered that mistake, I spent some hours to make it work.

             

            What I was trying to accomplish, was to find text in just a page range of my document.

             

             

            So, if anyone is interested, the snippet of code that I used for obtaining a clean array containing the findings of a "find" statement only in a range of pages, is this (sorry, it's a little cluttered, but I'm still learning on it. It's meant only for learning purposes):

             

             

            case pagesRangeRB:
            var fromPageNum     :int     = (new Number(ini_TI.text) - 1) as int;
            var toPageNum     :int     = (new Number(fin_TI.text) - 1) as int;
            var pagesRange     :Object     = 
            inDesignDocument.pages.itemByRange(fromPageNum,toPageNum);
            
            
            var framesRange1     :TextFrames          = pagesRange.textFrames;
                                               
            foundText = new Array();
                                               
                                               
            //There's no need for traversing the array of TextFrames. Actually, the search is performed 
            //     in the whole array of frames, when you search in the first one, and an error is dispatched
            //     when one searches within other TextFrames.
            var iTextFrames               :int      = 0 ;
            var foundTextByFrame     :Array     = 
                 (framesRange1.item(iTextFrames) as TextFrame).findText() as Array;
                                               
            for (var iFindText:int = 0 ; iFindText < foundTextByFrame.length ; iFindText++)
            {
                 if (foundTextByFrame[iFindText] is Array)
                 {
                      var currentFoundTextByFrameArray     :Array = foundTextByFrame[iFindText] as Array; 
                                          
                 if ( currentFoundTextByFrameArray.length > 0 )
                 {
                      for (var iFoundTextByFrame:int = 0 ; iFoundTextByFrame < currentFoundTextByFrameArray.length ; iFoundTextByFrame++)
                      {
                           var textItemToPush     :com.adobe.indesign.Text     = currentFoundTextByFrameArray[iFoundTextByFrame] as com.adobe.indesign.Text;
                              foundText.push( currentFoundTextByFrameArray[iFoundTextByFrame] );
                      }
                    }
                 }
                 else
                 {
                      if ( foundTextByFrame[iFindText] != null )
                   {
                      foundText.push( foundTextByFrame[iFindText] );
                   }
                 }                                   
            }     
            break;
            

             

             

             

            _______

             

             

            The main two problems, I think, with CS_SDK is that:

             

            1- Documentation is poor

            2- Many method results are not strong typed, and thus, they are masked when called from Flash/Flex Builder, because the only thing you see is a CSHostObject, which you don't know whether represents a Text, and Array, or anything else, and which doesn't present you neither with properties nor methods whatsoever.

             

            To overcome this, I'm starting to use a "trace()" statement after I declare any variable by using one of this methods that return ":Object" (or CSHostObject, which is how I see them in Flash builder)