[Closed] Selecting root node after merge
Hello,
I am slowly teaching myself MAXscript so apologies if this is an elementary question.
I have written a script that imports X,Y,Z coordinates over time (T) and assigns that information to multiple dummies. Now I need to automate the process of merging in models and attaching them to those dummies.
I merge in models using:
mergeMAXfile <filename> #select #noRedraw #AutoRenameDups #renameMtlDups
This obviously merges in a model and selects all parts.
These models are always linked to a main dummy. After I merge in a model, I would like to select the main dummy (so I can them align it and attach it to the moving dummies in the scene).
Am I correct to believe that I need to find the root node? If so, is there a simple way to determine and select the root node?
Read about global variable “rootNode” – your root Dummy is probably the first child of rootNode.
Thanks for the suggestion, Archangel. rootnode.children would select the main dummy I imported… but it would also select all the other dummies in the scene.
I stumbled into the answer:
select selection[1]
Apparently, when you use #select in the mergeMAXfile function, MAXscript automatically makes an array called $selection and places all of the selected objects into it according to the hierarchy. Therefore, the first entry is always the main parent of the hierarchy.
This is more of a roundabout way of selecting the main parent but I’ll take it.
Thanks you for the responses.
The problem is that in the data set I received, they have multiple units of multiple types all in the same array: Type, Unit #, Time, X, Y, Z.
So you could have, say, 8 units of Object A, 6 units of Objects B, 26 units of Object C, etc.
All said and done, I could have 30+ individual objects with undefined parent properties so “Select rootnode.children” would select multiple objects, which is not what I wanted.
Each time I merge in a new model, I needed to be able the select that specific parent dummy of the model that I had just merged into the scene.
I stumbled across a fix: apparently when you use #select with the mergeMAXFile function, MAXscript automatically creates an array “selection” and drops each selected object of the merged model into it, in order according to the hierarchy. So:
select selection[1]
would select the main parent of the newly merged in model.
It’s not exactly what I was looking for and there was some luck that MAXscript automatically makes an array for me to select from, but I will take it for now.
I’d still like the know how to select the main parent from the current selection. If anyone knows how to do that, I would appreciate it.
As Rotem suggested, doesn’t this work for you?
fn GetRootNodesFromSelection nodes =
(
for node in nodes where node.parent == undefined collect node
)
GetRootNodesFromSelection selection
Post an example of your data file… so if I understand, your script imports a text data file and applies that as animation onto dummy helpers. You then want to merge in existing .max files and then collocate those imported objects (assume to be meshes?) to specific dummies? And these are procedural objects and not skinned to bones, yes? Please clarify…
Thanks for the responses.
Archangel, you are correct.
Jorge, that code doesn’t seem to work. When I merge in model “ObectA”, it comes in with “17 objects selected”. While your code did not return any errors, it still had all 17 objects selected.
I need to only select the main helper that the model is linked to so that I can link that main helper to the moving object already in the scene.
For now,
select selection[1]
works after I merge in an object so I going to move on for now. I will post the entire code in the near future for evaluation and suggestions.
Thanks again for your help.
Then why not assign the animation directly onto those procedural objects in the file where they reside? Why do you need another file with dummies?
Interesting suggestion.
I’m pulling a variety of rigged models from an inventory database into the scene and I don’t know how many of each model are in the scene (it varies with each iteration of the animation) at the time I run the script, so I think I still need to ability to merge in models. I guess in theory I could populate the environment with 1 of each type of model and then clone additional models as I need them but I don’t know if that is more efficient than merging in additional models, right?
But I guess there is no need to animate a bunch of helpers and then link the models to those helpers. I could just animate the model’s parent object…
Yeah, I’m pulling in a variety rigged robots that have float limits and are already animated, Automated Guided Vehicles (AGVs) that have wire parameters set for wheel rotation, etc. A lot of different pieces you would find in a large factory (think car manufacturing). Each of these models is linked to a main helper that I use to move the model.
Those main “model” helpers are the ones I was trying to attach to the “data-driven” helpers.