Communicating between Photoshop and Maya (Python)

This looks interesting in the context of this thread. Anybody tried it?

this looks very cool, but requires cc :frowning: I like the direction they are taking though. having full node access to PS is going to be very powerful.

I updated my pslib with http request support GitHub - theiviaxx/PSLib: Photoshop CommonJS modules

so you can use it like


(function() {
    var $http = require('lib/net');

    $http.get('http://www.google.com');
    $http.post('http://www.example.com/', {myvar: true});
    new $http.Request({
        url: 'http://www.example.com',
        method: 'POST',
        data: {myvar: true},
        files: [{file: 'path/to/file.png', name: 'file'}],
        onSuccess: function(response) {
            alert(response.content);
        },
        onUpdate: function(value, total) {
            $.writeln(value + '/' + total);
        }
    }).send();
})();

[QUOTE=Theodox;23663]This looks interesting in the context of this thread. Anybody tried it?
github.com/adobe-photoshop/generator-core/wiki/Generator-Architecture[/QUOTE]
I’ve heard about this way but never used. I also interested in real reviews regarding this matter.

I thought I should check out PyPs but I just can’t get it working.
I’ve installed pyps via the command line - pip install pathToZipFile
I’ve gone into photoshop and activated remote connections and set the password to “Swordfish”
Then in my Python shell (IDLE GUI, w. Python 2.7.11) I’ve executed the code you provided.
[QUOTE=TheMaxx;23602]


from pyps import Connection, EventListener

conn = Connection()
conn.connect(passwd='Swordfish')
conn.send('alert("Hello");', True)

print conn.send('$.version;', True)

def callback(message, *args):
    print message.command
    print message.content

def callback2(message, *args):
    print message.command
    print message.content
    print args

listener = EventListener(conn)
listener.start()
listener.subscribe('foregroundColorChanged', callback)
listener.subscribe('toolChanged', callback2, (True, 'xxx'))
listener.subscribe('currentDocumentChanged', callback)

## -- We need to keep the EventListener alive
while True:
    time.sleep(1.0)

[/QUOTE]
But nothing happens - I get no prints outs from the Python shell.
I’ve tried triggering the toolChanged -callback for example by switching tools in PS.
What am I missing?


I’ve also tried running it from Eclipse, but there I get errors about the methods being used (more precisely: how many args are passed):

Traceback (most recent call last):
File “C:\Users\ USER \Eclipse workspace\PyPs\pypstest.py”, line 5, in <module>
conn.send(‘alert(“Hello”);’, True)
TypeError: send() takes exactly 2 arguments (3 given)

Removing True from all conn.send() gives me:

<generator object send at 0x00000000023E74C8>
Traceback (most recent call last):
File “C:\Users\ USER \Eclipse workspace\PyPs\pypstest.py”, line 26, in <module>
time.sleep(1.0)
NameError: name ‘time’ is not defined
Exception in thread Thread-1:
Traceback (most recent call last):
File “C:\Program Files\Autodesk\Maya2016\bin\python27.zip hreading.py”, line 810, in __bootstrap_inner
self.run()
File “C:\Python27\Lib\site-packages\pyps\pyps.py”, line 219, in run
msg = self._connection.send(SUBSCRIBE % item[‘eventName’], True)
TypeError: send() takes exactly 2 arguments (3 given)

and editing that in pspy.py (removing the True argument) gives:

<generator object send at 0x00000000028BC828>
Traceback (most recent call last):
File “C:\Users\ USER \Eclipse workspace\PyPs\pypstest.py”, line 26, in <module>
time.sleep(1.0)
NameError: name ‘time’ is not defined
ERROR:PSLIB:<generator object send at 0x00000000028BC828>
ERROR:PSLIB:<generator object send at 0x00000000025555A0>
ERROR:PSLIB:<generator object send at 0x00000000028BC828>

So I just imported time at the beginning of the script and it runs - but there is still nothing happening inside Photoshop.
Not even the alert() appears in Photoshop with this:

from pyps import Connection

conn = Connection()
conn.connect(passwd=‘Swordfish’)
conn.send(‘alert(“Hello”);’)

Worth mentioning:
I’m on Photoshop CC 2015 - is that a big no no?

dammit, i need to update the docs better. If you look at the tests in the pyps repo, you’ll see the new api usage. Theres now a send() method with returns a generator that you need to consume and a .send_sync() method which just takes the js to execute and blocks until a result is returned.


c = Connection()
c.connect('Swordfish')
c.send_sync('alert("Hello");')

[QUOTE=TheMaxx;29347]dammit, i need to update the docs better. If you look at the tests in the pyps repo, you’ll see the new api usage. Theres now a send() method with returns a generator that you need to consume and a .send_sync() method which just takes the js to execute and blocks until a result is returned.


c = Connection()
c.connect('Swordfish')
c.send_sync('alert("Hello");')

[/QUOTE]

Maybe it’s too early in the morning for me but I’m totally lost tbh.
I have replaced the pyps.py with the pyps -module from your master branch (py_des.py, pyps.py and the package init) and I’ve also created that test_ps.py file in another location than the module folder.
However, it is looking for another module (pytest) which I can’t find. Also I’m quite confused as to what exactly I need from these files (classes and functions - and that new decryption-stuff).

first, pytest is py.test, you’ll need to install that with pip. Again, thats my fault, i should have included that in setup.py. Its just a testing framwework and not needed for the actual lib.

init just imports some things from pyps for you and py_des is a purepython encrypt/decrypt lib. You need that to send and receive messages from photoshop. Are you getting any errors?

hi, thanks for all the inputs, I have combine all the information useful to me and put it into a complete simple and easy tool package,

call utt_PhotoshopUI.py, basically a Maya script editor like Javascript Script Panel, let you send commands and received output in the same Qt windows,

of course, you can just use the simplifed module_photoshop.py as a part of your own tool.

Main method is based on “Photoshop theCustomScript.jsx” method, since it works for all photoshop versions, and cross-platform, and potentially works for all other adobe applications, like After Effects, Indesign, AI, etc.

however, i am also planning to wrap the dedicated photoshop cs5+ “remote connection” method into a ready-to-use-tool, if later I may work heavy on Photoshop.

here is code on my github: GitHub - shiningdesign/utt_PhotoshopUI: created based on universal_tool_template.py, together with module_photoshop.py, it allow you to run a cross-platform, cross-application Qt UI to scripting Photoshop in Javascript like Script Editor in Maya.