PDA

View Full Version : Import script as though it were a scenefile


marcuso
11-02-2010, 07:14 PM
Here I have a python script that imports a bunch of geometry and attaches the appropriate point cache to each one.

How would I go about if I wanted to make a .ma, or any other format maya would consider importing/opening, that performs the same action? Basically a self-contained scenefile, ready to perform this script in any scene.

import pymel.core as pm
import glob

mddDir = 'w:/somefolder/mdd/'
meshList = [['C:\\somefolder/mdd/meshes/object1.obj', 'object1'], ['C:\\somefolder/mdd/meshes/object2.obj', 'object2']]

fileList = glob.glob(mddDir+'*')

shotRange = [114.0, 349.0]
#pm.playbackOptions(min=shotRange[0], max=shotRange[1])
print "Using range: " + str(shotRange[0]) + "-" + str(shotRange[1])

if pm.objExists( 'cacheGroup' ):
cacheGroup = pm.ls('cacheGroup')
else:
cacheGroup = pm.group(n='cacheGroup')
for entry in meshList:
file = pm.importFile(entry[0], returnNewNodes=1)

mesh = pm.ls(file, tr=1)
pm.rename(mesh, entry[1])
pm.parent(mesh, cacheGroup)
pm.select(mesh)

pm.mel.eval('PO_ApplyReader')
reader = pm.ls('PO_Reader1')
newReader = pm.rename(reader, 'PO_reader_' + entry[1])

for file in fileList:
if file.find(entry[1]) != -1:
newReader.FilePath.set(file)

NaughtyNathan
11-02-2010, 08:16 PM
you would probably embed the code into a scriptNode and save that as a .ma scene file.
at least, that's how I'd do it.

:nathaN

marcuso
11-02-2010, 08:52 PM
Ah, how cool. I'll try it out. Thanks!

CGTalk Moderation
11-02-2010, 08:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.