Hi,
I am at a disadvantage since I am not proficient in JS. I primarily use Python.
Even so, I have successfully opened a PSB file, can read the layer names, figured out how to toggle visibility in the active document as well.
My question is how do I access the embedded smart objects? I'm trying to write a tool that will toggle visibility on ALL smart objects in a massive PSB. Each embedded graphic has 3 layers all with the same names. I want a tool that will cycle visibility on all embedded layers without having to open each one and switch it.
Thanks in advance for any help!
[solved] [Python] How to access Smart Objects?
[solved] [Python] How to access Smart Objects?
Last edited by alonza1 on Tue Jul 14, 2020 6:45 pm, edited 1 time in total.
Re: [Python] How to access Smart Objects?
Before you create smart object create layers composition for layers. Create then from them SO and switch visibility without opening embedded layers by properties panel. Probably you can also open smart object to set layers compositions for the first time, then save document once for keeps and access layers compositions from outside the same way.
Re: [Python] How to access Smart Objects?
Figured it out. Here is roughly how it works:
Code: Select all
def AccessSmartObjects():
psApp = comtypes.client.CreateObject('Photoshop.Application', dynamic=True)
psDoc = psApp.Application.ActiveDocument
smartObjects = []
for layerGrp in psDoc.layerSets:
for layer in layerGrp.artLayers:
if layer.kind == 17: # 17 means it's a smart object
smartObjects.append(layer)
for layer in smartObjects:
try:
psDoc.activeLayer = layer
psApp.executeAction(psApp.stringIDToTypeID("placedLayerEditContents"))
smartDoc = psApp.activeDocument
print 'Run some function here on the smart object'
smartDoc.save()
smartDoc.close()
# after closing the smartDoc the main psd will now be the active document
except:
print 'passed on something here.'
pass
Last edited by alonza1 on Mon Jul 13, 2020 9:03 pm, edited 1 time in total.