Thanks @Dave Finch for this great example! This is my favorite of all the Minecraft scripts out there already. I’ve update this great tool with a little more Python fancy schmanciness. Made it object oriented and added some functionality with the idea of upgrading the algorithm to generate the maze, make it 3D, and add some funkiness. Stay tuned!
Say you have an environment variable named PYROOT with a lis of a few paths where python libs are stored. Use python’s site module to add your lib directories as site directories like this:
import os import site PYTHONPATHS =  if os.environ.has_key('PYROOT'): if os.pathsep in os.environ.get('PYROOT'): for p in str.split(os.environ.get('PYROOT'), os.pathsep): PYTHONPATHS.append(p) else: PYTHONPATHS.append(os.environ.get('PYROOT')) if len(PYTHONPATHS): for j in PYTHONPATHS: site.addsitedir(j)
This quick script works cross-platform using os.pathsep to test for environment variable separators ‘;’ (win) and ‘:’ (linux) and using that to split the PYROOT string variable appending each of the paths to the PYTHONPATHS buffer list. By using the site.addsitedir module, python will treat these directories as normal site-package directories with all the built-in abilities to customize such as sitecustomize module and .pth files. If subdirectories are already organized into packages using __init__.py then they are already ready to be used and imported into Maya right away, or else if the directory has a .py file and no __init__.py just add an empty one.
To add your custom user site-packages directory just append the lines of code or create a new userSetup.py and make sure it is on your PYTHONPATH when you start up, previously explained here, or just put it in any one of the default maya scripts areas.
It’s been long enough. The intention to get back to blogging, probably the most enriching things that the internet can be used for, is not as easy as it the benefit would lead one to believe. It is often the hardest these sort of things in life that have the greatest benefit that go without being utilized, but that changes now with the mother of all instigators, New Years Day.
What’s the topic of the year that is a continuation and solidification of growing interest in the previous year? What else, the ubiquitous topic across the blog-o-sphere; filtering, utilizing and leveraging the mind-numbingly viral growth of open source hardware and software, DIY, Hacktivism, Public Domain, and Creative Commons information to engage in gratuitous amounts of geekery, life/career hacking.
Expect expositions in 2012 on topics in addition to the aforementioned and the regular posts on 3d animation and tech art ranging in this list of interests:
Use of hobby as a way of making money
Hopefully shedding some light on some of the fundamentals will blaze trails for others that are interested to get started in the most noble of activities of the modern era, one that is being affected by movements like SOPA; developing and sharing software and media and artist entrepreneurialism.
What do you do when you screw up and delete all your history and input code in Maya script editor usually do to a right-click muscle memory FAIL? First of all, DON’T close Maya! Navigate to your prefs directory, depending on the system you’re using that is in different locations, and then open up the handy little mel file called “commandExecuter”, and that file name may have a hyphen and some numbers behind it depending on how many tabs you have going. Open the corresponding file based on the tab you mistakenly erased in notepad or favorite text editor and then copy the contents back into your script editor.
This won’t get you everything back however, sad, I know, but if you can get back to where you were before the melt-down without too much hassle this way then that’s better than nothing. That’s why I like using external IDE’s for longer coding sessions and the script editor for little things that make my life easier in the particular scene I’m working on.
setuptools – You should have setuptools installed.
pip – If you have setuptools and/or use easy_install switch to pip by using easy_install to download and install pip, you won’t be sorry. Pip is awesome, setuptools sux.
pyWin32 – Use pip to download pyWin32 from the commandline using pip install pyWin32. Copy the installation to your Maya site-packages folder including any .pth, .txt, or .egg-info files. Tip: open .pth files in a text editor of choice and check out where pip’s libs are.
''' based on mel script found here: http://bit.ly/e4qdyH ''' import win32clipboard def getClipboardData(): win32clipboard.OpenClipboard() d = win32clipboard.GetClipboardData( win32clipboard.CF_TEXT ) win32clipboard.CloseClipboard() return d getClipboardData() def putClipboardData(text): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText( text ) win32clipboard.CloseClipboard() t= 'test text' putClipboardData(t)
This is based on what I found on teacup’s techy art stuff, written a while ago. I though it deserved an update, plus I needed it for something specific. It is a really handy module to have in your repertoire. I posted these in a hurry so you probably need to add in some checks to make sure the datatype you are trying to retrieve is text only or else you’ll get errors.
PyQt and Qt obviously are way more powerful for getting other types of data including pixmap and slew of others. This is simplified for a specific purpose. Maybe soon I will be able to post a Qt version including drag and drop functionality.
Here’s a handy little script you can run in Maya script editor to see a list of CG jobs with corresponding salaries. Obviously, this is kind of a joke because of some of the figures, but it’s still a pretty cool example of using urllib2 module.
VFXWages is a global database of hourly monetary rates of people in the film and television visual effects, animation, motion graphics, and gaming industry. It allows you to see where you rate among the rest of the artists in your experience, occupation and location. Have you ever wondered if you’re earning too little? Pondering what a similar artist in your position is making on the other side of the world? Using our Wages system, you can graphically compare wages and salaries around the world. -via VFXWages.com
Run this from Maya’s script editor, or whatever. Shared by my colleague Mike. It’s kinda neat but sometimes you wonder if this information is real! $100/hr for Anim Sup or Vfx Sup?!
I’m just starting to code seriously in python and it seems like just getting everything to work right in Maya without a lot of fuss is pretty daunting for a beginner with little outside help except for the internet and a couple books.
As my Script Repo develops over time, I don’t want to have to keep worrying about PYTHONPATH having everything in it so I tell it where the root directories are and this script does the rest.
Hope somebody finds this helpful!
import sys from os import walk path = ja_python_paths for p in path: for root, dirs, files in walk(p): if p is not root: sys.path.append(root) #You can add an optional print statement at the end #to see what it's doing... if p is not root: print 'adding', root, 'to sys.path' sys.path.append(root)
Lately, I’ve been working on learning how to develop PyQt UI tools with Maya. Since I work with Maya 2009 daily, I have had to do quite a lot of digging to find out how things were implemented smoothly for it to work with that version. Hopefully, this makes it easier to understand and appreciate it in 2011 and *gasp* :-O 2012, where PyQt is fully integrated! Anyway, if you are in the same predicament, then I should be able to help, send comments and emails my way.
For the Advanced user:
Delving into what how userSetup files work can be tedious. That’s why i’m posting how to configure Maya properly for those people who are perpetually scratching their heads, trying to figure out what way is better or why things aren’t working out like they planned. Check out my previous post on userSetup and see if you are pondering things after reading all of that. Of course, i’ve learned some things about the process too since then because my startup process is a lot more complicated than sourcing a couple of tools. I’m setting up whole programming environments! Learning Maya startup configuration has been a process of trial and error, searching and finding or sometimes not finding. Here’s the beef. Maya loads script paths in a specific order. Once you learn that order, the daunting task of setting configurations for a whole studio is as simple as pie. I work at a smaller studio, so the process of discovery falls on my shoulders and so I had to rise to the challenge.
Case Study: Finding the Solution to a Problem with userSetup.py
So where do you find the source code to decipher what’s really going on when Maya starts up? After finding this relic of a thread online, It crystallized one piece of the puzzle. I was having the hardest time figuring out why PYTHONPATH wasn’t working for all my scripts. After all, I was pointing it to find my userSetup.py and also my Maya2011 python\libs\site-packages directory so I can have access to all my downloaded modules yet my PyQt modules were failing to import while my userSetup modules were sourcing just fine.
Here's the order of how Maya finds scripts for python taken from the post linked above, which is directly from module: maya.app.startup.basic Per-version prefs scripts dir (eg .../maya8.5/prefs/scripts) Per-version scripts dir (eg .../maya8.5/scripts) User application dir (eg .../maya/scripts) Look for userSetup.py in the search path and execute it in the "__main__" namespace Set up sys.path to include Maya-specific user script directories. Set up auto-load stubs for Maya commands implemented in libraries which are not yet loaded Run the user's userSetup.py if it exists Register code to be run on exit
I started to get inspired to start writing documentation again for my script repository yesterday and the brilliance quickly became marred by the thought of how daunting that task can become. It’s a necessary part of the process though and starting somewhere is unavoidable at this point since the organization of the repo is quickly growing beyond what a directory structured system can handle. Documentation is increasingly hard to dig up and it’s much nicer for the tools to be indexed all in one place in a textual and graphical format, even adding tutorial vids for workflows being used when using specific tools or a tool set. I know html is the solution for many of this but how cumbersome it is to use.
In comes TiddlyWiki onto the scene again after having been distracted for a while and not concerning myself with writing help files since I have been busy. I felt motivated again after having read Morgan Loomis’ blog post and seeing his small but effective wiki used for this very purpose. Morgan has links to Scienceoss.com where another useful Python script will create tiddlers for your wiki automatically. Wow, it works great from the command-line but also from inside Maya 2009 which i’m using for rigging stuff. Now if I write a script in Maya I can use this tidder script to automatically update my script repo help wiki thus cutting down the time i’m working inside the wiki editor. Amazing and helpful and it even supports images and resizing images!
Example tidder creation script:
import sys sys.path.append('N:\Scripts\Python') from addtiddler import addtiddler addtiddler('N:\Scripts\Help\script_repo_help.html', image='images/asaro_head.jpg', description='test image', tags='images', author='JA', title='Asaro Head', resize=True, replace=True)