Skip to main content
Known Participant
March 22, 2012
Answered

[JS CS3] How to select Selection Tool

  • March 22, 2012
  • 1 reply
  • 2591 views

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

This topic has been closed for replies.
Correct answer Laubender

@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

1 reply

Community Expert
March 22, 2012

@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

Known Participant
March 22, 2012

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.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

LaubenderCommunity ExpertCorrect answer
Community Expert
March 22, 2012

@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