Ronald Fong Obj Sequence to Maya MEL

Obj Sequence to Maya

A quick and dirty way to load an .obj sequence in Maya and have each geometry’s visibility automatically keyed to show up at the frame they are supposed to show up. Wrote this script as an experiment, but don’t have time to make a UI, so I just commented on the two variables to change accordingly to your setup. Cheers!

Update [10 Feb 2020]: Made sure the import command explicitly points to the specified folder directory (Thanks Cody for pointing out that the script didn’t work for you!)

global proc rf_objSeqImport() {
string $folder = "C:/objImport/"; //Change the folder directory to the folder containing your .obj sequence
string $mesh = "Mesh"; //Change the word 'Mesh' to the name of the geometry that would be imported

string $objFiles[] = `getFileList -folder $folder -filespec "*.obj"`;
int $i = 0;
while ((size($objFiles[$i])) > 0){
    print ("Importing " + $objFiles[$i] + "... \n");
    file -import -type "OBJ"  -ignoreVersion -ra true -mergeNamespacesOnClash false -namespace ("objImport" + $i) -options "mo=1"  -pr  -importTimeRange "combine" ($folder + $objFiles[$i]);
    currentTime ($i+1) ; //visible on frame
    setAttr ("objImport" + $i + ":" + $mesh + ".visibility") 1;
    setKeyframe ("objImport" + $i + ":" + $mesh + ".v");
    
    currentTime $i ; //invisible before frame
    setAttr ("objImport" + $i + ":" + $mesh + ".visibility") 0;
    setKeyframe ("objImport" + $i + ":" + $mesh + ".v");
    
    currentTime ($i+2) ; //invisible after frame
    setAttr ("objImport" + $i + ":" + $mesh + ".visibility") 0; 
    setKeyframe ("objImport" + $i + ":" + $mesh + ".v");

    $i++;
};
}

rf_objSeqImport();
2 replies
  1. Cody Lukas
    Cody Lukas says:

    I tried running this and got the error code “// Error: line 7: File not found.”
    I changed the top 2 lines of code to access the folder with all the obj files and the name of the files. I am not sure as to which file it is referring to on line 7.

    Is there anything else I need to change?

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply to Ronald Fong Cancel reply

Your email address will not be published. Required fields are marked *