Skip to main content
Known Participant
January 2, 2020
Answered

how to make alert for circle shape

  • January 2, 2020
  • 2 replies
  • 640 views

 i know how to get  kind of solid layer  

 

if(_layers[i].kind == LayerKind.SOLIDFILL){
  alert("rectangle");
}

 

but what`s the kind of ellipse (circle shape) i need to make it in alert and thanks for you

This topic has been closed for replies.
Correct answer Chuck Uebele

This script will test to see if the first anchor point is a corner or rounded, so it will tell if the shapes are possibly a rectangle or an ellipse.

#target photoshop
var doc = activeDocument;
var layPath = doc.pathItems[0].subPathItems[0];
$.writeln(layPath.pathPoints[0].anchor+'===='+layPath.pathPoints[0].leftDirection)

if((layPath.pathPoints[0].anchor[0]===layPath.pathPoints[0].leftDirection[0])&&(layPath.pathPoints[0].anchor[1]===layPath.pathPoints[0].leftDirection[1])){
    alert('Shape could be rectangle')
    }
else{alert('Shape could be an ellipse')}

2 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
January 2, 2020

This script will test to see if the first anchor point is a corner or rounded, so it will tell if the shapes are possibly a rectangle or an ellipse.

#target photoshop
var doc = activeDocument;
var layPath = doc.pathItems[0].subPathItems[0];
$.writeln(layPath.pathPoints[0].anchor+'===='+layPath.pathPoints[0].leftDirection)

if((layPath.pathPoints[0].anchor[0]===layPath.pathPoints[0].leftDirection[0])&&(layPath.pathPoints[0].anchor[1]===layPath.pathPoints[0].leftDirection[1])){
    alert('Shape could be rectangle')
    }
else{alert('Shape could be an ellipse')}
JJMack
Community Expert
Community Expert
January 2, 2020

Also  if the layer bounds does not have a 1:1 Aspect ratio the layers is not a square or a circle.

 

 

I also do not know if all solid fill layers are Shape Layers or that all Shape layers are solid fill layers for shapes can have no fill, a gradient fill and a pattern fill as well.

 

I also do not know Action manager code and when you get layer descriptions using Action manager code the code seems to have a different  layerKind  list than DOM LayerKind.  Its list seem to be like the Layers Palette Kind Filter (Pixel, Adjustment, Text, Shape and Smart Object)  + three fill type (Colorfill, Patternfill and Gradientfill) I had map Action Manager layerKind integers different the DOM LayerKind integers.

 

 

JJMack
Stephen Marsh
Community Expert
Community Expert
January 2, 2020

Unless I am missing something, whether you are adding a solid fill layer or a shape via one of the shape tools, the layer kind is still a LayerKind.SOLIDFILL layer kind.

 

Perhaps there is a way to get live shape properties or to do complicated math based on vector path co-ordinates...