4 Replies Latest reply on Aug 16, 2012 10:53 AM by Peter Kahrel

    [JS][ID5] Check if cell contains inline graphic

    stoereee Level 1

      Hello,

       

      I have the following script:

       

      var myDoc = app.activeDocument;
      var myImages = myDoc.allGraphics;
      
      var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
      
      for (i=0; i<myImages.length; i++)
      {  
      for (j=0;j<myTables.length;j++) {
      
      var myActiveTable = myTables[j];
      
      if (myActiveTable.rows.everyItem().cells.everyItem().texts[0].contents == myImages[i]) 
      

       

      I want to check if a table cell contains an inline graphic, but don't know how to do it!?

       

      Regards, Sjoerd

        • 1. Re: [JS][ID5] Check if cell contains inline graphic
          [Jongware] Most Valuable Participant

          The 'contents' of a Text item contains the plain unformatted text, so it's puzzling why you thought that would somehow work ...

           

          Try http://jongware.mit.edu/idcs6js/pc_Text.html#allGraphics ("Lists all graphics contained by the Text.")

           

          As it happens, "allGraphics" is also available for Cell (so you don't have to use 'texts[0]'), Row (so you don't have to use "rows.everyItem"), and even for Table ... There is no need to drill down to individual texts in cells and gathering them together using everyItem -- simply use

           

          if (myActiveTable.allGraphics.length > 0)

           

          it contains an inline graphic.

           

          Looping over all images and over all tables does not seem necessary, as an image inside a table "is" a link straight to the object, and in reverse, every inline image knows where it is located. Then again, it depends on what information you need to be able to recommend from what angle you should approach this.

           

          I would recommend you not to use my on-line version of the DOM reference but download the searchable and indexed CHM version instead. Pick the one you need for your ID version from http://www.jongware.com/idjshelp.html. If you are using Windows, you can use it straight away; for the Mac, you need to find a suitable CHM viewer.

           

          All I had to do was look up "allGraphics" in the index to get an immediate list of objects that supported this property; then, it's just a case of point-and-click to walk up and down the object hierarchy to git to whereever you want to get.

          • 2. Re: [JS][ID5] Check if cell contains inline graphic
            stoereee Level 1

            I trying to figure it out, but I'm not good with Javascript

             

            Now I want to point to allGraphics in stories except those placed within tables!??

            • 3. Re: [JS][ID5] Check if cell contains inline graphic
              Peter Kahrel Adobe Community Professional & MVP

              Sjoerd,

               

              You said you wanted "to check if a table cell contains an inline graphic", but I think that what you mean is "I want to check if an inline graphic is in a table". That's not so hard:

               

              myImages = myDoc.allGraphics;

              for (i = 0; i < myImages.length; i++)

                 {

                 if (myImages[i].parent.parent.parent.constructor.name != "Cell")

                    {

                    // image is not in a cell

                    }

                 }

               

              Peter

              • 4. Re: [JS][ID5] Check if cell contains inline graphic
                Peter Kahrel Adobe Community Professional & MVP

                I see that Trevor had the same idea in another thread on the same topic...

                 

                P.