Saori Yoshimoto work notes since 2018

Monday, August 25, 2025

MAYA to Houdini model export (alembic)

Thx for shearing MK!
 



# coding=utf-8

#-----------------------------------------------

#

#

#-----------------------------------------------


import pymel.core as pm

import os


def uiWindow_abcMayaToHoudini():

name = 'abcMayaToHoudini'

if pm.window(name, ex=True):

pm.deleteUI(name)

with pm.window(name,t=name, mnb=False, mxb=False, widthHeight=(200, 200)):

uiLayout()



def uiLayout():

scene = pm.Env().sceneName()

dir = scene.dirname()

print (dir)

sel = pm.ls(sl=1,long=1)

#root = []

#for i in sel:

# root.append("-root %s" % i.longName())

#rootJoin = u'%s' % " ".join(root)

pm.columnLayout(adj=True,rowSpacing=5,width=500,height=120)#pm.columnLayout(adj=True, rowSpacing=20)

pm.text('Out Path.')

#pm.text('startFrame / endFrame / marginFrame')


texB = pm.textField('textlog',text=dir, w=300, changeCommand='chVal()')

ckb = pm.checkBox('cbx',label="cameraBake", value=1, changeCommand='chVal()')

intg = pm.intFieldGrp('f3a', numberOfFields=4, label='sf/ ef/ addFront/ addBack', extraLabel=' Frame',v1=pm.Env().getMinTime(), v2= pm.Env().getMaxTime(), v3=30, v4=0, changeCommand='chVal()')


#pm.setParent('..')

#listA = pm.textScrollList('List',allowMultiSelection=True, append=(sel), selectItem=sel, showIndexedItem=8, height=120,selectCommand="chVal()")


pm.button(l='exportAlembic',c='mom_exprtABC()')


def chVal():

print (pm.textField('textlog', q=True, text=True))

print (pm.checkBox('cbx', q=True, value=True))

print (pm.intFieldGrp('f3a', q=True, v1=True))

print (pm.intFieldGrp('f3a', q=True, v2=True))

print (pm.intFieldGrp('f3a', q=True, v3=True))

print (pm.intFieldGrp('f3a', q=True, v4=True))

#print (pm.textScrollList('List', q=True, si=True))



def mom_exprtABC():

sf = pm.intFieldGrp('f3a', q=True, value1=True)

ef = pm.intFieldGrp('f3a', q=True, value2=True)

aff = pm.intFieldGrp('f3a', q=True, value3=True)

afb = pm.intFieldGrp('f3a', q=True, value4=True)

camBake = pm.checkBox('cbx', q=True, value=True)


scene = pm.Env().sceneName()

filePath = os.path.split(scene)

fileName = os.path.splitext(filePath[1])

sName = fileName[0].replace(".","_")


sel = pm.ls(sl=1)

#sel = list

aStart = sf - aff

aEnd = ef + afb

#print (sel[0])

pm.refresh(suspend=True)

for x in sel:

root = " -root %s" % x.longName()

name = x.name()

fileName = name.replace(":","_")

print (root)

command = "-frameRange " + str(aStart) + " " + str(aEnd) + " -uvWrite -worldSpace -writeVisibility -dataFormat ogawa" + root + " -file " + filePath[0] + "/" + sName + "_" + fileName + "_s" + str(aStart) + "e" + str(aEnd) + ".abc"

print (command)

pm.AbcExport ( j = command )


#bake cam

if camBake==True:

mom_action_makeBakeCam()


pm.refresh(suspend=False)


return sel



##back cam //////////////////////////////////////////

def mom_action_makeBakeCam():

sel = pm.ls(sl=1,long=1)


outItem = []

camList = []

for c in sel:

chid = pm.listRelatives(c, allDescendents=True)

print (chid)

for ii in chid:

#print (i.type())

if ii.type()== "camera":

print (ii)

camTrans = pm.listRelatives(ii, parent=True)

camList.append(camTrans[0])


#print (camList)

if camList!=0:

for x in camList:

outItem = mom_makeBakeCam(x)


return outItem



def mom_makeBakeCam(inputItem):


print ("\n")

selCam = inputItem

aff = pm.intFieldGrp('f3a', q=True, value3=True)

afb = pm.intFieldGrp('f3a', q=True, value4=True)

sf = pm.intFieldGrp('f3a', q=True, value1=True) - aff

ef = pm.intFieldGrp('f3a', q=True, value2=True) + afb


