Hey folks,
I’m kinda stuck with the attempt to read the current size of the paint brush tool in PS. I connect from Python via COM and actually I’m able to set the brush size and get it afterwards, but not to get it without having it set before.
Here’s the code snippet that works for setting (and then getting) the size. (Info: ctid() and stid() just call charIdToTypeId and stringIdToTypeId from Photoshop.Application).
@staticmethod
def set_paintbrush_size(brushSize):
des0 = client.Dispatch("Photoshop.ActionDescriptor")
ref = client.Dispatch("Photoshop.ActionReference")
ref.PutEnumerated(ctid("Brsh"), ctid("Ordn"), ctid("Trgt"))
des0.PutReference(ctid("null"), ref)
des1 = client.Dispatch("Photoshop.ActionDescriptor")
des1.PutUnitDouble(stid("masterDiameter"), ctid("#Pxl"), brushSize)
brSize = des1.GetUnitDoubleValue(stid("masterDiameter"))
print brSize
des0.PutObject(YPSGlobal.ctid("T "), YPSGlobal.ctid("Brsh"), des1)
psApp.ExecuteAction(ctid("setd"), des0, 2)
If I call that function with brushSize=50 Photoshop sets the brush to that size and I can print it out.
But if I remove the line
des1.PutUnitDouble(stid("masterDiameter"), ctid("#Pxl"), brushSize)
it suddenly stops working and throws:
brSize = des1.GetUnitDoubleValue(stid("masterDiameter"))
File "<COMObject Photoshop.ActionDescriptor>", line 2, in GetUnitDoubleValue
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Adobe Photoshop', u'General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- <no additional information available>', None, 0, -2147212704), None)
Does anybody know what’s wrong about it or can provide some help on how to read the brush size from Photoshop?
I already worked myself through the PS CS6 Scripting Reference, searched in the PS Forum and tried to find something in the object-model viewer of the Extendscript Toolkit, but all with no success.
Any help is much appreciated!
Thanks in advance.