Categories
scripting softimage

XSI SDK: Picking forever with Python YIELD

What’s the smart way to pick any arbitrary number of items with XSI’s PickElement or PickObject commands? Read below… 😀

si = Application

def pickForever(**kwargs):
    '''
    Pick forever, and ever, and ever, and ever...
    until you rightclick.
    '''

    # Default options
    leftMessage = kwargs.setdefault('leftMsg', 'Pick something')
    middleMessage = kwargs.setdefault('middleMsg', leftMessage)
    selFilter = kwargs.setdefault('selFilter', 'object')

    # Loop and yield forever until complete:
    while 1:
        out = si.PickElement(selFilter, leftMessage, middleMessage)
        obj = out("PickedElement")
        buttonPressed = out("ButtonPressed")
        modifier = out("ModifierPressed")

        if obj:
            yield obj, buttonPressed, modifier
        else:
            break


# _______________________________________
# USAGE EXAMPLES:

def processIndividually():
    '''
    Deal with each pick, one object at a time...
    '''
    for obj, button, modifier in pickForever(leftMsg='Pick Object', selFilter='polygonmesh'):
        button = ['left','middle'][button-1]
        # (-1 because 0 means right, but is never returned.)
        si.LogMessage( "Picked %s with your %s mouse button!" % (obj.FullName, button) )


def listExample():
    '''
    Getting a list of picked objects, only after picking is complete...
    '''
    pickedObjects = zip(*list( pickForever(leftMsg='Pick Object') ))[0]
    si.LogMessage( pickedObjects )


# Cool, eh? :)
Categories
scripting softimage tutorials

How to read an XSIADDON file in Python

Ever wondered what’s the deal with *.xsiaddon files? What are they?

Well, they’re good ol’ XML with a bit of metadata and the files embedded in them are compressed with the zlib library and base64 encoded for safe plaintext storage.

How would we parse such a file? Check this out:

Categories
scripting softimage

Python: Naming Objects for Numerophobes 101

You can call me a numerophobe when naming rig objects, but the reason I personally avoid numbers in my rigging naming conventions (99% of the time) is so that when I duplicate something, a number at the end won’t increase by itself because there isn’t one. (The issue can be circumvented by having numbers somewhere before the end, but I’m the kind of weirdo that prefers to go with letters altogether.)

We humans work numbers in what’s known as the “Numeral system“, also known as the “base 10” system (as we have that many fingers…) but hold on… the alphabet has 26 letters, not 10, so what do we call that system? It has a name: it’s the Hexavigesimal (or “base 26”) system.

As the ever-so-handy Wikipedia denotes,

Any number may be converted to base-26 by repeatedly dividing the number by 26.

Pretty easy stuff for Python.

This is how I’d do it:

Categories
softimage tutorials

Softimage: ICE String to Particles trick

[I shared this on the Softimage Mailing List the other day and thought it was worth posting here.]

Here’s a fun trick for parsing an ICE string attribute, identifying the letters and typing out the text with particles:
ICE string to particles
Download the sample scene here and read more about it below. (Soft 2011+ required.)

Categories
softimage tutorials

Softimage: Symmetrical Shape Splitting with ICE

I propose a way of using ICE to split symmetrical shape halves. Here it is in action:
My
(Download here and read more about it below.)

Categories
scripting softimage

Python: Distance between 2 Position Vectors

This post surged from a question at a forum where somebody tried to use the ctr_dist() function — that returns distance between two object centers — in a Softimage script only to realise that actually it only exists for expressions, not scripting.

Here’s my take on said function for both Softimage and Maya…

Categories
softimage

Softimage: Undocumented TEMP Folder that cleans up after itself

Environment variables are no secret and neither is the system-set “TEMP” variable, but what is not really mentioned in the SDK Docs is that Softimage overrides the TEMP and TMP environment variables with a temporary folder made by XSI:

LogMessage( XSIUtils.Environment("TEMP") );

If I run that (JavaScript) I get something like: C:\Users\Alan\AppData\Local\Temp\XSI_Temp_15076

Categories
softimage

Softimage: RefModel Deltas’ Hygiene in Production

I used to think refmodels were buggy, annoying and out to get me. After some exploration, they exhibit a couple patterns of fixable issues. Let’s bring them to light, shall we?

Here’s some of my observations with them in the context of artists animating a referenced rig in production:

Categories
softimage

Softimage: Automatic Symmetry Mapping Template

If you do rigging in Softimage you probably know when trying to Mirror Weights it only pays attention to the last created Symmetry Mapping Template for that model. There’s no interface to append to or join mapping templates. It gets annoying having to recreate them and verify that Soft guessed all the correct symmetrical equivalents, so…

Categories
softimage

Rendertree Compound: Shadow AO

Ever noticed that Ambient Occlusion doesn’t happen in the real world in lit areas? It’s more of a darkness thing… so why apply it everywhere?

With this Rendertree compound you have AO in darkness and that’s it. Simple! 🙂
Notice how there's no AO in lit areas

Shadow AO compound