# scenePath = pm.Env().sceneName()

# filePath = os.path.split(scenePath)

# fileName = os.path.splitext(filePath[1])

# sName = fileName[0].replace(".","_")



path = pm.Env().sceneName()

fn = os.path.splitext(os.path.basename(path))[0]

fnd = fn.replace(".","_")

fnu = fnd.replace("-","_")

print (fnu)


if selCam:

shapes = pm.listRelatives(selCam.name(), shapes=True)

if shapes:

selCamShape = shapes[0]


##make camera

nCam = pm.camera()

pm.rename(nCam[0].name(), fnu + "_" + selCam.name() + "_Bake" + "_s" + str(int(sf)) + "e" + str(int(ef)))

#pm.rename(nCam[0].name(), fnu + "_" + selCam.name() + "_s" + str(int(sf)) + "e" + str(int(ef)))

print ("//mom// select camera [%s]. make camera [%s]." % ( selCam.name(), nCam[0].name()))


##create constraint.

pc = pm.pointConstraint( selCam.name(), nCam[0].name(), offset=(0,0,0), weight=1 )

oc = pm.orientConstraint( selCam.name(), nCam[0].name(), offset=(0,0,0), weight=1 )

sc = pm.scaleConstraint( selCam.name(), nCam[0].name(), offset=(1,1,1), weight=1)

print ("//mom// set constraint [%s] to [%s]. \n//mom// [%s].\n//mom// [%s].\n//mom// [%s]" %(selCam.name(), nCam[0].name(), pc, oc, sc))


##much camera atter list.

attrCamList = []

attrCamList.append("horizontalFilmAperture")

attrCamList.append("verticalFilmAperture")

attrCamList.append("focalLength")

attrCamList.append("lensSqueezeRatio")

attrCamList.append("fStop")

attrCamList.append("focusDistance")

attrCamList.append("shutterAngle")

attrCamList.append("shutterAngle")

attrCamList.append("centerOfInterest")

##set camera attr

for i in attrCamList:

mVal = cmds.getAttr(selCamShape + "." + i)

keyNum = pm.keyframe( selCamShape +'.' + i, query=True, keyframeCount=True )

pm.setAttr( (nCam[1] + "." + i), mVal)

#pm.setKeyframe(nCam[1], t=sf, at=mVal)

#key copy

if keyNum != 0:

pm.copyKey(selCamShape,attribute=i)

pm.pasteKey(nCam[1],attribute=i)

print ("//mom// set key [%s.%s]" % (nCam[1], i))

else:

pm.setAttr( (nCam[1] + "." + i), mVal)

print ("//mom// set value [%s.%s] = %s" % (nCam[1], i, str(mVal)))



##bake prosses

#veiwport lock

pm.refresh(suspend=True)

pm.bakeResults( nCam[0], t=(sf,ef), simulation=True)

#pm.bakeResults( nCam[0], t=(sf,ef), minimizeRotation=False, simulation=True)

pm.filterCurve( '%s_rotateX' % nCam[0].name(), '%s_rotateY' % nCam[0].name(), '%s_rotateZ' % nCam[0].name(),)

#pm.bakeResults( nCam[0], t=(sf,ef), simulation=True)

#veiwport unlock

print ("//mom// full bake key [%s] and [%s]" % (nCam[0],nCam[1]))


##remove constreint

pm.delete(pm.listRelatives(nCam[0],typ="constraint"))

print ("//mom// remove constraint [%s]" % (nCam[0]))

#export cam

scene = pm.Env().sceneName()

dir = scene.dirname()

root = " -root %s" % nCam[0].longName()

name = nCam[0].name()

fileName = name.replace(":","_")


print (root)

command = "-frameRange " + str(sf) + " " + str(ef) + " -uvWrite -worldSpace -writeVisibility -dataFormat ogawa" + root + " -file " + dir + "/" + fileName + ".abc"

#command = "-frameRange " + str(sf) + " " + str(ef) + " -uvWrite -worldSpace -writeVisibility -dataFormat ogawa" + root + " -file " + dir + "/" + fileName + "_s" + str(sf) + "e" + str(ef) + ".abc"

print ("print (command " + command)

pm.AbcExport ( j = command )

pm.refresh(suspend=False)


print ("//mom// return [%s]" % str(nCam))

return nCam



uiWindow_abcMayaToHoudini()

No comments:

Post a Comment