r/pythonhelp • u/CodingInMyCup • Apr 27 '22
Is it possible for a Python Script to automate tasks across multiple applications? (Context in post)
I'm new and still learning Python, so l am not sure how to necessarily ask this question properly.
Basically I am wondering is it possible to create a Python Script that will automate tasks across multiple applications?
For context, I am a product designer by day, and am wanting to automate some mundane tasks that involve performing some tasks in my 3D modeling software (Rhino), saving out that 3dm file, then taking the file and opening it in the rendering software (Keyshot) and performing some tasks/render save outs, then taking the png file and resizing and other tasks in Photoshop, and finally saving over the previous png. I know these applications can read Python, as they have built in Python Consoles for scripting. So I am sure worse comes to worse I just write scripts for each individual tasks. I am just hoping there’s a way (and not even necessarily for these specific applications) to have a Python script that can work across multiple applications.
I am not necessarily looking for exactly how to do this, unless of course someone is able to provide a script 😂. But more so, I am just wondering if this is even possible and if so, what is the terminology/name of the process of creating a script that works across multiple applications?
I have tried googling, but because I am not too familiar in this subject, I am struggling to find the proper words and terminology to search for a solution and learn how to script what I am wanting (if it’s even possible). TIA
1
u/Zeroflops Apr 27 '22
One other thought. You mention resizing etc in photoshop. Depending on what your doing you could do that in python with different modules. Simple resizing an image can be done easily, depending on what other actions you want to do, you might be able to remove photoshop from the equation.
1
u/CodingInMyCup Apr 27 '22
Yeah there’s a few more actions needed before resizing, and for the most part they are all automated besides the resizing. For the resizing, we will put an exact dimension (acquired from the 3D model, to resize the image to a 1 to1. Ideally if I can automate across multiple platforms, I’d like to pull that dimension float from the 3D model and have it insert into the resizing step at the end.
1
u/throwaway8u3sH0 Apr 28 '22
Yes, it's possible. How easy depends on the application and how it interacts with Python. Usually it's a trade-off between versatility and power.
So, for example, the most universal library is something like PyAutoGui. That library lets you control the mouse and keyboard, so in theory you can make it work with any program. But if what you want to do requires intricate mouse commands (like rotating a 3d object a certain way), it's going to be very hard to script the mouse to do that.
The other possibility is an actual library for the program. For example, here's a snippet of code that can resize an image in Photoshop (once you've done the proper imports and set up the doc correctly):
...
doc.ResizeImage(Width=2048,
Height=2048,
Resolution=300,
ResampleMethod=8)Pretty straightforward. Think about how you'd have to program that if just using the mouse and keyboard -- Find the right menu. Click Resize. A form pops up asking for details about the resize. You have to navigate to each input box, highlight the contents and replace them with the numbers you want. Then you click "Ok" (or "Resize" or whatever the confirmation button is called, but you need to know exactly what it's called to find it on the screen). It's a lot...
So you get a lot of power in a single command, but there may be restrictions on how the library can be used. Maybe it has to be loaded as a plugin instead of run on the command line. The devil is in the details.
So, to summarize, yes, you can definitely automate it. Python can automate anything. How hard it will be depends on the details of what you're trying to do, what libraries exist to do it, and whether those libraries can be chained together in a single process.
1
u/CraigAT Apr 27 '22
Check out pyautogui: https://pyautogui.readthedocs.io/en/latest/
You can programmatically control your desktop, and therefore any apps running on your desktop.