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

How do we to get the corner points value from Quadrilateral?

Explorer ,
Nov 28, 2020 Nov 28, 2020

Copy link to clipboard

Copied

Hi EveryOne!,

 

Is this possible to get the corner points value from Quadrilateral?

Thanks in advance.

-yajiv

 

test.png

 

TOPICS
Actions and scripting , Windows

Views

1.1K

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Nov 28, 2020 Nov 28, 2020

Another approach would be creating a Working Path from a Selection based on the Layer’s transparency and evaluating that path. 

Votes

Translate

Translate
People's Champ , Nov 30, 2024 Nov 30, 2024
The previously proposed version can also fail if the figure is too small and shifted from the center to the right and up. The new version is free of this drawback.
 
UPD: improved and accelerated.

 

 

var doc = activeDocument;
var tmp = "tmp"+Math.random();

var ok = true;

try { doc.selection.bounds; } catch (e) { alert("No selection"); ok = false; }

if (ok)
    {
    activeDocument.suspendHistory("script", "main()");
    }

/////////////////////////////////////////////////
function main()
    {
  
...

Votes

Translate

Translate
Adobe
Community Beginner ,
Nov 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

Wow! Thank you so much! This is exactly what I need! Thank you very much!!!!

Votes

Translate

Translate

Report

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 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

No offense, but after I change other shapes, will this script report an error?

Votes

Translate

Translate

Report

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 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

I didn't quite understand what you mean.

The script works with the initial selection. You can insert the code to create a selection based on the structure of your files. You know better what's usually inside.

 

I just showed the idea of ​​how to find "protruding" corners.

From the lower left corner, a selection of 1 pixel thick is created in the form of a 45-degree line.

This selection moves from the edge of the canvas until it touches some corner in the lower left part. Ideally, the contact will be only 1 pixel in size. To find corners in other parts of the figure, you can move the selection from other corners of the canvas to the center.

Since you have high-resolution files, to speed up the process, the first movement (scanning) is done with a step of 50 pixels for a rough location of the place where the figure is present in this part.

After that, this range (50 pixels) is scanned with a step of 1 pixel to accurately find the extreme pixel of the intersection of the line and the figure.

 

Of course, there may be figures that have several "corners" in a certain frame. The result of the work may be unexpected. You need to look and adapt the script to your "typical" figures, which usually stand vertically and without tilt.

 

Good luck!

Votes

Translate

Translate

Report

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 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

Sorry, I'm not very familiar with scripting code, most of my scripting is done using ChatGPT

Votes

Translate

Translate

Report

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 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

You can look at this example file. The situation I faced was so complex and varied, and it was different every time. The only thing that was the same was that I needed to find the lower left corner of these shapes.

Votes

Translate

Translate

Report

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 29, 2024 Nov 29, 2024

Copy link to clipboard

Copied

I corrected it for a long time and found that the reason why the script failed to run on other shapes is because if the document exceeds 7300 pixels, the script will report an error, but if it is less than 7300 pixels, there will be no problem. How should I solve this problem?

Votes

Translate

Translate

Report

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 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

The large size shouldn't be a problem.
I resized your files to 8000 and there is no problem.
aaaa.jpg
 
What error message exactly are you getting?
 
 
 

Votes

Translate

Translate

Report

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 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

The problem may be if the shape is much smaller than the canvas.

If I change the canvas size to 8000 instead of the size of your file, I also got an error.

 

To avoid this, replace the line in the code

 

var from = scan(0, w/2, h, 50);

 

with

 

var from = scan(0, Math.min(w,h), h, 50);

 

Votes

Translate

Translate

Report

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 30, 2024 Nov 30, 2024

Copy link to clipboard

Copied

The previously proposed version can also fail if the figure is too small and shifted from the center to the right and up. The new version is free of this drawback.
 
UPD: improved and accelerated.

 

 

var doc = activeDocument;
var tmp = "tmp"+Math.random();

var ok = true;

try { doc.selection.bounds; } catch (e) { alert("No selection"); ok = false; }

if (ok)
    {
    activeDocument.suspendHistory("script", "main()");
    }

/////////////////////////////////////////////////
function main()
    {
    try {
        app.preferences.rulerUnits = Units.PIXELS;

        save_selection(tmp);

        scan(scan());

        del_channel(tmp);

        doc.guides.add(Direction.VERTICAL, doc.selection.bounds[0])
        doc.guides.add(Direction.HORIZONTAL, doc.selection.bounds[1])
        }
    catch(e) { alert(e.line+"\n"+e); }
    }

/////////////////////////////////////////////////
function scan(from)
    {
    try {
        app.preferences.rulerUnits = Units.PIXELS;

        load_selection(tmp);

        var x0 = doc.selection.bounds[0].value;
        var y0 = doc.selection.bounds[1].value;

        var x1 = doc.selection.bounds[2].value;
        var y1 = doc.selection.bounds[3].value;

        var w = x1-x0;
        var h = y1-y0;

        var safe = 3;

        var beg = -w/2-h/2;
        var end =  w/2+h/2;
        var step = 20;

        if (from != undefined)
            {
            beg = from;
            end = from+step;
            step = 1;
            }

        for (var off = beg; off <= end; off+=step)
            {
            load_selection(tmp);

            doc.selection.select([[(x0+x1)/2-h/2+off, (y0+y1)/2-h/2-safe], [(x0+x1)/2-h/2+1+off, (y0+y1)/2-h/2-safe], [(x0+x1)/2+h/2+1+off, (y0+y1)/2+h/2+safe], [(x0+x1)/2+h/2+off, (y0+y1)/2+h/2+safe]], SelectionType.INTERSECT, 0, false);

            try { doc.selection.bounds; } catch (e) { continue; }

            return off-step;

            break;
            }
        }
    catch(e) { alert(e.line+"\n"+e); }
    }

/////////////////////////////////////////////////
function save_selection(name)
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
        d.putReference(stringIDToTypeID("null"), r);
        d.putString(stringIDToTypeID("name"), name);

        executeAction(stringIDToTypeID("duplicate"), d, DialogModes.NO);
        }
    catch(e) { alert(e.line+"\n"+e); }
    }

/////////////////////////////////////////////////
function load_selection(name)
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
        d.putReference(stringIDToTypeID("null"), r);
        var r1 = new ActionReference();
        r1.putName(stringIDToTypeID("channel"), name);
        d.putReference(stringIDToTypeID("to"), r1);
        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
        }
    catch(e) { alert(e.line+"\n"+e); }
    }

/////////////////////////////////////////////////
function del_channel(name)
    {
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putName(stringIDToTypeID("channel"), name);
        d.putReference(stringIDToTypeID("null"), r);
        executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
        }
    catch(e) { alert(e.line+"\n"+e); }
    }

 

UPD: improved and accelerated.

 

 

Votes

Translate

Translate

Report

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 ,
Dec 02, 2024 Dec 02, 2024

Copy link to clipboard

Copied

wa! This is exactly what I need! Thank you very much, it works perfectly!

Votes

Translate

Translate

Report

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 ,
Dec 02, 2024 Dec 02, 2024

Copy link to clipboard

Copied

If there are multiple groups in the current file, I only need one group to be active and all other groups to be locked, can this be achieved through a script? Because I checked a lot of codes and tried, but all failed.

Votes

Translate

Translate

Report

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 ,
Dec 03, 2024 Dec 03, 2024

Copy link to clipboard

Copied

LATEST

I have solved my problem, thank you very very very much for your help!

Votes

Translate

Translate

Report

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