Here is a quick code snippet for calling a Python script from Substance Painter and parsing the results. The in/out is very simple, but serves as an example of using the alg.subprocess.check_output function to bridge the JS api and your own Python scripts. // This can be called from the QML UI, or elsewhere in the plugin code. function GetAllFilesInDirectory(root) { if (root == undefined) return; // I put my scripts in a relative path to keep my plugin tidy. var script_path = "Scripts/FileUtils.py"; // Gathering files var ret = "NOSTRING"; try { // The arguments are used as parameter inputs to the Python script. This requires some planning // and well communicated conventions, but works well enough. ret = alg.subprocess.check_output( [ pypath, // Absolute path to interpreter. script_path, // Relative path to the py script. "log_files_of_type", // sys.argv[1], in this case the python
This little guide is written for Photoshop Cs5. Other versions of Photoshop may have slightly different folder setups and listener output locations. As discussed in a few of my earlier posts, Python is a great choice for scripting in Photoshop when coupled with a good COM interface and a desire to make monkeywork just go away . But as you are busy putting those monkeys to work it is inevitable that you will come up against a command or two that's not made available in the regular Photoshop scripting documents. CRISIS! The monkeys go on strike. But wait, there is hope! Introducing awesomeness... The scripting listener is a brilliant plugin for Photoshop. Using it gives you access to many commands that are not included in the Photoshop scripting reference. While active (that is, present in the Automate folder) it spits out a JS and VB log of all all your actions in Photoshop. For the purposes of this guide we are only really interested in the VB log. Getting useful Python code fro
So here is a working example of what I was talking about in my last blog post- making Photoshop automation possible without needing to use the win32com module. This specific example is not cross-platform compatible. It relies on getting the Photoshop application through it's registry entry, but the subprocess module is cross platform so it shouldn't be too hard to hammer this into a shape that can be used on Mac and PC. Or just Mac. Or whatever. Essentially there is no real magic going on here, just lots of string manipulation behind the scenes. Like I said in my last post, the biggest hole in this right now is the lack of feedback from Photoshop, but that's something I'm looking into when I get a few spare minutes here and there. Here is the example. When you run it, you should come up with something that looks like this: What an Amazing document. And the code! This is a particularly long snippet. Hang in there! Essentially when the commands are called, like add_new_
Comments
Post a Comment