Create Curve from Motion Path
# !/usr/bin/env python
# *********************************
# Anim to Curve
# author Keith Sheppard
# Apr 2016
# *******************************
import lx
import modo
import sys
def alwaysList(modoData):
if type(modoData) is list:
return modoData
elif type(modoData) is tuple:
return list(modoData)
elif type(modoData) is str:
return list([modoData, ])
elif type(modoData) is int:
return list([modoData, ])
def vertList():
vList = lx.eval('query layerservice verts ? selected')
if not vList:
vList = lx.eval('query layerservice verts ? all')
return vList
def vertPos(vert):
return lx.eval('query layerservice vert.wpos ? {%s}' % int(vert))
def vertAdd(xPos, yPos, zPos):
lx.eval('vert.new {%s} {%s} {%s}' % (xPos, yPos, zPos))
def CurrLayerIndex_get():
return lx.eval('!!query layerservice layer.index ? current')
#PreChecks
layerIndex = CurrLayerIndex_get()
if not layerIndex:
modo.dialogs.alert('Mesh Layer Detection','Please select a mesh and rerun AnimToCurve', dtype='info')
sys.exit()
vChk = alwaysList(vertList())
#leaving this here in case only for selected verts - need to change vertList()function above
if not vChk:
modo.dialogs.alert('Vert Selections','You need to select some verts rerun AnimToCurve', dtype='info')
sys.exit()
try:
lx.eval('!!time.step key last')
frame = lx.eval('select.time ?')
except:
modo.dialogs.alert('Mesh Not Animated','Please Animate the layer and rerun AnimToCurve', dtype='info')
sys.exit()
#Good to Go
masterList = []
for v in vChk:
lx.eval('!!time.step key first')
curveDrawList = []
while True:
vPos = alwaysList(vertPos(v))
curveDrawList.append(vPos)
if frame == lx.eval('select.time ?'): break
lx.eval('!!time.step key next')
masterList.append(curveDrawList)
lx.eval('item.create mesh')
lx.eval('item.name curveDraw')
for vPosList in masterList:
for vp in vPosList:
vertAdd(vp[0],vp[1],vp[2])
lx.eval('select.vertex add poly equal 0')
lx.eval('poly.makeCurveOpen')
#Done