You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Goes without saying that this depends entirely what properties you're looking to get, but here's a good start. You can run this as a script with the files as command-line arguments.
Windows
importsysfromos.pathimportabspath# Pretty printing, so that the result is legiblefrompprintimportpprintfromwin32com.clientimportDispatchps=Dispatch("Photoshop.Application")
# Add/remove any properties you want returned heredefparse_layer(lyr):
return {
"name": lyr.Name,
"opacity": lyr.Opacity,
"blend mode": lyr.BlendMode,
"bounds": lyr.Bounds
}
defget_layer_info(parent):
result= []
foriinrange(1, parent.Layers.Count+1): # 1-based indexcurlyr=parent.Layers.Item(i)
info=parse_layer(curlyr)
# If it's a LayerSet, then run this again with the LayerSet as the parentifcurlyr.typename=="LayerSet":
info["items"] =get_layer_info(curlyr)
result.append(info)
returnresult# Reference files you want to inspect as command-line argumentsforfileinsys.argv[1:]:
print(f"Info for: {file}")
cur_doc=ps.Open(abspath(file))
pprint(
get_layer_info(cur_doc),
sort_dicts=False
)
cur_doc.Close(2)
macOS
importsysfromos.pathimportabspath# Pretty printing, so that the result is legiblefrompprintimportpprintfromappscriptimportapp, kps=app(id="com.adobe.Photoshop", terms="sdef")
defget_layer_info(parent):
# appscript lets us return all the layer's properties in one commandprops=parent.layers.properties()
fori, infoinenumerate(props):
# If it's a LayerSet, then run this again with the LayerSet as the parentifinfo[k.class_] ==k.layer_set:
info[k.layers] =get_layer_info(parent.layers[i+1]) # 1-based indexreturnprops# Reference files you want to inspect as command-line argumentsforfileinsys.argv[1:]:
print(f"Info for: {file}")
ps.open(abspath(file))
pprint(
get_layer_info(ps.current_document),
sort_dicts=False
)
ps.current_document.close(saving=k.no)
No description provided.
The text was updated successfully, but these errors were encountered: