Photoshop scripting, masks?

Been working on a idea for some workflow tools for PS, but after looking at the scripting documatation I see no way to manipulate layerset masks or layer masks.

Anyone found a workaround?

All i really need to do is copy one mask into the mask of a other layerset.

as far as i know, there is no api for masks. Use the scriptlistener and just copy what it spits out and wrap that in a function as best you can

That really sucks, how would I wrap it though it isn’t a 1 off thing I need to take the data from one mask and put it into a other mask.

Guessig I would beed to ensure that the right layerset is selected for the mask to copy which is easy enough but what about the target?

i believe it gives a string or a layer index for a source/dest in the script dump. Try to decipher it. i did something similar before but no longer have access to the code

Ahhh yes. Photoshop scripting; where once you start using script listener your scripts look like code from the matrix.

All of the parameters for the functions you call will be accessible in the script listener output, so you can pass in your own values. It can just take a bit to figure out what corresponds to what.

Thanks for the info guys, also I should be able to just reformat the script listener output, to work with python or c# right.

I’m accessing the api through the com interface, using python, so I can build a better ui using qt and pyside.

i believe so, but it will be even more confusing :slight_smile: You can always just use the ExecuteJS function and just feed it a string

ah ya that makes more sense, feed it a string of JS code, and just use string reformatting to put in any changes i want.

That’s probably a smarter idea, but I have always reformatted the code to work directly with pywin32 calls, so you end up with a function like

def hueSaturation(hue, saturation, lightness, colorize=False, psApp=None):
    if psApp is None:
        psApp = win32.gencache.EnsureDispatch('Photoshop.Application')
    dialogMode = 3
    idHStr = psApp.CharIDToTypeID( "HStr" )
    desc169 = win32.gencache.EnsureDispatch( "Photoshop.ActionDescriptor" )
    idpresetKind = psApp.StringIDToTypeID( "presetKind" )
    idpresetKindType = psApp.StringIDToTypeID( "presetKindType" )
    idpresetKindCustom = psApp.StringIDToTypeID( "presetKindCustom" )
    desc169.PutEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom )
    idClrz = psApp.CharIDToTypeID( "Clrz" )
    desc169.PutBoolean( idClrz, colorize )
    idAdjs = psApp.CharIDToTypeID( "Adjs" )
    list27 = win32.gencache.EnsureDispatch( "Photoshop.ActionList" )
    desc170 = win32.gencache.EnsureDispatch( "Photoshop.ActionDescriptor" )
    idH = psApp.CharIDToTypeID( "H   " )
    desc170.PutInteger( idH, hue )
    idStrt = psApp.CharIDToTypeID( "Strt" )
    desc170.PutInteger( idStrt, saturation )
    idLght = psApp.CharIDToTypeID( "Lght" )
    desc170.PutInteger( idLght, lightness )
    idHsttwo = psApp.CharIDToTypeID( "Hst2" )
    list27.PutObject( idHsttwo, desc170 )
    desc169.PutList( idAdjs, list27 )
    psApp.ExecuteAction( idHStr, desc169, dialogMode )

thanks for all the help guys, i managed to get some time to take a peek at it today, and played with it a little, and was able to make a JS function that duplicates the layerMask of the active layer to a named layer, so proved it is doable and flexible enough. SO i will soon remake that in my python code, and add some convince functions like haveing it set and restore the activeLayer for me, and having it accept a layer object instead of just a string name.

Also a other question, is how would i set up event callbacks, such as triggering one of my methods every time a layerSet is renamed removed or added?

EDIT: just found the notifier object, but it dosnt allow me to give it a callback, but only lets me give it jsx file to execute anyone got ideas how i can get python to know when a notifier event happens.

All i can really think if is a socket server, set one up in python, on a new thread to watch for a message. Than find some kinda socket library for JS that would be in the file executed from the notifier object in PS.

@TheMaxx you mentioned in a other thread you got a api that can sub to events in PS, is it able to accept function objects from python, that it fires when the event happens?

notifiers will simply call jsx files, so python is out. You can use my api for it, but it requires CS5+. If that works for you, then yeah, use your normal python functions for callbacks

How does your callback system work, I got no real need for the whole api, but still haven’t found a reliable way to emulate callbacks.

take a look at https://github.com/theiviaxx/photoshopConnection/blob/master/tests/test_ps.py. the test_listener has an example. you just set up the listener object and then subscribe to an event and give a callback when the event happens

getting a little stuck again when dealing with extendScript.

Am trying to get the intersection of 2 arrays, but extendScript has no intersection method.

So far i tried makeing my own, only to find out, unlike javaScript extendScript has no array.filter() or array.indexOf() methods, so i managed to create my own array.IndexOf(), but am still trying to figure out how to make the filter method, or find a other way to get the intersection of 2 arrays that dosnt require it.

nvm i was able to find what i need here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter