forked from bengolder/py-adobe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchLayers.py
More file actions
103 lines (87 loc) · 3.4 KB
/
matchLayers.py
File metadata and controls
103 lines (87 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
from appscript import *
from mactypes import *
def matchLayers(inFilePaths, outFilePaths, fileType='.ai'):
"""Reads the graphic style of an open illustrator files, and edits a batch
of files to match.
Records the layer order, stroke, opacity, fill, and dash of each layer
in the open file, and then edits in each layer in the batch of
documents to match the settings of the open document. The open document
must have at least the layers that exist in the batch of document.
"""
find = app('Finder')
il = app('Adobe Illustrator')
# read the settings of the current document
docName = il.current_document.name()
doc1 = il.documents[docName]
layers = doc1.layers()
layerList = []
opacityList = []
colorList = []
filledList = []
strokedList = []
strokeList = []
fillList = []
dashList = []
strokeCapList = []
strokeJoinList = []
# loop through layers of current document
# store a value for each layer
for layer in layers:
layerList.append(layer.name())
item = layer.path_items()[0]
opacityList.append(item.opacity())
strokedList.append(item.stroked())
filledList.append(item.filled())
colorList.append(item.stroke_color())
strokeList.append(item.stroke_width())
fillList.append(item.fill_color())
dashList.append(item.stroke_dashes())
strokeCapList.append(item.stroke_cap())
strokeJoinList.append(item.stroke_join())
for i, inPath in enumerate(inFilePaths): # This is an appropriate place to limit the number of files
outPath = outFilePaths[i]
f = File(inPath)
il.open(f)
# switches the doc ref to the newly opened document
doc = il.current_document()
for j in range(len(layerList)):
layerName = layerList[j]
opacity = opacityList[j]
color = colorList[j]
stroke = strokeList[j]
fill = fillList[j]
dashes = dashList[j]
stroked = strokedList[j]
filled = filledList[j]
caps = strokeCapList[j]
joins = strokeJoinList[j]
layer = doc.layers[layerName]
try:
layer.opacity.set(opacity)
for item in layer.path_items():
item.stroked.set(stroked)
item.filled.set(filled)
if stroked:
item.stroke_color.set(color)
item.stroke_width.set(stroke)
item.stroke_dashes.set(dashes)
item.stroke_cap.set(caps)
item.stroke_join.set(joins)
if filled:
item.fill_color.set(fill)
layer.move(to=doc.end)
except:
pass
doc.save(in_=outPath )
doc.close(saving=k.no)
if __name__=='__main__':
layerstring = 'solids'
inFolder = '/Volumes/BOOTCAMP/amigos/exports/'
outFolder = '/Users/benjamin/projects/amigos/%s' % layerstring
from mergeSketch01 import ids
#ids = range(1,766)
inFiles = ['%s%s.ai' % (i, layerstring) for i in ids]
inFilePaths = [os.path.join(inFolder, p) for p in inFiles if layerstring in p]
outFilePaths = [os.path.join(outFolder, p) for p in inFiles if layerstring in p]
matchLayers( inFilePaths, outFilePaths )