How to find type of a photoshop shape layer using photoshop api

I’m exploring ways to identify the type of shape layer in Photoshop using its API. Specifically, if I draw a rectangle in Photoshop, how can I extract information that identifies it as a rectangle through the available Photoshop APIs? I’ve checked the basic layer information provided by the API, but it doesn’t seem to include specific shape identifiers like ‘rectangle’. Does anyone have experience or insights into how to retrieve shape type information such as rectangles, circles, or custom shapes using Photoshop APIs? Any guidance or examples would be greatly appreciated!

Certainly those types do not seem to be recorded. Since the coordinates of the path can be obtained, it may be possible to determine them mathematically.

For example, there is a rule that a rectangle has two diagonals of equal length. If there are at least four anchor points, and they can be considered four corners, and the lengths of the two diagonals match, then it is a rectangle.

Besides, in the case of a circle, the circularity formula may be used. In Illustrator, the area used for the calculation can be easily obtained in a script, so that’s what I did.

It may be possible to determine if the position and ratio of the anchor point and handle match the circle.

Thank you for your input! Also discovered another workaround for identifying shape types. By using the Alchemist plugin, we can access detailed layer information that includes a property known as keyOriginType. This property correlates with specific numbers for each shape drawn, allowing us to create a mapping as follows:

  • 1: Rectangle
  • 4: Line
  • 5: Ellipse
  • 7: Triangle
  • 9: Custom Shapes
    This mapping allows us to determine the type of shape of shape layer.

Any additional insights or alternative methods that could contribute to refining our approach in identifying shape types more effectively is welcomed. Please feel free to share your thoughts!

3 Likes

I learned about this for the first time just now. Thanks for letting me know.

2 Likes