Running a script in a new Maya instance


#1

Hello!

I decided to create a little asset manager on my spare time for my future personnal projects. I know the basics in programming (mostly MEL), so I thought it’ll be nice to do this manager to improve my script knowledge.

I managed to do a lot of things, like browse into a specific directory, show specific files depending their extensions, etc. I also wanted to make a screenshot of my files, in order to have a thumbnail, but I’m stuck there.

Here’s the thing:

Let’s say I have a scene opened - work.ma.
I load my asset manager and I realize that a file (toto.ma) doesn’t have a thumbnail; I click on the button “update toto.ma thumbnail” and a thumbnail is made.

So far I got the thumbnail procedure (creating the cam, doing the playblast on one frame, saving the pic etc), but I don’t want to merge my current opened scene (work.ma) with the toto.ma scene as the file -o does.

Basically, what I want to do is something like that:

> Start a new instance of Maya
> Open toto.ma in it (I got this part with the system command)
> Run my thumbnail creator script in this new Maya
> Close toto.ma scene.

So after long researches on internet, I read that command lines could be a solution for what I want, like creating a .bat calling something like “maya -batch -file toto.ma -script thumbnail.mel”, but every try I make is unsuccessful (maya isn’t recognized as a command, the path doesn’t exist …) and it’s still very hard to understand for me.

Can anyone help me :confused: ?
Thank you very much in advance!


#2

If you do not need the UI, the best way is to use mayabatch.exe. If you start it from within maya with a system call, the path environment should be correct and the file should be found.

A suggestion: Do it with python and pymel, it makes handling in most cases very much easier.


#3

Thanks Haggi for your feedback!
I wrote a .bat file with inside the following line, as you adviced me:

"C:\Program Files\Autodesk\Maya2016\bin\mayabatch.exe" -script "script.mel"

In script.mel, I open maya with the scene I want with the system, but I’m stuck there. Indeed, in the called script, there is all the stuff to do a screencap but nothing is done once the file is opened.

I figured that a proper .bat file would be something like that:

"C:\Program Files\Autodesk\Maya2016\bin\mayabatch.exe" -file myscene.ma -script "script.mel"

… but the -file flag doesn’t open my file.
Once again, I’m a beginner in this specific scripting case so my problem might be dumb, but I can’t see where it doesn’t work :sad:

(PS: for my script I used mel for the few lines, but I can use python if it’s much easier)


#4

First, if you want to do a snapshot of the screen, you will need the UI what means mayabatch will not work because it does not open the UI. So you will have to use “maya.exe -script …”.

The difference is that maya.exe will not exit automatically if the script is done, so you have to add a quit(); at the end of your script if you want Maya to close.

So for me works this:


fullPathToMayaBin/maya.exe -script "somePath/myScript.mel"

If you only use a few lines of mel, it does not matter if you you python or mel. For larger scripts especially if you want to do some filesystem operations like directory listings etc. python offers some nice tools.


#5

Thank you very much Haggi, that was exactly what I was looking for :slight_smile: !