1 Reply Latest reply on Oct 21, 2014 10:10 AM by Harbs.

    Object detection. Why is InDesign not following standard javascript practices

    DustinMichaels1982

      One of the things I am tasked with now is given an element determine if it is a table cell or a text frame.

       

      How come whenever I use

       

      if (element.bottomEdgeStrokeColor) {

         //this is a table cell

      }

      else {

         //this is a textframe

      }

       

      my code blows up on the if statement. Why isn't indesign following object detection instead of throwing exceptions all over the place. Very annoying. Anyone know how to determine the type of element something is without wrapping everything in a try catch and going that route.

        • 1. Re: Object detection. Why is InDesign not following standard javascript practices
          Harbs. Level 6

          Because it's not really Javascript objects under the hood. You are dealing with specifiers to C++ objects which act very differently...

           

          You always want to test hasOwnProperty() on native InDesign objects.

           

          FWIW, you can use this approach for dealing with different object types:

           

          function isText (obj) {
            switch(obj.constructor.name){
              case "InsertionPoint":
              case "Character":
              case "Word":
              case "TextStyleRange":
              case "Line":
              case "Paragraph":
              case "TextColumn":
              case "Text":
              return true;
              default :
              return false;
              }
            }
          

           

          Harbs