Working with modifier instances


How do you tell if the currently active modifier is an instance, and get the other objects it’s a part of?

Never done anything with instanced modifiers before in script and am lost one where to even start.


Try this example

 theBox = Box pos:[100,0,0]
 theTea = Teapot radius:10
 theMody1 = TurboSmooth()
 addModifier theBox theMody1
 addModifier theBox (Bend())
 addModifier theTea theMody1
 addModifier theTea (Edit_Poly())
 addModifier theTea theMody1
 checkMods = InstanceMgr.CanMakeModifiersUnique
 for o in objects do
 	for m in o.modifiers do
 		format "obj: % modifier: % instance: %
" (classof m) (checkMods o m)

refhierarchy.IsRefTargetInstanced <modifier_instance>


delete objects 
 bb = for k=1 to 2 collect box()
 m = Edit_Poly()
 addmodifier bb m
 -- check it
 refhierarchy.IsRefTargetInstanced m
 -- >> true

InstanceMgr.MakeModifiersUnique bb m #individual
 -- check it again
 refhierarchy.IsRefTargetInstanced m
 -- >> false


I did not know about refhierarchy interface
Very cool Denis. Thanks for info.


One question
Is this proper way to collect all unique nodes that have assigned modifiers

 	fn uniqueNodes objs = if objs.count != 0 do
 		local getNodeByHandle = maxOps.getNodeByHandle, getObjIns = InstanceMgr.GetInstances
 		local uniqNodes = #(), allINodes = #()
 		for o in objs where o.modifiers.count != 0 do append allINodes o.inode.handle
 		while allINodes.count != 0 do
 			obj = (getNodeByHandle allINodes[allINodes.count])
 			if isValidNode obj do append uniqNodes obj
 			if not (refhierarchy.IsRefTargetInstanced obj) then deleteItem allINodes allINodes.count else
 				getObjIns obj &firstOnly
 				for o in firstOnly where (idx = findItem allINodes o.inode.handle) != 0 do deleteItem allINodes idx


something like this:

for node in <nodes> where InstanceMgr.GetInstances node i == 1 collect node

would be shorter…


No. Only unique nodes. I wrote simple tool by request on and i need a simple function. I not want to loop trought all scene objects to delete some modifiers


Yup. But I need also first instance


the first instance is the node itself


everything is much easier than you do it…

mapped fn collectModifiers node classes: = 
	for modi in node.modifiers where classes == unsupplied or finditem classes (classof modi) > 0 collect modi
mapped fn deleteModifiers modi node = (deletemodifier node modi)
mapped fn deleteModifiersByClass node classes: = 
	deleteModifiers (collectModifiers node classes:classes) node
deleteModifiersByClass (objects as array) classes:#(Edit_Poly)


I do not know why I always try to complicate things :slight_smile:
Thank you Denis. I really appreciate your advice.


it’s not you complicate, it’s i simplify :slight_smile:


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.