7 Replies Latest reply on Mar 26, 2012 4:28 AM by Laubender

    [JS CS3] How to select Selection Tool

    Tom Tomasko Level 1

      Hello,

       

      At the end of a script I wish to return to the Selection Tool (black arrow). Now the Text tool is active because the last thing the script did was to create a text frame. I do not see any property I can use to invoke the selection tool.

       

      Thanks,

       

      Tom

        • 1. Re: [JS CS3] How to select Selection Tool
          Laubender Adobe Community Professional & MVP

          @Tom – Huh?
          Select the Selection Tool and run the following code snippet:

           

           

          app.documents[0].pages[0].textFrames.add({
              geometricBounds:[0,0,30,50]
              });
          

           

          Does the Selection Tool change to Text Tool? I bet no.

           

          Let's show us some of your code to sort this out…

           

          Uwe

          • 2. Re: [JS CS3] How to select Selection Tool
            Tom Tomasko Level 1

            The following script gives the distance between two parallel guides and places that distance on the clipboard. For whatever reason I always end up with the Text Tool as the active tool.

             

             

            var arrGuides = app.selection;
            var docUnits = findDocUnits();
            selectOnlyGuides();
            switch(arrGuides.length){
                    case 0:
                    alert("Please select two parallel guides. \r\rYou did not select any.");
                    break;
                    case 1:
                    alert("Please select two parallel guides. \r\rYou selected only one.");
                    case 2:
                    twoGuidesSelected();
                    break;
                    default:
                    alert("Please select only two parallel guides. \r\rYou selected three or more.");
                    break;
                    }//end switch
            arrGuides[0].select();    
            arrGuides[1].select(SelectionOptions.ADD_TO);
            
            //******FUNCTIONS************        
            function findDocUnits(){
                if(app.activeDocument.viewPreferences.horizontalMeasurementUnits !=app.activeDocument.viewPreferences.verticalMeasurementUnits){
                    alert("The vertical and horizontal units must both be either inches or picas. Please check the Preferences and set them the same.");
                    exit();
                    }//end  if
                else{
                var currentUnits = "";
                switch(app.activeDocument.viewPreferences.horizontalMeasurementUnits){
                    case MeasurementUnits.INCHES:
                    case MeasurementUnits.INCHES_DECIMAL:
                    currentUnits = "inches";
                    break;
                    case MeasurementUnits.PICAS:
                    currentUnits = "picas";
                    break;
                    default:
                    alert("Your document should be set in only inches or picas. Please check the Preferences.");
                    break;
                    }//end switch
                }//end else
            return currentUnits;
            }//end function findDocUnits
            
            function selectOnlyGuides(){
            try{
                for(var i = 0; i< arrGuides.length; i++){
                    if(arrGuides[i].constructor.name != "Guide"){
                        var alert1="Please select two parallel guides and no other elements.";
                        alert(alert1);
                        exit();
                    }//end try
                        }//end if constructor.name
                }//end for 
            catch(e){
                alert(alert1);
                }//end catch
            }//end function selectOnlyGuides
            
            function twoGuidesSelected(){
                //testing to see if perpendicular guides have been selected by user.
                try{
                 if(arrGuides.length==2&&(arrGuides[0].orientation==HorizontalOrVertical.vertical&&arrGuides[1].orientation==HorizontalOrVertical.horizontal)||(arrGuides[1].orientation==HorizontalOrVertical.vertical&&arrGuides[0].orientation==HorizontalOrVertical.horizontal)){
                    alert("Please select two parallel guides. \r\rYou selected two perpendicular ones.");
                    }//end  if; test for perpendicular guides
                //testing if only horizontal or vertical guides have been selected. If yes, tell difference.
                 if(arrGuides.length==2&&(arrGuides[0].orientation==HorizontalOrVertical.vertical&&arrGuides[1].orientation==HorizontalOrVertical.vertical)||(arrGuides[0].orientation==HorizontalOrVertical.horizontal&&arrGuides[1].orientation==HorizontalOrVertical.horizontal)){
                    var deltaDistance = Math.abs((arrGuides[0].location)-(arrGuides[1].location)).toFixed(4);
                    alert("The distance between the two guides is: "+deltaDistance+" "+docUnits+".\r\rThis figure is now on your clipboard if you want to paste it.");
                    var numToCopy = deltaDistance;
                    copyNum(numToCopy);
                }//end if; test for parallel guides.
            }//end try
            catch (e){//do nothing
                }//end catch
            return arrGuides;
            }//end function twoGuidesSelected
            
            function copyNum(numToCopy){
            var framePropRecord = {contents:numToCopy.toString()}
            var myTextFrame = app.activeDocument.textFrames.add(framePropRecord);
            myTextFrame.parentStory.texts[0].select();
            app.copy();
            myTextFrame.select();
            myTextFrame.remove();
                }//end function numToCopy
            
            • 3. Re: [JS CS3] How to select Selection Tool
              Laubender Adobe Community Professional & MVP

              @Tom – The reason is clear, so at least seems to me:

              your function copyNum() selects some text, that obviously triggers the text tool.

               

              You could invoke the selection tool  at the end of your code:

               

              app.menuActions.itemByID(118822).invoke();
              

               

              btw. to get rid of your text frame you need not to select it.
              Just use your variable:

               

              //myTextFrame.select();
              myTextFrame.remove();
              

               

              Uwe

              • 4. Re: [JS CS3] How to select Selection Tool
                Tom Tomasko Level 1

                Uwe,

                Thanks! All is well now (until the next script that frustrates me!).

                Tom

                • 5. Re: [JS CS3] How to select Selection Tool
                  Marijan Tompa [tomaxxi] Level 4

                  Uwe,

                   

                  this is pretty ugly... :-D

                   

                  Check this out:

                  http://tomaxxi.com/2010/08/change-active-tool-with-script/

                   

                  HTH

                   

                  --

                  Marijan (tomaxxi)

                  http://tomaxxi.com

                  • 6. Re: [JS CS3] How to select Selection Tool
                    greenrookie Level 2

                    A bit off topic but,

                     

                    This is one fo the most frustrating things in Illustrator. In Indesign, I can assign the function keys for the select/direct select tools to get out of the text tool. Works great on a multi- buttoned mouse.

                     

                    But you can't use function or other specilaised keys for keyboard shortcuts in AI!

                    • 7. Re: [JS CS3] How to select Selection Tool
                      Laubender Adobe Community Professional & MVP

                      this is pretty ugly... :-D

                      @Marijan – I know . Thank you for the link. I'll test your approach…

                      Though, it's only available in InDesign CS5 and above.

                       

                      The OP is running CS3

                       

                      Uwe