6 Replies Latest reply on Apr 19, 2009 1:03 PM by Dave Saunders

    Get TextFrame Shape VB Script CS3

    Archie-Tucker

      When I use the TypeName command on a TextFrame it returns the value textframe, how do you get the shape value (rectangle, oval) of a textframe?

      Thanks,

      Archie

        • 1. Re: Get TextFrame Shape VB Script CS3
          Peter Kahrel Adobe Community Professional & MVP

          If the return value is 'textframe', then you're dealing with a text frame. Rectangles are (usually) containers for e.g. images. So select an image frame and try typename again -- that should return Rectangle. Or draw an oval and try typename.

           

          Peter

          • 2. Re: Get TextFrame Shape VB Script CS3
            Dave Saunders Level 4

            It's one of the weaknesses of InDesign's object model that you can't tell the shape of a text frame (other than by detailed examination of its geometry).

             

             

            Here's a trick that might help:

             

            1. Get a reference to entirePath of the path of the text frame.

             

            2. Make a new rectangle.

             

            3. Set the entirePath of the path of the new rectangle to the entirePath from 1.

             

            4. See what InDesign now thinks it is.

             

            I'll code that in JS and see if it works.

             

            Dave

            • 3. Re: Get TextFrame Shape VB Script CS3
              Dave Saunders Level 4

              Yes! This works. I made an oval and typed some text into it and ran this script which correctly reported that the text frame is an oval.


                  if (app.documents.length > 0 &&
                              app.selection.length > 0 &&
                                  app.selection[0] instanceof TextFrame) {
                      determineShape(app.selection[0]);
                  } else {
                      alert("Please select a text frame")
                  }
                  function determineShape(tf) {
                      var entirePath = tf.paths[0].entirePath;
                      var myRect = tf.parent.rectangles.add();
                      myRect.paths[0].entirePath = entirePath;
                      alert(myRect.getElements()[0].constructor.name);
                      myRect.remove();
                  }

               

              But I don't know how much of that translates into VB with its stricter typing.

               

              Dave

              • 4. Re: Get TextFrame Shape VB Script CS3
                Peter Kahrel Adobe Community Professional & MVP

                Ah -- of course... I forgot that when you enter some text into an oval or any shape, that shape becomes a TextFrame.

                 

                Peter

                • 5. Re: Get TextFrame Shape VB Script CS3
                  Steven.. Level 3

                  Dave here's the Code in VB

                   

                  Set myInDesign = CreateObject("InDesign.Application.CS3")
                  If myInDesign.Documents.Count > 0 Then
                  If myInDesign.Selection.Count > 0 Then
                        If TypeName(myIndesign.selection(1))="TextFrame" then
                             determineShape(myIndesign.selection(1))
                        Else
                             MsgBox ("Please select a text frame")
                        End If
                  Else
                        MsgBox ("Nothing is selected. Please select an object and try again.")
                  End If
                  Else
                  MsgBox ("Please open a document, select an object, and try again.")
                  End If
                  Sub determineShape(tf)
                  entirePath = tf.Paths(1).entirePath
                  Set myRect = tf.parent.rectangles.add
                  myRect.paths(1).entirePath = entirePath
                  Msgbox(TypeName(myRect))
                  myRect.Delete
                  End Sub

                  • 6. Re: Get TextFrame Shape VB Script CS3
                    Dave Saunders Level 4

                    Thanks Steven.

                     

                    Interesting that TypeName gets to the heart of the element. The apparent equivalent in JavaScript:

                     

                    myRect.constructor.name

                     

                    returns Rectangle even though the object is now an Oval. It's the .getElements()[0] that gets to what the object actually is.

                     

                    Dave