.OBJ sequence importer for Maya

Hey there.
I’m aware that many artists don’t use OBJ sequences any more.
But now and then this may come in handy. Which happened to me.
And odd enough Maya doesn’t allow to import obj sequences. i used
it some years ago in max and it worked quite nicely.

So i took the time to write a python script for it. With a little help
from my Buddy John P. Neumann aka Arrantsquid here it is.

Hope it will help you. If not, you can still learn a bit from the code :)

Cheers

import maya.cmds as cmds

current_scene=cmds.ls(assemblies=True)

def selectDir():
	basicFilter = "*.obj"
	filename=cmds.fileDialog2(fileMode=4,ds=1, caption="Select Sequence",fileFilter=basicFilter)
	uniToStr=str(filename)
	global objList
	filePath=uniToStr.split("'")
	search=".obj"
	objList=[mesh for mesh in filePath if search in mesh]
	cmds.textScrollList(path, edit=True, append=objList)

def importer():
	objList.sort()
	for each in objList:
		loaded=cmds.file(each,i=True,dns=True)
	cmds.deleteUI('objwindow',window=True)
	getMeshes()

def loadWin():
	if cmds.window('objwindow',exists=True):
		cmds.deleteUI('objwindow',window=True)
	win=cmds.window('objwindow',title="Load Obj sequence",widthHeight=(250,450))
	cmds.columnLayout()
	cmds.text('Path to files')
	global path
	path=cmds.textScrollList(w=250)
	browseButton=cmds.button(label='browse',w=250,c='selectDir()')
	importButton=cmds.button(label='import',w=250,c='importer()')
	cmds.showWindow(win)

def getMeshes():
	newScene=cmds.ls(assemblies=True)
	meshList=[mesh for mesh in newScene if mesh not in current_scene]
	cmds.group(meshList,n="OBJ_GROUP")
	for i in range(len(meshList)):
		cmds.setKeyframe(meshList[i],attribute='visibility',value=0,t=0)
		cmds.setKeyframe(meshList[i],attribute='visibility',value=1,t=i+1)
		cmds.setKeyframe(meshList[i],attribute='visibility',value=0,t=i+2)

loadWin()
About these ads

15 thoughts on “.OBJ sequence importer for Maya

  1. Your script works really well. Thanks!

    I’m not sure exactly how to express it in Maya terms, but if you wanted to render the sequence, right now you would have to apply materials to every frame. It would be much more convenient to just set it once and have it applied everywhere.

    Do you know how to do this?

  2. Hi Ricardo,
    Thanks a lot for your script.
    I needed an STL sequence importer so I used yours as a base and changed a couple lines. It is basically yours but with a few changes so the visibility animation works properly with STL files.
    Still some cleanup to do but works.
    Would you like it to be shared here?
    Cheers

    • Hi Bill and Mayapy
      Probably way too late, but an STL sequence importer would be a huge help for me. I am trying to develop a pipeline for bringing in molecular dynamics visualizations calculated in NAMD into Maya. The .obj format has the limitation of bringing in the molecule as a single mesh, where .STL keeps atoms as separate objects which provides a lot of flexibility for designing the final render style.

      I am not a python wiz, so if anyone could provide an .stl modification of this otherwise perfect sequence importer…I would be so very grateful!

      drew berry

  3. Hello. My obj sequence is accompanied by a texture *.jpg sequence (each obj has a corresponding unique jpg). How would I load these textures and apply them to obj’s using your script?

    Thank you.

      • here it is.
        It creates a Shader common to all geometry. Then you just have to go to the shader and insert the image sequence in the file node.(check image image sequence in parameters).
        hope it helps
        cheers

        
        import maya.cmds as cmds
        
        current_scene=cmds.ls(assemblies=True)
        
        #shader creation - if u want can change from lambert to blinn or phong.
        
        shader=cmds.shadingNode("lambert",asShader=True,name='ObjectShader')
        
        #-------------------------  ^  change above if desire -------------------------
        
        file_node=cmds.shadingNode("file",asTexture=True)
        
        shading_group= cmds.sets(renderable=True,noSurfaceShader=True,empty=True)
        
        cmds.connectAttr('%s.outColor' %shader ,'%s.surfaceShader' %shading_group)
        
        cmds.connectAttr('%s.outColor' %file_node, '%s.color' %shader)
        
        #-------------------------------------------------------------------------
        
        def selectDir():
        	basicFilter = "*.obj"
        	filename=cmds.fileDialog2(fileMode=4,ds=1, caption="Select Sequence",fileFilter=basicFilter)
        	uniToStr=str(filename)
        	global objList
        	filePath=uniToStr.split("'")
        	search=".obj"
        	objList=[mesh for mesh in filePath if search in mesh]
        	cmds.textScrollList(path, edit=True, append=objList)
        
        def importer():
        	objList.sort()
        	for each in objList:
        		loaded=cmds.file(each,i=True,dns=True)
        		
        	cmds.deleteUI('objwindow',window=True)
        	getMeshes()
        
        def loadWin():
        	if cmds.window('objwindow',exists=True):
        		cmds.deleteUI('objwindow',window=True)
        	win=cmds.window('objwindow',title="Load Obj sequence",widthHeight=(250,450))
        	cmds.columnLayout()
        	cmds.text('Path to files')
        	global path
        	path=cmds.textScrollList(w=250)
        	browseButton=cmds.button(label='browse',w=250,c='selectDir()')
        	importButton=cmds.button(label='import',w=250,c='importer()')
        	cmds.showWindow(win)
        
        def getMeshes():
        	newScene=cmds.ls(assemblies=True)
        	meshList=[mesh for mesh in newScene if mesh not in current_scene]
        	cmds.group(meshList,n="OBJ_GROUP")
        	for i in range(len(meshList)):
        		cmds.sets(meshList[i],e=True,fe=shading_group)
        		cmds.setKeyframe(meshList[i],attribute='visibility',value=0,t=0)
        		cmds.setKeyframe(meshList[i],attribute='visibility',value=1,t=i+1)
        		cmds.setKeyframe(meshList[i],attribute='visibility',value=0,t=i+2)
        
        loadWin()
        
        

  4. hi ,

    i want to use ur script but iam getting this error :

    // Error: current_scene=cmds.ls(assemblies=True)
    //
    // Error: Syntax error //

    can u plz tel me what iam doing wrong :(

    • Hi Nitish.
      do you have > import maya.cmds as cmds
      in the beginning?

      If not it will not work. you have to paste the whole code
      into your script editor.

      If you don’t import the maya cmds. cmds wont work. check also if you are in the mel tab instead of the python tab.

      cheers
      R.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s