2

My first question on here after lurking for a long time whenever I need help!

First of all, sorry for the confusing title! My question is quite specific and didn't know how to sum it up!

I just want you to know that I am not a programmer. I only learn coding in the context of the software I use for my VFX work, that being, python for Maya.

While I am quite comfortable with python for Maya, I am now trying to write a script (on Windows exclusively) that requires a functionality that isn't built in Maya:

After collecting the textures paths used in the Maya scene, which I can do within python, I need to resize these images and save them as a different format

And the way I'm thinking of approaching this is using imagemagick, an image editor that runs from command prompt. I would create a .bat file containing the commands to run, using the textures paths collected as parameters, and then I would call that .bat file in my python script.

What I did so far is installing imagemagick, and testing its functionality from command prompt. I also created the batch file and made sure it works. Lastly I created a python script that calls this file.

Here is what my batch files looks like:

magick convert %1  %2

magick mogrify -resize 500x500 %2

pause 

pause being there to be able to see what's being executed.

And here is the python code I'm using:

import os
os.system("C:/users/Jay/Desktop/resize.bat %s %s" %(param1, param2))

param1 and param2 being two variables containing the textures paths as strings.

When I run the above code from the "Python (command line)" on windows, it works just fine and completes its job successfully.

However, when I try to run the same script from within Maya, I get this error:

'magick' is not recognized as an internal or external command, operable program or batch file.

Command prompt snapshot

Any reason why magick is not being recognized when running from within Maya? Is there any way to solve that?

I'm sorry for the long question! I'm just trying to be clear! And thank you in advance!

aschipfl
  • 31,767
  • 12
  • 51
  • 89
Jay
  • 23
  • 3
  • 1
    Typically, when running from some tool other than the shell, you should put the full path to magick in your bat file. Also you seem to be using ImageMagick 7. If so, then use magick and not magick convert. But you still need magick in front of other tools such as mogrify. – fmw42 Jun 08 '20 at 19:48
  • 1
    See Mark's solution below. It is more detailed than my comment above. – fmw42 Jun 08 '20 at 19:49

1 Answers1

2

The issue is that your PATH doesn't include the directory which contains the magick.exe program, so it can't be found.

Either add that directory to your system's PATH variable - it used to be done like this about 100 years ago when I last used Windows.

Or, use the full path in your batch file:

C:\PATH\TO\IMAGEMAGICK\magick.exe ...

Also, your script can be simplified to:

C:\PATH\TO\IMAGEMAGICK\magick.exe %1 -resize 500x500 %2
Mark Setchell
  • 169,892
  • 24
  • 238
  • 370
  • 1
    It may, or may not, also be advisable to surround `%1` and `%2` with double quotes in case they contain spaces... not sure. – Mark Setchell Jun 08 '20 at 19:52
  • Hello Mark! Thanks for your answer, that was quick! I can;t believe it was something as simple as that! problem solved! Cheers! – Jay Jun 08 '20 at 19:58
  • 1
    Cool - good luck with your project! Come back if you get stuck, questions (and answers) are free – Mark Setchell Jun 08 '20 at 20:30