Setting up our Maya session in a bat file

921 views
Skip to first unread message

Benjam901

unread,
Oct 31, 2015, 4:02:44 PM10/31/15
to Python Programming for Autodesk Maya
* Google group error in my attempted last post, re-posting here

Hello all,

I have been meaning to set up a scripting blog on my portfolio for a while and have just finished a tutorial on setting up a localised Maya environment using batch files:

The tutorial covers:
What it is
Why it is useful
Setting up relative pathing per user
Setting up relative pathing to Maya scripts
Setting our PYTHONPATH locally giving Maya access to specified directories
Setting up a pinnable bat file shorcut
Opening Maya files with it (double clicking on files in windows)

If you have 10 mins and are interested please take a read and let me know what you think :)

PDF / word doc and tutorial material is inside the zip file

Cheers,

Ben
maya_batch_file_tut.zip

Justin Israel

unread,
Oct 31, 2015, 4:20:45 PM10/31/15
to Python Programming for Autodesk Maya
Hey Ben,

I had a couple questions...

You make a couple references to the preference of switching to the system PyQt4 versus the Maya PySide, for reasons of it being easier to develop without a Maya-specific PySide. I wasn't clear on this statement. I don't believe there is anything special about the Maya PySide, other than it being bundled. Could you just as easily install PySide on your system, the same as you would PyQt, and then be able to use PySide inside and outside of Maya?  This isn't really a comment on preference or anything. I just didn't get the part about it being easier to develop, or that anything was special about PySide in Maya.

Also, as a non-windows user that hasn't seen batch file programming in many many years, I was a bit unclear as to the behavior of the built PYTHONPATH at runtime. I figure this is similar to someone who uses windows and knows nothing about batch file syntax.  Is that a hard-coded SHOW variable in the batch file, or does it somehow derive from external sources? Or is the goal that you would have different batch files for different shows, and the only externally derived bit is the CGROOT? I'm trying to map this to my osx/linux env experience, where you would launch Maya from a shell, with a wrapper that would pick up your shell environment. Such as, starting from a shell that is set to SHOW=MyShow, in which case that Maya session would be launched under those settings. 
Maybe it might help to describe the behavior of the variables and the intended usage of the batch file? As in, how would you end up using it across 3 shows?

Justin


On Sun, Nov 1, 2015 at 8:47 AM Benjam901 <benandr...@gmail.com> wrote:
Hello all,

I have been meaning to start a scripting blog on my portfolio for a while now and have recently finished up a tutorial that covers setting up a localised Maya environment using batch files.

The tutorial covers:
What it is
Why it is useful
How we set it up
How we can set relative pathing for each users session
How we can open our Maya files using our setup (double clicking in windows)
Setting up a pinnable shortcut
Customising our Maya icons and splash screen

If you have 10 mins please take a read and let me know what you think :)

Cheers,

Ben

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1987a6d4-7924-4bff-976c-b08085502bb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Hearn

unread,
Oct 31, 2015, 4:45:04 PM10/31/15
to python_in...@googlegroups.com
Hey Justin,

Thanks for the feedback I should have been more concise with the explanation of SHOW and CGROOT. 

The SHOW variable is hard coded to the batch file In question and Is the name of the top level directory where your tools live. For example if you had a huge structure for maya tools and your batch file was 5 directories into your top level folder the for loop steps back through the directories until it finds the folder name specified with SHOW.
CGROOT is mapped throughout the for loop and is the path to the top level directory you specified in SHOW. 

My CGROOT on my machine would end up being D:/projects/tools/maya_tools for example. 

If we had 3 projects we could set 3 batch files up and simply change the SHOW variable to use an entirely different set of directories if we wanted to or even restrict a specific maya setup to only step back a couple of directories and not give it full access to our entire tools folder.

We use the CGROOT variable on our python path so we can set CGROOT/dirname/subdir/subsubdir etc. 

The built PYTHONPATH at runtime does the same thing as sys.path.append but we are not specifying it in a script we are giving maya and any other script we want to run access to these directories specified. It allows us to easily add directories later without the hassle of any scripts in our sub folders not having access to them. 

Yes you can install pyside on your machine but I use the anaconda python distributable and when I'm using my IDE (pycharm) I can run any UI using pyqt without having to install pyside and avoid that hassle inside my IDE. I think it's a personal preference :)

I hope that cleared up a couple of things. I will amend the tut to more clearly explain your feedback 

Cheers,

Ben
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0nkVzT9Qmy810Q40_hLRFn1oPc%3DR9noXkTTk11jjnYEA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Tel - +46 76245 92 90 (Sweden)

Justin Israel

unread,
Oct 31, 2015, 4:58:08 PM10/31/15
to python_in...@googlegroups.com

l

On Sun, 1 Nov 2015 9:44 AM Ben Hearn <benandr...@gmail.com> wrote:

Hey Justin,

Thanks for the feedback I should have been more concise with the explanation of SHOW and CGROOT. 

The SHOW variable is hard coded to the batch file In question and Is the name of the top level directory where your tools live. For example if you had a huge structure for maya tools and your batch file was 5 directories into your top level folder the for loop steps back through the directories until it finds the folder name specified with SHOW.

CGROOT is mapped throughout the for loop and is the path to the top level directory you specified in SHOW. 

My CGROOT on my machine would end up being D:/projects/tools/maya_tools for example. 

If we had 3 projects we could set 3 batch files up and simply change the SHOW variable to use an entirely different set of directories if we wanted to or even restrict a specific maya setup to only step back a couple of directories and not give it full access to our entire tools folder.

We use the CGROOT variable on our python path so we can set CGROOT/dirname/subdir/subsubdir etc. 

The built PYTHONPATH at runtime does the same thing as sys.path.append but we are not specifying it in a script we are giving maya and any other script we want to run access to these directories specified. It allows us to easily add directories later without the hassle of any scripts in our sub folders not having access to them. 

Oh I see it now. The pdf didn't go into detail on what that for loop really does. I glossed over it.

Yes you can install pyside on your machine but I use the anaconda python distributable and when I'm using my IDE (pycharm) I can run any UI using pyqt without having to install pyside and avoid that hassle inside my IDE. I think it's a personal preference :)

So does that mean you still build and install PyQt for Maya 2016? Or that you always write your Maya UI code to dynamically switch on whichever is available to import (using that method which remaps PySide to PyQt names, and sticking to SIP api v2)


--

<img src="https://ci3.googleusercontent.com/proxy/a_UFhwHkn_1-r78vYCHjmB12ryot0bY5WWMX5kXIaLF28rBlLQfIDVBKuShy_4q9dui8rTtIYfJakyYgy5WkoFrsI-sK_YsaGMsvOgyCuoCVgbC5JXtEGjoCz2xjrIROpNyudrK86lNLV8SQ16Y1bVMWA90pUA=s0-d-e1-ft#https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash3/1397644_10151776789302986_608293640_o.jpg">

Tel - +46 76245 92 90 (Sweden)

LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b

--

You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkWw64YMKAN1LPM3L%3D%3D%3Dg-33YrkzeBWFeam93PY_A_n5cw%40mail.gmail.com.

Ben Hearn

unread,
Oct 31, 2015, 5:05:11 PM10/31/15
to python_in...@googlegroups.com
Yes essentially we are dynamically switching from PySide to PyQt4. Not sure about building and installing for Maya, we are just telling maya to use the system version of pyqt. We do not need to install and build into Maya's system directories. We are essentially keeping our native maya clean and unaltered. We can still use pyside if we want to 
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0i%3D6C_P%2BLTzw9GkMLgQZrE1OgAkMSYG41mzAqRr%2B5FSQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Justin Israel

unread,
Oct 31, 2015, 5:10:27 PM10/31/15
to python_in...@googlegroups.com


On Sun, 1 Nov 2015 10:05 AM Ben Hearn <benandr...@gmail.com> wrote:

Yes essentially we are dynamically switching from PySide to PyQt4. Not sure about building and installing for Maya, we are just telling maya to use the system version of pyqt. We do not need to install and build into Maya's system directories. We are essentially keeping our native maya clean and unaltered. We can still use pyside if we want to 

But does that work across many versions of Maya, when the Qt ABI changed? It means your system install works for a certain range of Maya's. Then again you probably aren't running Maya 2013 anymore. But what happens if they bump the Qt ABI on the next Maya? I suppose it just means your batch file needs to switch on different locations of PyQt to match the Maya

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkVh2y5Qeay%2B%3DeENgYn9mtHHjMWRrzi7prdg_2OrwTGDUg%40mail.gmail.com.

Arvid Schneider

unread,
Oct 31, 2015, 5:13:49 PM10/31/15
to python_in...@googlegroups.com

Ben Hearn

unread,
Oct 31, 2015, 5:15:35 PM10/31/15
to python_in...@googlegroups.com
Yes, we can set our pyqt version to whichever works with maya it does not have to be fixed. In my example my pyqt path is set to c/anaconda/pyqt. We can easily change this to a newer or older version of pyqt by just setting the path on our PYTHONPATH 
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2w%3Dz0RxVpCKNbTfcwafP-RKvJN1frmkf5G%2BFgs8L_UYw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Justin Israel

unread,
Oct 31, 2015, 5:18:36 PM10/31/15
to python_in...@googlegroups.com


On Sun, 1 Nov 2015 10:13 AM Arvid Schneider <arvidsc...@gmail.com> wrote:

Guys it's Halloween ;)

It was Halloween for me yesterday, in New Zealand ;-)

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7993D3F1-1E22-45CE-BAA4-83BFE26FB8FF%40gmail.com.

Justin Israel

unread,
Oct 31, 2015, 5:20:55 PM10/31/15
to python_in...@googlegroups.com


On Sun, 1 Nov 2015 10:15 AM Ben Hearn <benandr...@gmail.com> wrote:

Yes, we can set our pyqt version to whichever works with maya it does not have to be fixed. In my example my pyqt path is set to c/anaconda/pyqt. We can easily change this to a newer or older version of pyqt by just setting the path on our PYTHONPATH 

Right on. Just clarifying. The script is meant to be all-inclusive to bootstrap Maya.

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkW38wuD0N%2Bru6%3DFzQEoarxmPGJKd%3D9mq8SixAm4-Lg%2Bqg%40mail.gmail.com.

Ben Hearn

unread,
Oct 31, 2015, 5:27:15 PM10/31/15
to python_in...@googlegroups.com
Yes indeed. An all inclusive maya bootstrap. Great way to sum it up :) how is it the logic working with osx? 
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA29HDWZq1JR8cHqaxhknXBp7QzzxwAcZDKPu%3Dt4p1U6ww%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Arvid Schneider

unread,
Oct 31, 2015, 5:30:12 PM10/31/15
to python_in...@googlegroups.com
The you have to party NZ just won the World Cup ;)

Justin Israel

unread,
Oct 31, 2015, 5:45:38 PM10/31/15
to python_in...@googlegroups.com
On Sun, Nov 1, 2015 at 10:27 AM Ben Hearn <benandr...@gmail.com> wrote:
Yes indeed. An all inclusive maya bootstrap. Great way to sum it up :) how is it the logic working with osx? 

Since the intention was to have a completely self-contained bootstrap, then the same approach could be done on osx or linux, where you build paths from current variables. I was just referring to a situation where the bootstrap wasn't 100% self-contained, and derived stuff like the SHOW settings from the launching shell:

$ facility_env_set_shot myShow myScene myShot
$ maya

In an example like this, you have some kind of facility way of setting your show/scene/shot env to impact all subsequent commands. So when I would launch "maya", which could be the actual bootstrap wrapper, it could look at $SHOW, $SCENE, $SHOT, to derive the rest of the paths that should be configured. 

But I think you could do this same thing from a Window shell? Although I think most windows users don't work out of the cmd prompt, and prefer to double click everything? I don't know. I haven't worked many windows shops (outside of a 12 person boutique shop that had zero pipeline). 

Ben Hearn

unread,
Oct 31, 2015, 5:54:20 PM10/31/15
to python_in...@googlegroups.com
I hadn't considered that approach but you are correct most if not all windows users don't tend to work directly from the command line. Setting it up as we have here allows windows users to just double click on either the setup or the maya file itself 
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24%2BsTco%3D2Js5Ndx8%3Dyh_duJNivwooPFdoGG3SbGA0jAA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Oct 31, 2015, 6:07:33 PM10/31/15
to python_in...@googlegroups.com


On Sun, 1 Nov 2015 10:54 AM Ben Hearn <benandr...@gmail.com> wrote:

I hadn't considered that approach but you are correct most if not all windows users don't tend to work directly from the command line. Setting it up as we have here allows windows users to just double click on either the setup or the maya file itself 

Either way, nice write up. Thanks for sharing, and engaging on questions about it.


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24%2BsTco%3D2Js5Ndx8%3Dyh_duJNivwooPFdoGG3SbGA0jAA%40mail.gmail.com.



For more options, visit https://groups.google.com/d/optout.


--

<img src="https://ci3.googleusercontent.com/proxy/a_UFhwHkn_1-r78vYCHjmB12ryot0bY5WWMX5kXIaLF28rBlLQfIDVBKuShy_4q9dui8rTtIYfJakyYgy5WkoFrsI-sK_YsaGMsvOgyCuoCVgbC5JXtEGjoCz2xjrIROpNyudrK86lNLV8SQ16Y1bVMWA90pUA=s0-d-e1-ft#https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash3/1397644_10151776789302986_608293640_o.jpg">

Tel - +46 76245 92 90 (Sweden)

LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUQckDsJ69N7c9cwwYz%2BbT1AwL1PxyJsJ%2Bdijv6rqE3mA%40mail.gmail.com.

Ben Hearn

unread,
Oct 31, 2015, 6:10:02 PM10/31/15
to python_in...@googlegroups.com
No problem glad I could share. I'll amend the doc and explain the meaning of SHOW and CGROOT more clearly before I put it up on my portfolio and post it up again with the amendments
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3KzVauxch2S_CjoP_DXHCQ0RVBSnLXxiZVBVKTRQO%3D%2BQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Marcus Ottosson

unread,
Nov 1, 2015, 6:12:21 AM11/1/15
to python_in...@googlegroups.com

Hi Ben,

First off, great work. Having control over your environment is one of those invisible things you are either afraid of or have built your entire studio built upon, so this is a very good step in the right direction.

A few comments.

  1. As Justin said, there isn’t really a different between PyQt and PySide when working in or outside of Maya. In fact, if you use mayapy as your Python interpreter, then you won’t even need to install PySide nor Python separately, and will benefit from the exact environment as the one you have in Maya, with the added bonus of being able to actually initialise Maya at will to use more intimate features such as the cmds module.
  2. Bat files are at a disadvantage in a few areas.
    • One of which is portability. If you’re a Windows-only shop then that’s okay, but whatever work you do is locked to Windows and neither you or anyone else on Unix can benefit from it.
    • The other is syntax and what it can actually do for you. The syntax is of course new if you’re from Python, but also limiting compared to what they use on Unix; bash. A more powerful alternative on Windows is Powershell, which is essentially all of C# available via the command-line. It’s more powerful than bash in many respects, but then also more complicated to work with in as many circumstances. But the most powerful alternative is something we already know. Python. And it just so has it that Python is also cross-platform.

So here’s an example of what part of your script might looks like as .py instead of .bat.

import os
import subprocess

root = r"C:\Program Files\Autodesk\Maya2015"
exe = os.path.join(root, "bin", "maya.exe")
env = dict(os.environ, **{
    "CYGWIN": "nodosfilewarning",
    "SHOW": "maya_batch_file_tut",
    "USER": os.environ["USERNAME"],
    "MAYA_VERSION": str(2015),
    "MAYA_DISABLE_CIP": str(1),
    "MAYA_DISABLE_CER": str(1),
    "PYTHONPATH": ";".join([
        root,
        r"c:\Anaconda\Lib\site-packages",
        r"c:\some\other\path"
    ])
})

print("Running {exe} with:\n\t{env}".format(**locals()))
subprocess.call(exe, env=env)

Running that produces the same results and has the same advantages as you proposed about .bat, but is both cross-platform and more powerful. This isn’t the end though, the next phase might be to produce what Justin referred to above as a “wrapper” and implement more logic into it. That’s where .bat starts to show it’s flaws and where Python can really shine. Especially when moving on the the next-next phase; GUIs. :)



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Ben Hearn

unread,
Nov 1, 2015, 9:56:53 AM11/1/15
to Python Programming for Autodesk Maya
Hey Marcus,

I had indeed wondered about cross platform use for bat files. As I am not a Unix user my knowledge in the field of the bash command utility is limited. Your example on using Python since we have it already is a great way to go about things to make the setup cross platform.

I am going to experiment with your solution, this should be fun :)

-- Ben

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.

...

Marcus Ottosson

unread,
Nov 1, 2015, 11:33:16 AM11/1/15
to python_in...@googlegroups.com

While we’re at it, here’s how you might take it to the next level using Python.

There aren’t that many examples of interfaces for wrappers/launchers that deal with environment variables like this, yet oddly enough every studio that I’ve ever been to with even a hint of pipeline has had it in one form or another. Sometimes as a command-line utility like be, sometimes as a graphical interface and other times as some form of web/native hybrid where you establish an environment and launch software via something like Shotgun or Ftrack.

If you do find more examples, please do share. :)

For completeness, here’s the design document for be along with an earlier prototype.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.



--

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.

...

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ea9ae417-8e9f-4b68-9f11-35f7d2cb0294%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Nov 1, 2015, 1:01:18 PM11/1/15
to python_in...@googlegroups.com


On Mon, 2 Nov 2015 12:12 AM Marcus Ottosson <konstr...@gmail.com> wrote:

Hi Ben,

First off, great work. Having control over your environment is one of those invisible things you are either afraid of or have built your entire studio built upon, so this is a very good step in the right direction.

A few comments.

As Justin said, there isn’t really a different between PyQt and PySide when working in or outside of Maya. In fact, if you use mayapy as your Python interpreter, then you won’t even need to install PySide nor Python separately, and will benefit from the exact environment as the one you have in Maya, with the added bonus of being able to actually initialise Maya at will to use more intimate features such as the cmds module.Bat files are at a disadvantage in a few areas.One of which is portability. If you’re a Windows-only shop then that’s okay, but whatever work you do is locked to Windows and neither you or anyone else on Unix can benefit from it.The other is syntax and what it can actually do for you. The syntax is of course new if you’re from Python, but also limiting compared to what they use on Unix; bash. A more powerful alternative on Windows is Powershell, which is essentially all of C# available via the command-line. It’s more powerful than bash in many respects, but then also more complicated to work with in as many circumstances. But the most powerful alternative is something we already know. Python. And it just so has it that Python is also cross-platform.

So here’s an example of what part of your script might looks like as .py instead of .bat.

import os import subprocess root = r"C:\Program Files\Autodesk\Maya2015" exe = os.path.join(root, "bin", "maya.exe") env = dict(os.environ, **{ "CYGWIN": "nodosfilewarning", "SHOW": "maya_batch_file_tut", "USER": os.environ["USERNAME"], "MAYA_VERSION": str(2015), "MAYA_DISABLE_CIP": str(1), "MAYA_DISABLE_CER": str(1), "PYTHONPATH": ";".join([ root, r"c:\Anaconda\Lib\site-packages", r"c:\some\other\path" ]) }) print("Running {exe} with:\n\t{env}".format(**locals())) subprocess.call(exe, env=env)

