Check out my portfolio and contact me.

Archive for the ‘Tutorial’ Category

Setting up environment variables for Mac and

Posted on: February 14th, 2013 by Redd 5 Comments

Okay so I’m in my second semester at the Dojo and i’m focusing on pipeline creation. I have both Mac and Windows on my system at home. I favor Mac but work just as fine on Windows. In the initial set up to begin connecting everything together for a pipeline it’s rather easy to do on Windows… Not so much for Mac and so I wanted to do a quick write up on how to setup environment variables for Mac for any of the other crazy Mac user TD’s out there.

First off the programs you will be using are Terminal (which is part of the system), Xcode (which doesn’t come with OS X but can be found here) and a script editor of your choice (I use Sublime2 it’s a paid application but in my opinion worth the money). Now we will be doing things in the Terminal app and if you’ve never opened it up before it is a good time to finally do it! If you are new or just rusty on commands in Terminal I’d recommend checking MacRumors Terminal guide, it should get you up to speed or at least understanding some of the basics quick enough.

Before we begin I’m going to be showing and discussing a lot of things talked about in Lebenszeichen’s blog. The code will be the similar and the how to will be about the same but with my own take since i’m integrating this into Maya as well.

Environment Variables for Mac

To create an environment variable on Mac it requires the creation of a file called “environment.plist”. But unfortunately there are some steps required to get everything set up properly.

Now to start, open up Terminal (which is found in the utilities folder inside of the applications folder) you should see something similar to this.

Environment Variables for Mac - Terminal Window

Now in Terminal type.

cd ~

This is just to make sure that we are in the root directory or the users directory. The cd just means to change directory and the ~ means the root directory. Now that we are in the root directory type.

ls -a

This should display all the folders contained in the user directory. Not only do you see all the folders that you would normally see but you should also see a number of folders with a “.” at the beginning of the names. Naming folders with a “.” at the beginning is strictly for the OS which is why they are hidden from all users. There are some other folders hidden in user directory as well but for now let’s move on.

Check to see if there is a folder named “.MacOSX” if there is you can skip the next step and move onto the creation of the environment.plist file. If the directory doesn’t exist yet (which in most cases it shouldn’t) type in Terminal.

mkdir .MacOSX

Here we are creating a new directory called “.MacOSX” make sure to pay attention to capitalization since this is case sensitive. Type in Terminal.

touch .MacOSX/environment.plist

What has happened here is the creation of the “environment.plist” file that we need to setup our environment variable that contains the path information for our directories or reopositories. Type in Terminal.

open .MacOSX/environment.plist

Now we just open up our “environment.plist file” to add all the fun stuff we need. I would like to add that on my personal system when I went to open the “environment.plist” file Xcode tossed and error saying the file was corrupted. This was simple enough to work through and I’ll explain the work around. If you system didn’t toss up an error you can skip the next step and continue to setting up the plist file.

In Xcode go to file>New>File or command N. Click on the Resource selection on the left hand side from the pop up window. Select Property List. Now it’s going to prompt you to name the file right then and there. So in Terminal type.

open .MacOSX

This should pop up a new finder window with the .MacOSX directory open and we should be able to see the corrupt environment.plist file. Simply select the “environment.plist” file thats inside of the hidden directory that we can now see and drag it over the Save As window in Xcode. This will automatically set the path to the .MacOSX directory and should just name the file the name we already created. Press create and overwrite when the program asks the question.

With a new environment.plist file open in Xcode you should see something like this.

Environment Variables for Mac - Xcode pList

The document should be blank unless the environment.plist file already existed on the system before the beginning of this whole process. To setup the varialbe all we need to do is click on the + sign located on the root line. Just name the variable, in this case mine is called “ARTTOOLS” but it can be anything you want. In the value field add the drive or path information that you want to be contained in that variable. My value field is the path information to my google drive folder and looks something like /user/jredd/google drive/. Once you have the new variable named and it holds a value save the file. Now for the environment variable to take effect we need to logout of the account and log back in before Maya can take advantage of the environment variable we just set.

On a side note. If during the process of creating and setting up the “.MacOSX” folder or the “environment.plist” a wrong directory are document was created, like something was miss spelt or just plain wrong. You can always remove the newly created document by typing in Terminal.

rm nameToDelete

Integration with Maya and creating

Now that we can setup Environment Variables for Mac we can move onto getting things working in Maya. I implemented this by creating a document. I recomend typing and not just copying and pasting from the browser into the script editor. I have found that just byt typing out the code it helps with comprehension and memory.

import sys, os
import pymel.core as pmi
import maya.cmds as cmds


All we are doing here is importing Maya’s command modules for python to use and appending Maya’s paths list. In place where I have “ARTTOOLS” be sure to change that to whatever variable was created in the environment.plist document.

Now that we have finished our code we need to save our document. Unfortunately Maya for Mac doesn’t check the regular scripts folder that most users are use to putting tools and things into. To get Maya to load this file when it’s starting, we must place it in /Users/UserName/Library/Preferences/Autodesk/maya/scripts. If you notice the path has you going into the library folder contained in the root user directory. The problem is that the library folder is hidden in the user directory so we need to turn back to Terminal. Type in Terminal

open Library

This should open up a new finder window with the library folder, thats hidden, opened up for us. Now just follow the path /Users/UserName/Library/Preferences/Autodesk/maya/scripts and save the text document as in the scripts folder.

Now that the folder has been created let’s open up Maya to test it out. Once Maya is open, open up the script editor in Maya and type.
If a joint is created in the scene then the document is being read. Now to check to see if the path to the directory has been added to Maya’s paths. In Maya’s script editor type.

import sys, os

import maya.cmds as cmds

for path in sys.path: print path

This should print out all of the paths Maya looks at and if the link to the directory is located in that list then we have been successful in setting up an environment variable for Maya to use.

I hope this has been informative on how to setup Environment Variables for Mac. If there are any mistakes in this setup or questions please feel free to comment or email me. Cheers!