Notifications
Clear all

[Closed] 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.

11 Replies
3 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

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)
 	)
 )
 
(@denist)
Joined: 11 months ago

Posts: 0
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
(@gazybara)
Joined: 11 months ago

Posts: 0

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

something like this:


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

would be shorter…

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Yup. But I need also first instance

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

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

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

(@gazybara)
Joined: 11 months ago

Posts: 0

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

the first instance is the node itself

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