Skip to content

Instantly share code, notes, and snippets.

@ptone
Created September 14, 2012 23:55
Show Gist options
  • Save ptone/3725666 to your computer and use it in GitHub Desktop.
Save ptone/3725666 to your computer and use it in GitHub Desktop.
extracting test polygons from a illustrator sketch: http://cl.ly/image/3M111A2O1Y0j
from appscript import app, k
import json
il = app(u'Adobe Illustrator')
doc = il.documents[u'GeoPolySketch.ai']
generated_code = ''
poly_template = 'self.{obj_name} = Polygon({points})'
for layer in doc.layers.get():
obj_name = layer.name.get()
anchors = [p[k.anchor] for p in layer.path_items[1].entire_path.get()]
# close the loop
anchors.append(anchors[0])
print poly_template.format(obj_name=obj_name, points=json.dumps(anchors))
self.A = Polygon([[15.66650390625, -70.4228515625], [18.966796875, -57.0556640625], [31.01318359375, -50.78515625], [28.2080078125, -72.732421875], [15.66650390625, -70.4228515625]])
self.B = Polygon([[34.5, -63.0], [34.5, -70.5], [51.0, -70.5], [34.5, -63.0]])
self.C = Polygon([[4.775390625, -76.5], [24.24755859375, -40.5], [59.396484375, -40.5], [35.3037109375, -76.5], [4.775390625, -76.5]])
self.D = Polygon([[32.5, -40.5], [44.5, -40.5], [44.5, -45.5], [32.5, -45.5], [32.5, -40.5]])
self.E = Polygon([[32.5, -31.5], [44.5, -31.5], [44.5, -40.5], [32.5, -40.5], [32.5, -31.5]])
self.F = Polygon([[32.5, -31.5], [44.5, -31.5], [44.5, -40.5], [32.5, -40.5], [32.5, -31.5]])
self.G = Polygon([[67.775390625, -71.8134765625], [53.689453125, -86.5], [68.0, -86.5], [67.775390625, -71.8134765625]])
self.H = Polygon([[66.5, -64.5], [52.5, -64.5], [52.5, -58.5], [66.5, -58.5], [66.5, -64.5]])
self.I = Polygon([[91.5, -54.5], [77.5, -54.5], [77.5, -40.5], [91.5, -40.5], [91.5, -54.5]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment