Website Update & First PyMel script

My *splutter* lovely *ahem* face sits on the left side now, I’m not a narcissist I promise. I updated a lot since I put it live, I’m pretty happy with the way it’s going, if this was proper software development I’d say I’ve reached beta. I know that I need to add more content, this is my first text post in a little while, I’ve been having fun just fiddling with how the site works. If you’re interested in how WordPress is working for me, I love it! Plenty of plugin support and on the off chance I don’t find something I’m after, the code is documented well so it’s easy to build on existing functionality. I’m understanding why WordPress is one of the biggest CMS’.

The biggest update: I restructured the way that my art is displayed, it’s as a post type instead of a random page of images. I was originally updating them manually but now I’ve got galleries in place, thanks nivoBox (lightbox) & jetpack! I did some work in PHP, HTML & CSS to format the way posts appear in the Artwork page which looks pretty damn snazzy now if I do say so myself.

I do have one complaint that my images seem to be heavily compressed. I did some research and it may be a WordPress function doing it, I was pretty sure it only happened when I connected jetpack but not 100% about that. I’ll try my best to fix that soon as well.

In other news, I got setup in Maya for some Pymel scripting! I was originally just doing straight python, but from an OOP standpoint Maya’s python is alien and non-intuitive to me. Pymel has some overhead but I think clear readable code is important too, if I wanted the best performance I’d be writing a C++ plugin, it seems to be quick enough for most operations any way (feels faster than Maxscript? I’m probably imagining it).

To get myself up to scratch I wrote a small Maya script that centers & bottoms out the pivot pretty simple!

There are a few sections that I found a little interesting. Of course the imports, it was my first time working with Maya’s xform finding it in Pymel was a breeze, it’s straight up Transform in this case. Now as for the structure, Python is a mostly new language for me as I’ve only studied it a little bit & I wanted to mess around with the native language a little bit so of course I defined a function for a single task. Python seems to be coming from a C++ angle in the sense that hoisting things that aren’t defined yet gets a bit broken, while I was making this I didn’t realise this though because I was calling then defining like in JavaScript. Weirdly enough the Python interpreter didn’t produce any runtime errors at first but it produced weird and inconsistent results confusing me for a short while, soon enough runtime errors came in thick and fast and soon it was impossible to run certain Maya cmds. So I restarted Maya, restructured it and haven’t had an issue since. That’s one to watch for though.

For the code itself it’s pretty simple, the main loop iterates through all the objects the user has selected and identifies if it meets the type ‘transform’, if so it’ll trigger the cntrBtm() function. There’s a big reason for the loop itself, of course the user may not have selected a transform so the script will throw a Python error, in the same vein I first noticed this when I created an object. In Maya when you select and existing object you will by default grab the transform, when creating an object the transform isn’t the selected object which threw me for a loop for a moment (excuse the pun). In the function, we have a pvt variable being declared as the result of getBoundingBoxInvisible(ws=True) which returns a list of the bounding box’s limits. For example, if we draw a 1 meter3 cube, centered on world 0, then getBoundingBoxInvisible(ws=True) would return -0.5m, -0.5m, -0.5m, 0.5m, 0.5m 0.5m. The results are ordered as xmin, ymin, zmin, xmax, ymax, zmax, Maya’s height is measured along the Y axis so ymin will give us the lowest point of the mesh.

The variable xyz does something similar, it returns a list of co-ordinates for the current rotatePivot (rotate pivot is shared with the translate). Python is a 0+ index language which means that we count lists starting at zero. 0 = milk, 1 = sugar, 2 = eggs… So all we have to do now is change the xyz variable so that it’s second item ‘xyz[1]’ is equal to the ymin value which also happens to be at ‘pvt[1]’. Done! Just throw that into a setPivots command.

As far as scripts go this one was pretty tame but was really fun to get started with PyMel so I’ll be working on more in the future.

Side note: I just realised my favicon (image in the tab) looks like a jellyfish instead of the letters 3D, jelly fish are cool so it’s a happy accident.

The last executed function I used in my script was wrong. It reset the transform when it shouldn’t have, I must admit that coming over from Max I’m still getting used to Maya, though I should have caught this sooner as it works pretty much the same way. I could probably just query the pivot position too instead of reaching for transforms, but it was a good dive into that area at least. It works across all selected objects same as before.


One thought on “Website Update & First PyMel script”

Leave a Reply

Your email address will not be published. Required fields are marked *