Photoshop / COM / BrushSize

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! :slight_smile:
Thanks in advance.

Push :slight_smile:

Really nobody? Seems like I’m the only one who tried doing that, eh? :slight_smile:

the reason it stops working is because you’re setting the value in the action descriptor and then reading out exactly the same value you just set. So if you don’t set the value beforehand PS gives you an error. What you’re missing is calling the command that puts the current value INTO the action reference… if there is a command for that?

Here’s a solution - save the current brush as template, then parse the template. Seems a bit cumbersome though:
http://1.adobe-photoshop-scripting.overzone.net/detecting-the-current-brush-size-t105.html

You’re right about reading a value that I’ve set before. It’s just there to demonstrate that I can read it once it was set. But yeah, that certain command you’re mentioning is what I’m looking for. I couldn’t find out anything useful from the SL code regarding reading variables from PS.

Also, I already kinda reverse-engineered the *.abr files (even with a slight success) but, honestly, that’s not the way I would like to go.
Think I will keep trying to find the right set of required commands for putting a variable from PS into a action reference.

I’ll post the results as soon as I find a solution.
Thanks for your comment.