[Closed] Maxscript: Get the root node of Referenced nodes
Hello wrote a maxscript function to retrieve the root of the referenced objects, but it’s pretty slow, I’m wondering if there’s anything else built-in that I’m missing to make the whole thing faster.
Here’s my code, I’m basically adding a modifier on every node, and getting the root by comparing the modifiers count.
fn get_reference_parent node_list test_mod: =
(
local root = undefined
local modifiers_ref_count = 0
if test_mod == unsupplied then test_mod = EmptyModifier()
if node_list.count > 1 then
(
for node_ in node_list do
(
addmodifier node_ test_mod
)
root = node_list[1]
modifiers_ref_count = node_list[1].modifiers.count
for i=1 to node_list.count do
(
node_ = node_list[i]
if node_.modifiers.count < modifiers_ref_count then root = node_
)
for node_ in node_list do
(
deleteModifier node_ 1
)
)
return root
)
Why do you add the empty modifier, wouldn’t returning the node with the least modifiers do the same anyway? Edit: Okay, now I see why, if there’s a reference with no modifier applied – that could be identified by getting the stack listbox item count if it’s is displayed in the modifier panel, but that’s not a fast solution either since you’d have to select the items one by one. Another question, how is this used?
For example, if you’re looking for an object with no reference separator in the stack, so to say, testing for hasProperty obj[4] #Modified_Object should be enough.
Yeah the problem comes when there are no modifiers on the children.
I need to detect the root to make it a Cachable by tagging it for exemple, so an automatic Point Cache Script system can only load/save Caches on the root of the references.
So I presume this could work for you:
fn get_reference_parent node_list =
for obj in node_list where hasProperty obj[4] #Modified_Object do exit with obj
Cool thanks I just can’t find any documentation on obj[4] part, what’s the 4 for ?
That’s the fourth subanim of a node, first three are #visibility, #space_warps and #transform and this one is either #<object_class> if there’s no modifier or #modified_object if the node has some modifiers, and if there are some modifiers and the node is a reference, the #modified_object will have its own #modified_object subanim. Actually, I posted the reverse of what you asked for, should be instead something like
fn is_base obj =
(obj.modifiers.count > 0 and not hasProperty obj[4] #Modified_Object) or
(obj.modifiers.count == 0 and findItem (getSubAnimNames obj) #Modified_Object == 0)
fn get_reference_parent node_list =
for obj in node_list where is_base obj do exit with obj
delete objects
b = box name:#b
bb = reference b name:#bb pos:[30,0,0]
addmodifier bb (Edit_Poly())
bbb = reference bb name:#bbb pos:[60,0,0]
addmodifier bbb (Edit_Poly())
bbbb = reference bbb name:#bbbb pos:[90,0,0]
addmodifier bbbb (Edit_Poly())
/* now try to delete:
delete #(b,bb,bbb)
*/
Find all reference objects. Then find the object(among all references) with the lower inode.handle – it is the father of all references.
This is pretty good, are you sure, that the handle, is only incremental ? I mean if I delete object, the new created ones will not get lower handle than already existing ones?