Running that produces the same results and has the same advantages as you proposed about .bat, but is both cross-platform and more powerful. This isn’t the end though, the next phase might be to produce what Justin referred to above as a “wrapper” and implement more logic into it. That’s where .bat starts to show it’s flaws and where Python can really shine. Especially when moving on the the next-next phase; GUIs. :)

Also, if you don't want that python wrapper script sitting around as a parent process in the process tree, you could just exec the Maya process and let it replace the pid

https://docs.python.org/2/library/os.html#os.execvpe

You don't do anything after the subprocess returns, so the script is basically done with its job anyways. It can be cleaner in the long run is someone is ever inspecting their launched "maya" command, to actually get the pid of the Maya process and not a wrapper parent process.

For more options, visit https://groups.google.com/d/optout.



--

Marcus Ottosson
konstr...@gmail.com

--

You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBUxUuLMimNhZds_Nu6%2BX8nc%2BzLr_fCahaGFW2j8ODWhA%40mail.gmail.com.

Ben Hearn

unread,
Nov 2, 2015, 7:12:08 AM11/2/15
to python_in...@googlegroups.com
Hey Marcus,

I am just having a flick through the documentation and overview. It looks like an excellent tool. Is its focus primarily unix systems?

-- Ben


For more options, visit https://groups.google.com/d/optout.



--

Marcus Ottosson

unread,
Nov 2, 2015, 7:37:46 AM11/2/15
to python_in...@googlegroups.com

Also, if you don’t want that python wrapper script sitting around as a parent process in the process tree, you could just exec the Maya process and let it replace the pid

That’s a neat trick.

Is its focus primarily unix systems?

Thanks, happy to hear you like it. It’s mostly seen use on Windows, as far as I know, and it’s been developed there also. But it’s meant to be used on any major platform.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Nov 2, 2015, 7:39:50 AM11/2/15
to python_in...@googlegroups.com

Also, if you don’t want that python wrapper script sitting around as a parent process in the process tree, you could just exec the Maya process and let it replace the pid

Except it looks like Windows doesn’t “embed” the wrapped process in that way, instead both are visible with their own PIDs, should the wrapping process be long-lived. For a batch script, it usually dies upon completion, and Python does too unless it’s explicitly kept open.

--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Nov 2, 2015, 6:17:44 PM11/2/15
to python_in...@googlegroups.com
On Tue, Nov 3, 2015 at 1:39 AM Marcus Ottosson <konstr...@gmail.com> wrote:

Also, if you don’t want that python wrapper script sitting around as a parent process in the process tree, you could just exec the Maya process and let it replace the pid

Except it looks like Windows doesn’t “embed” the wrapped process in that way, instead both are visible with their own PIDs, should the wrapping process be long-lived. For a batch script, it usually dies upon completion, and Python does too unless it’s explicitly kept open.

Hmm, I will just take your word for it since I can't test that. Does it have to do with windows and double clicking? I know Windows has a different model for launching processes than POSIX. But I thought exec would work the same way, at least when launched from a command line within a Python script. Not sure about bat files though. 

 

Ben Hearn

unread,
Nov 4, 2015, 4:59:50 AM11/4/15
to Python Programming for Autodesk Maya
When you run the process in the batch file, the command line is opened as a process but it looks like as soon as the process is complete the process is killed. It would make sense since we are essentially just booting Maya at the end of the process. 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.

...

Justin Israel

unread,
Nov 4, 2015, 5:50:16 AM11/4/15
to Python Programming for Autodesk Maya

Yea its true, Windows has a different process  model and no exact equivalent for execv[pe] that works the same as posix
http://serverfault.com/a/567393/105722

It says it launches a new process and the calling process ends.

In terms of just booting up Maya, from a posix perspective, that could mean either exec'ing which replaces the current process with the Maya process, or launching it as a child process and waiting, which keeps the parent open as well, or forking Maya as a background process and letting the parent end (effectively what you are getting in windows, if the wrapper is finishing)


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.



--

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/UV_fdWrS3YM/unsubscribe.

To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.

...

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fbea4dc3-eb72-49c4-be40-cd2e88e5d0c6%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages