HELP - OBJ sequence script with "choice" node

Hey, I am hoping sombody with a background in sripting can help me over this hurdle. 

I have been trying to get an OBJ sequence into my Maya scene and it seems all the scripts out there that I have found are written with visibility toggles for each frame. That is cool and all but it just isnt going to work for what I need to do.

I found a better way to go about OBJ sequencing in Maya using the "choice" node. I am able to connect its selector input to the "time1" node and let the .outTime attribute flip through the meshes while keeping all the data in one shape node.

The problem! :

There are hundreds of OBJs and unless I get a script written, I would have to connect each OBJs shape.outMesh connection manualy into the "choice" node's .input[1-360] !!! Wich I could really do without and I am sure you could understand that.

Could sombody please help me figure out how to write the script or point me to a reasource that would help? It would be greatly appreciated :slight_smile:

Right now my scripting knowledge is limited to writting hundreds of these:

connectAttr -f oil_shape_0001.outMesh choice1.input[1];

connectAttr -f oil_shape_0002.outMesh choice1.input[2];

connectAttr -f oil_shape_0003.outMesh choice1.input[3];

connectAttr -f oil_shape_0004.outMesh choice1.input[4];

connectAttr -f oil_shape_0005.outMesh choice1.input[5];

connectAttr -f oil_shape_0006.outMesh choice1.input[6];

connectAttr -f oil_shape_0007.outMesh choice1.input[7];

connectAttr -f oil_shape_0008.outMesh choice1.input[8];

connectAttr -f oil_shape_0009.outMesh choice1.input[9];

YIKES!!

// Usage:
//    Select your objects and run. It creates a new choice node, and a new target mesh.
//    Connects every shape node to the choice node. No error checking so select only meshes.

global proc ConnectToChoice()
{
    // get selection
    string $mySel[] = ls -sl;

    // create choice node with name
    string $choice = createNode -n ($mySel[0] + "\_choice") choice;

    // connect obj outMesh to choice input attr
    for( $i=0; $i<size($mySel) ;$i++ )
    {
        string $shapes[] = `listRelatives -s $mySel[$i]`;
        connectAttr -f ($shapes[0] + ".outMesh") ($choice + ".input[" + $i + "]");
    }

    // connect time to choice selector attr
    connectAttr -f time1.outTime ($choice + ".selector");

    // create new mesh to hold the animation   
    string $newMesh[] = polyCube -ch 0 -n ($mySel[0] + "\_OBJ\_Seq\_Holder");

    // connect choice output to new mesh inMesh attr
    string $meshShape[] = listRelatives -s $newMesh[0];
    connectAttr -f ($choice + ".output") ($meshShape[0] + ".inMesh");

    // hide original objects
    hide $mySel;
}

ConnectToChoice();

// Let me know if it is working. I did a quick test and it works. Cheers!

Wow, yes this is exactly what I've been trying to accomplish. It works perfectly! 

Thank you very much Mr. Charlie, you sir are a saint! :smiley:

You have certainly helped enough as it is, but I am just curious, do you know of a way to prevent Maya from forcing a pop-up when dragging OBJs into the viewport from an explorer window? I can load in OBJs without the popup if I use the Edit/Import Options window, but even if I save those settings, it defaults to settings that result in a pop-up (when dragging OBJs in). Right now I am forced to hold the Enter key down for a couple minutes to press OK for hundreds of pop-ups... very frustrating..

Anyway, hope others stumble appon this thread too, im sure they will find this script much more useful than most all the other OBJ sequencer scripts out there.

Thanks again! - GIL

Instead of hiding the original objects you should mark them as intermediary. This will remove the nodes form the normal DAG visisbility making the scene cleaner for the user.

Not a bad idea, thanks for the tip.

Hey! Good to know it works for you. The pop-up thing is really annoying. It seems the key is to use this flag
( -options "mo=0")  when importing. In the Import dialog it is the options below "File Type Specific Options"
which says "Single Object".

//Ex.
         file -f -i -type "OBJ" -options "mo=0" "OBJ_FILE";

but of course you can only do it for multiple files via script. I think, don't really know. The thing is I'm assembling a script to do just that (thanks to your idea), well it's going to be just another OBJ Sequence Import/Export script that makes some scene cleanup (making groups to hold the sequences) . I guess I will upload it today or tomorrow, a soon as it is ready. I'll post the link here when it's done.

PD: Joojaa: Well, I don't use intermediary objects because each transform node will still be shown , cluttering the outliner anyway, so... (the fact is that I don't know how to unparent the mesh nodes from the transform to leave just the shape node which is only what I want, in fact I don't really know if it is even  possible. I would be nice to know)

Cheers!

There it goes:

http://www.creativecrash.com/maya/downloads/scripts-plugins/data-management/c/obj-sequences-import-export

Demo video
http://www.youtube.com/watch?v=Fl2NplM1ih4&feature=youtu.be

Hope it helps!

Let me know if there are bugs.

Cheers!

because each transform node will still be shown

You can mark the transform intermediary that will hide it from the normal DAG listing (intermediaryObject is a property of DAG objects thus also the transform). Obviously if you take the outline and tell it to list all objects it will still be shown but so will any node. By default tough this is not the case.

the fact is that I don't know how to unparent the mesh nodes from the transform
to leave just the shape node which is only what I want, in fact I don't really know if it is even  possible

You can not, but you can put many shapes under ONE transform*. Thereby reducing the number of nodes dramatically. Heres how:

//suppose you have a scene with 2 spheres
file -f -new;
sphere;
sphere;
move -r -2.773559 0 0 nurbsSphere1.cv[0:100][0:100];
// you can then do as follows either pause here or evalDeferred
parent -shape -add nurbsSphereShape2 nurbsSphere1;
// and delete the extra transform
delete nurbsSphere2;

*So you could put all the shapes under the transform that hosts the choice shape leaving you with one node visible. if you have intermediary object on.

You can not, but you can put many shapes under ONE transform*

Yeah, could be another solution, thanks. The snippet above was just to provide quickly some usable code. The fact is that the latest script orginises the objects, grouping the imported meshes, so in the end I end up with a main group that holds the sequences and a mesh for each imported sequence. Thanks for the feedback. Cheers!

Edit: Joojaa, in the end I followed your advice and I implemented that option as well ( pretty neat! in fact it is way more cleaner ). Thanks!

Hey Charlie, tried going to your links but it says the pages are not found. Read the convo between you and Joojaa, sounds like you might be uploading a newer version. Hope you'll come back here and post the links, I'd like to see what you came up with.

Thanks again for everything, hope my suggested OBJ sequence solution is or will be of use to you down the line. Much better than toggled visibility scripts, wouldnt you agree?

Cheers :slight_smile: - GIL