Working with modifier instances


#1

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.


#2

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: %
" o.name (classof m) (checkMods o m)
 	)
 )
 

#3
refhierarchy.IsRefTargetInstanced <modifier_instance>

so:

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

#4

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


#5

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
 			)
 		)
 		uniqNodes		
 	)	
 

#6

something like this:


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

would be shorter…


#7

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


#8

Yup. But I need also first instance


#9

the first instance is the node itself


#10

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)
*/


#11

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


#12

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


#13

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.