Highlighted

Any easy way to detect if a PathItem is a given shape?

Engaged ,
Jun 18, 2020

Copy link to clipboard

Copied

I'd like to iterate through PathItems and detect if one is a parametric shape like a rectangle, ellipse, polygon, etc., specifically having been made from the corresponding tool (rectangle tool, and so on). I figure this can be done by iterating through PathPoints of enclosed PathItems:

 

  • Rectangle has 4 vertices, and two pairs of equal paths
  • You could tell if something is an ellipse by looking at the distance of the Bezier handles or anchors. If these are all equal length, it's a perfect circle. It it has an equal amount of two matching pairs, it's oblong.
  • Polygons should have equal distance between all pathPoints, and would have 3 or more sides

 

So I figure I could do all this logic, but first was curious if there's a much easier way to detect since I'm essentially just looking to return a value of "Rectangle", "Ellipse", "Polygon". Is there any easier way to do this?

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

not easily as with most everything but there's hope

 

if you save your document with "Use Compression" unchecked, and open the ai document with a Text Editor, you'll find a lot of useful information about the file.

 

search for "BeginLayer" to get to the good stuff. It turns out Illustrator adds tags to Shapes

 

this snippet shows a 6 side Polygone named "myHexagone". Expanded Shapes just list a bunch of Anchor coordinates, no shape tags

 

shapeObjectsUncompressedFile.PNG

Topics

Scripting

Views

80

Likes

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

Any easy way to detect if a PathItem is a given shape?

Engaged ,
Jun 18, 2020

Copy link to clipboard

Copied

I'd like to iterate through PathItems and detect if one is a parametric shape like a rectangle, ellipse, polygon, etc., specifically having been made from the corresponding tool (rectangle tool, and so on). I figure this can be done by iterating through PathPoints of enclosed PathItems:

 

  • Rectangle has 4 vertices, and two pairs of equal paths
  • You could tell if something is an ellipse by looking at the distance of the Bezier handles or anchors. If these are all equal length, it's a perfect circle. It it has an equal amount of two matching pairs, it's oblong.
  • Polygons should have equal distance between all pathPoints, and would have 3 or more sides

 

So I figure I could do all this logic, but first was curious if there's a much easier way to detect since I'm essentially just looking to return a value of "Rectangle", "Ellipse", "Polygon". Is there any easier way to do this?

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

not easily as with most everything but there's hope

 

if you save your document with "Use Compression" unchecked, and open the ai document with a Text Editor, you'll find a lot of useful information about the file.

 

search for "BeginLayer" to get to the good stuff. It turns out Illustrator adds tags to Shapes

 

this snippet shows a 6 side Polygone named "myHexagone". Expanded Shapes just list a bunch of Anchor coordinates, no shape tags

 

shapeObjectsUncompressedFile.PNG

Topics

Scripting

Views

81

Likes

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
Adobe Community Professional ,
Jun 19, 2020

Copy link to clipboard

Copied

not easily as with most everything but there's hope

 

if you save your document with "Use Compression" unchecked, and open the ai document with a Text Editor, you'll find a lot of useful information about the file.

 

search for "BeginLayer" to get to the good stuff. It turns out Illustrator adds tags to Shapes

 

this snippet shows a 6 side Polygone named "myHexagone". Expanded Shapes just list a bunch of Anchor coordinates, no shape tags

 

shapeObjectsUncompressedFile.PNG

Likes

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
Reply
Loading...