Texture Monkey: Starting to look like a real tool.
Stuff is happening... |
After a little while in the field it came to be pretty apparent that the win32com module can't be relied upon to consistently work on everyone's machines. I spent a good amount of time trying to work out why, but came up with no solution that worked consistently on everyone's workstations. Errors like ('Member not found, None, None) would constantly pop up in their debug feedback, but not on mine. Talk about frustrating. So I got pretty annoyed and just ripped the win32com components out.
This was a pretty big undertaking, because apart from the GUI, win32com stuff made up about 80% of the remaining code. The P4 functionality wasn't touched, because its operating through it's own native API.
The solution: Photoshop Automation without win32com!
The solution I went with was to write a wrapper around the JavaScript equivalent of what I was using the win32com module for. Each of these commands would be put into a list, which is then compiled into a temporary .jsx file. Finally this file is sent to Photoshop using the subprocess module.
To deal with getting information from Photoshop a similar process was used. A JavaScript command is called to write the requested data to a file on disk, while Python waits until it can see that the file has been modified. Once Python can see that Photoshop has completed writing to the file, the contents are read and fed back into the main program.
Benefits/Cons
Benefits? Right off the bat, the JavaScript executes much more quickly than the win32com commands. This is pretty cool, especially when coupled with the fact that it now works on all the artists machines without mysterious bugs. Yet. Also, I still get to keep writing the tool in Python.
The biggest con is that I can't help but feel that its a mother of a hack. I mean, writing JavaScript on the fly from Python to send to a program which can only feed data back through a temporary text file? Man. Awful. But it works. But I feel dirty. But it works. But what about those ugly chunks of strings pretending to be JavaScript? But it works. Yes it works. The structure of the code behind the scenes feels like its taken a train to the chest, but it works. My next couple of days will be pulling it together and making the code a little easier on the eyes.
Comments
Post a Comment