Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script (JS) : selecting an ellipse

Community Beginner ,
Nov 14, 2024 Nov 14, 2024

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

TOPICS
Actions and scripting
460
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
People's Champ ,
Nov 14, 2024 Nov 14, 2024
select_rect=source_img.selection;
What is this code for???
You should never do this!
It can cause the program to crash.
 

 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2024 Nov 14, 2024

But it works ! And I never had any crash doing like that...

 

Maybe it could be better to return like :

return source_img.selection;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2024 Nov 14, 2024

... but it doesn't answer my question... 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 14, 2024 Nov 14, 2024

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;
}

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 15, 2024 Nov 15, 2024

Thank you very much.

 

Fred

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2024 Nov 15, 2024

An elliptical selection to the canvas edges here:

 

https://gist.github.com/MarshySwamp/451f60096079084b818d693d8cf09547

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 18, 2024 Nov 18, 2024
LATEST

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 !

timeslice2.jpgtimeslice1.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines