Andy Moorer is a VFX artist and TD working in the film industry.
Jan
16

Minor Pipeline Tools – Logging Distance

By

There is an awesome thread on the softimage list where the small pipeline enhancements softimage users tend to accumulate in their personal collections are being discussed. In it I vowed to share mine to the community as a whole over time on this blog. So here’s the first one… a little python script I keep in a custom menu, which writes a log (as an anotation in the explorer) of distances between objects.

File (<1kb): LogDistances.py

#—————————————-
# Log Distances between 2 objects
# 2011 A Moorer
#—————————————-
xsi = Application
xsiRoot = xsi.ActiveSceneRoot
lm = xsi.LogMessage
root = xsi.ActiveSceneRoot

def SelectionCheck():
sel = xsi.Selection
if sel.Count <= 1:
lm(“Select two objects.”,4)
return False
if sel.Count >= 3:
lm(“More than two objects selected.”,4)
return False

else:
lm(“\nLog Distance\n————————”,32)
return True

#————————
#Distance Between Centers

def ctr_dist( objA, objB ):
from math import sqrt,pow
# Thx to Alan F for this function

Ax, Ay, Az = objA.Kinematics.Global.Transform.GetTranslationValues2()
Bx, By, Bz = objB.Kinematics.Global.Transform.GetTranslationValues2()

return sqrt( pow(Ax-Bx,2) + pow(Ay-By,2) + pow(Az-Bz,2) )

#———————–

#Annotate Distance

def annotate( nDist ):
if xsi.ClassName(root.Properties["MeasuredDistances"]):
prevText = xsi.getValue(str(root.Properties["MeasuredDistances"])+”.text”)
lm(“Logging new distance measurement…\n”,32)
xsi.SetValue(str(root.Properties["MeasuredDistances"])+”.text”, str(prevText)+nDist, “”)

else:
oSet = root.AddProperty(“Annotation”,0,”MeasuredDistances”)
lm(“Annotation Created.\n”,32)
xsi.SetValue(str(oSet)+”.text”, “Distance Measurement Log\r”+”\r ————————————-\n\r” + nDist, “”)

return

#———————–

#Log Distance

def LogDist():
try:
if SelectionCheck():
fromObj, toObj = xsi.Selection(0), xsi.Selection(1)

newDist = “\r\nDistance between <”+fromObj.FullName+”> to <”+toObj.FullName+”> is: ” +str( ctr_dist(fromObj, toObj))
lm(newDist+”\n\n————————\n”,32)
annotate(newDist)

except:
lm (“\n——-\nDistance Script Error.”,4)
return True

#—————————————-
#Call the function -
LogDist()

There you go… I hope it proves helpful to some of you. :)

I considered sharing my personal workgroup in it’s entirety, but there’s a lot of trash in there I wouldn’t want to burden people with, plus a considerable amount of stuff which Isn’t mine to share. So until I make a “clean” workgroup I’ll just have to post bits and pieces…

Categories : 3D Graphics, Examples

Comments are closed.

Andy Moorer

Copyright © 2010 All Rights Reserved