5 Replies Latest reply on Apr 27, 2009 10:17 AM by AaronKuehn

    VBSCRIPT ID2.0 - How to convert user's selection to a 'direct selection'

    AaronKuehn Level 1

      I've got a VBScript that uses the "resize" command to resize the selected image.  As long as the user has used the Direct Select tool to select the graphic, it works fine.  But if they use the Selection Tool I want to essentially change the selection to a "direct" selection.

       

      Can someone help me with how to do this?

       

      Thanks!

        • 1. Re: VBSCRIPT ID2.0 - How to convert user's selection to a 'direct selection'
          Dave Saunders Level 4

          You need to address the first graphic of the selection. I don't know the syntax for that in VB.

           

          Dave

          • 2. Re: VBSCRIPT ID2.0 - How to convert user's selection to a 'direct selection'
            AdobeScripts Level 3

            this will work for ID 2.0.x:

             

            Set myImage = myInDesign.Selection.Item(1).Images

             

            this for ID CSx:

             

            Set myImage = myInDesign.Selection.Item(1).AllGraphics.Item(1)

             

            robin

             

            www.adobescripts.co.uk

            • 3. Re: VBSCRIPT ID2.0 - How to convert user's selection to a 'direct selection'
              AaronKuehn Level 1

              Still having trouble.  I get an error 438 when trying to resize that image.  It allows me to do the "set" without error, but after that I can't seem to do anything with it.  I've tried to MsgBox the ID of the image, MsgBox the rotationangle -- but nothing seems to work.

               

              Any other thought?

               

              Thanks!

              <<Actual Code Below>>


              ''    Start Error Handling
                  On Error Resume Next

               

              ''    CHANGE THIS VARIABLE TO THE DESIRED HORIZONTAL SCALING PERCENTAGE
              scaleFactor = 200

               

              Set myInDesign = CreateObject("InDesign.Application.2.0")
              set myDocument = myInDesign.Documents

               

              if myInDesign.documents.count < 1 then
                  MsgBox "You must have a document open in order to change the Baseline Grid."
              else
                  Set mySelection = myInDesign.Selection

               


                  If mySelection.Count = 0 Then
                  ''Nothing is selected -- tell user to select something.
                      MsgBox "You must have a graphic frame selected."

               

                      Else

               

                          If TypeName(mySelection.Item(1)) = "Image" Then        ''IF USER HAS DIRECT-SELECTED THE GRAPHIC, ANAMORPHICALLY SCALE IT.
                      mySelection.Item(1).resize scaleFactor,100,1095656308,false,false

               

                      ElseIf TypeName(mySelection.Item(1)) = "Rectangle" Then        ''IF USER HAS ONLY SELECTED THE FRAME, SELECT THE GRAPHIC AND ANAMORPHICALLY SCALE IT.
                      set myImage = myInDesign.Selection.Item(1).Images
                      myImage.resize scaleFactor,100,1095656308,false,false
                     
                      Else
                          ''The selection is not a graphic or a frame frame -- tell user to select one
                          MsgBox "You must have a graphic frame selected." & vbCrLf & TypeName(mySelection)
                      End If
              end if
              end if

               

              ''ERROR HANDLER
              if err.number > 0 Then
              MsgBox "An error occurred while trying to scale the graphic." & vbCrLf & vbCrLf & "Error information: " & err.number & "_" & err.description
              End If

              • 4. Re: VBSCRIPT ID2.0 - How to convert user's selection to a 'direct selection'
                AdobeScripts Level 3

                sorry, it is my fault, I didn't tested it - I've misinterpreted ObjectBrowser's description

                 

                you need to change line:

                 

                Set myImage = myInDesign.Selection.Item(1).Images

                 

                to:

                 

                Set myImage = myInDesign.Selection.Item(1).Images.Item(1)

                 

                so - all versions of InDesign return collection of Images

                 

                robin

                 

                www.adobescripts.co.uk