Copy link to clipboard
Copied
Hi all
I am trying to select an ellipse and make that selection workable. It is straight forward for a rectangle :
function select_rect(source_img, left, top, right, bottom) {
source_img.selection.select([
[left, top],
[right, top],
[right, bottom],
[left, bottom]
]);
select_rect=source_img.selection;
}
For an ellipse selection, I found this code :
function select_Ellipse(left,top,right,bottom,antiAlias){
var circleSelection = charIDToTypeID( "setd" );
var descriptor = new ActionDescriptor();
var id71 = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var id72 = charIDToTypeID( "Chnl" );
var id73 = charIDToTypeID( "fsel" );
ref5.putProperty( id72, id73 );
descriptor.putReference( id71, ref5 );
var id74 = charIDToTypeID( "T " );
var desc12 = new ActionDescriptor();
var top1 = charIDToTypeID( "Top " );
var top2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( top1, top2, top );
var left1 = charIDToTypeID( "Left" );
var left2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( left1, left2, left );
var bottom1 = charIDToTypeID( "Btom" );
var bottom2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( bottom1, bottom2, bottom );
var right1 = charIDToTypeID( "Rght" );
var right2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( right1, right2, right );
var id83 = charIDToTypeID( "Elps" );
descriptor.putObject( id74, id83, desc12 );
var id84 = charIDToTypeID( "AntA" );
descriptor.putBoolean( id84, antiAlias );
executeAction(circleSelection, descriptor, DialogModes.NO );
}But the selection is not returned in the function like it is with my select_rect function.
I would like the select_ellipse to be in the form of :
function select_ellipse(sourceImg, left,top,right,bottom,antiAlias) {
[... code ...]
select_ellipse = ???
}
Is it possible ? How to do this ?
Clear sky
Fred
Copy link to clipboard
Copied
select_rect=source_img.selection;
Copy link to clipboard
Copied
But it works ! And I never had any crash doing like that...
Maybe it could be better to return like :
return source_img.selection;
Copy link to clipboard
Copied
... but it doesn't answer my question...
Copy link to clipboard
Copied
You have strange questions.
Why do you need to return something from the function?
Access to the selection is possible through the activeDocument.selection property anywhere in the code.
You can return it from the function using the return operator.
return activeDocument.selection;
To make sure that your code causes a crash, add one more line (with alert) to your function
select_rect(activeDocument, 1, 1, 100, 100);
function select_rect(source_img, left, top, right, bottom) {
source_img.selection.select([
[left, top],
[right, top],
[right, bottom],
[left, bottom]
]);
select_rect=source_img.selection;
alert(select_rect);
}
-----------------------------------------------------------------------------------------------------
And the answer to your strange question
var sel = select_Ellipse(activeDocument, 1,1,150,40,true);
alert(sel);
function select_Ellipse(sourceImg, left,top,right,bottom,antiAlias){
var circleSelection = charIDToTypeID( "setd" );
var descriptor = new ActionDescriptor();
var id71 = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var id72 = charIDToTypeID( "Chnl" );
var id73 = charIDToTypeID( "fsel" );
ref5.putProperty( id72, id73 );
descriptor.putReference( id71, ref5 );
var id74 = charIDToTypeID( "T " );
var desc12 = new ActionDescriptor();
var top1 = charIDToTypeID( "Top " );
var top2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( top1, top2, top );
var left1 = charIDToTypeID( "Left" );
var left2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( left1, left2, left );
var bottom1 = charIDToTypeID( "Btom" );
var bottom2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( bottom1, bottom2, bottom );
var right1 = charIDToTypeID( "Rght" );
var right2 = charIDToTypeID( "#Pxl" );
desc12.putUnitDouble( right1, right2, right );
var id83 = charIDToTypeID( "Elps" );
descriptor.putObject( id74, id83, desc12 );
var id84 = charIDToTypeID( "AntA" );
descriptor.putBoolean( id84, antiAlias );
executeAction(circleSelection, descriptor, DialogModes.NO );
return sourceImg.selection;
}
Copy link to clipboard
Copied
Thank you very much.
Fred
Copy link to clipboard
Copied
An elliptical selection to the canvas edges here:
https://gist.github.com/MarshySwamp/451f60096079084b818d693d8cf09547
Copy link to clipboard
Copied
Thank you Stephen, your code is more optimized than the one I used.
My script can now play with the selection I made to make rectangles, ellipses, slanted quadrigones... Good for timeslices !
Find more inspiration, events, and resources on the new Adobe Community
Explore Now