Tag Archives: Python

featuredImg_BestRenderScript

BestRenderSequence script

As I was rendering my last animation, I thought it would be better if the renderer shot the most distant frames instead of the closest. In a sequence from 1 to 15, for instance, it wouldn’t render 1, 2, 3, 4… but 1, 15, 8, 4… always getting the middle frames.

I took it as a challenge with a friend, and finally got it working in python ::

# Best Render Sequence
# by Ed Schiffer
# www.edschiffer.com
 
def bestRenderSeq(inN, outN):
    inN, outN   = int(inN), int(outN)
    sortedSeq   = [inN, outN]
    finalSeq    = [inN, outN]
    tempList    = []
 
    while len(finalSeq) != (outN -inN +1):
        for item in sortedSeq:
            if sortedSeq.index(item) != 0:
                count = sortedSeq.index(item) 
                tempN = (sortedSeq[count] +sortedSeq[count -1]) /2
                tempList.append(tempN)
        for item in tempList:
            if item not in finalSeq:
                finalSeq.append(item)
                sortedSeq.append(item)
                sortedSeq.sort()
                tempList = []
    print "best render sequence: %s" %finalSeq
 
bestRenderSeq(10,30)
featureImg_firstScript

my first real script

I didn’t do programming, and actually one year ago I didn’t even know what a ‘string’ was. But I’ve been using a little bit of python to automate tasks within Softimage. It’s still challenging, but excited too. Now I feel like I was living in a foreign country without knowing it’s language…

So,  here’s my first script. It’s dumb, but for me it’s very useful: it places a null as a parent of the selected objects, respecting the rest of the hierarchy; and if you hold down Ctrl, Alt or Shift, it places the null as a child…

download: ed_AddNullAsRelative.pys

#Add Null as Relative
#by Ed Schiffer
#edschiffer@gmail.com
 
#variables
xsi = Application
oRoot = xsi.ActiveSceneRoot
sel = xsi.Selection
ks = xsi.GetKeyboardState()
 
for obj in sel:
	#if Ctrl, Alt or Shift is pressed, add a null as child:
	if ks(1) >= 1:
		oNull = oRoot.AddNull(obj.Name +"_child")
		xsi.MatchTransform(oNull, obj, "siSRT", "")
		xsi.ParentObj(obj, oNull)
	#else, add it as parent:
	else:
		oNull = oRoot.AddNull(obj.Name +"_root")
		oParent = obj.Parent
		xsi.MatchTransform(oNull, obj, "siSRT", "")
		xsi.ParentObj(oParent, oNull)
		xsi.ParentObj(oNull, obj)

Just drag&drop it under Softimage’s Script Editor.

Even for the simplest rig, like a rock, I find myself always putting an extra parent object for the animation controller, so it can be constrained at a higher level and the controller is still free to animate…