Skip to main content
Ka-Tja
Community Expert
Community Expert
February 1, 2020
Question

Get colors from a pattern

  • February 1, 2020
  • 2 replies
  • 815 views

Hi

Is there a way to get colors or path items from a pattern in Adobe Illustrator using javascript? There is nothing I can find in references, that is working.

This topic has been closed for replies.

2 replies

Ten A
Community Expert
Community Expert
February 3, 2020

Unfortunately, We can not access patterns information via script. However, we can read some info from Illustrator's document files directly.
Here is a sample data of patterns.

 

%AI3_BeginPattern: (testPattern)
(testPattern) 0 0 96.0603962102068 96.0603962102068
%_0 A
%_0 Xw
%_0 Ae
%_u
%_4 As
%_0 1 0 0 0 Xy
%_0 J 0 j 1 w 10 M []0 d
%_0 XR
%_0 96.0603962102068 m //move to current point that pattern rectangle
%_96.0603962102068 96.0603962102068 L //line to next point
%_96.0603962102068 0 L //line to next...
%_0 0 L //line to next...
%_0 96.0603962102068 L //line to next...
%_n
%_/ArtDictionary :
%_1 /Bool (AIPattern_Editor_Backing_Tile_Rect) ,
%_;
%_
%_1 Ap
%_4 As
%_0 O
%_0 0 0 1 k //c0,m0,y0,k100 fill-process ink
%_65.8276568462916 48.0301981051034 m //move to ellepse start point
%_65.8276568462916 38.2009330571509 57.8594631530559 30.2327393639152 48.0301981051034 30.2327393639152 c //rightDirection, next leftDirection and next anchor to make curve.
%_38.2009330571509 30.2327393639152 30.2327393639152 38.2009330571509 30.2327393639152 48.0301981051034 c //curve to next
%_30.2327393639152 57.8594631530559 38.2009330571509 65.8276568462916 48.0301981051034 65.8276568462916 c //curve to next
%_57.8594631530559 65.8276568462916 65.8276568462916 57.8594631530559 65.8276568462916 48.0301981051034 c
...

 

Ka-Tja
Community Expert
Ka-TjaCommunity ExpertAuthor
Community Expert
February 3, 2020

Oh, thanks for the tip. I hoped for an easier solution. But it could be cool to try this one as well :)))

rcraighead
Legend
February 1, 2020

Do you mean without dragging the pattern swatch onto the artboard? How would you want them saved? Graphic Styles? Swatches? Symbols?


The first thing I'd do is drag the pattern swatch to the artboard, save as Symbol and delete instance. Then parse the elements in the symbols.

Ka-Tja
Community Expert
Ka-TjaCommunity ExpertAuthor
Community Expert
February 2, 2020

No. 

A pattern contains path items. I want to get these paths items using javascript. For example, if it is a pattern with dots. It contains a circle and a square. It seems, that as soon you create a pattern, these items are not reachable anymore from a script. Is it a way to reach these items, when they are in the pattern by using a script?

Disposition_Dev
Legend
February 3, 2020

make a path with no stroke and fill it with your pattern swatch.

select your path and expand it with app.executeMenuCommand()

dig through the resulting group to extract the colors