Collapse ModifierStack and keep instances

Collapse ModifierStack and keep instances

rartidiello
Enthusiast Enthusiast
3,172 Views
9 Replies
Message 1 of 10

Collapse ModifierStack and keep instances

rartidiello
Enthusiast
Enthusiast

Hi,

I need a script for collapsing the modifier stack of all selected objects. Right now the Collapse button under the Utilities panel works but loses the instances.

 

Thanks.

0 Likes
Accepted solutions (1)
3,173 Views
9 Replies
Replies (9)
Message 2 of 10

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@rartidiello wrote:

Hi,

I need a script for collapsing the modifier stack of all selected objects. Right now the Collapse button under the Utilities panel works but loses the instances.

 

Thanks.


something like this...

 

 

fn collapseNodes nodes = 
(
	for node in nodes do maxops.collapsenodeto node node.modifiers.count off
)

/*
collapseNodes selection
*/

 

 

or this...

 

mapped fn collapseNodeToBase node = (maxops.collapsenodeto node node.modifiers.count off)
/*
collapseNodeToBase selection
*/

 

Message 3 of 10

rartidiello
Enthusiast
Enthusiast
thanks! works like a charm
0 Likes
Message 4 of 10

rutalauzikaite
Community Visitor
Community Visitor

Could someone help me, try to run those scripts and nothing happens at all 😞

Message 5 of 10

jesped
Enthusiast
Enthusiast

Can these be updated to work on 2024?

0 Likes
Message 6 of 10

denisT.MaxDoctor
Advisor
Advisor

what is not working in 2024?

0 Likes
Message 7 of 10

jesped
Enthusiast
Enthusiast

I select one object with 'Select Dependents' enabled:

 

Which selects 185 objects.

I save the script as a .ms file:


I run the script 

...and nothing at all happens, with either of the scripts. Am I doing something wrong? 🤔


This is the modifiers stack of the objects:

jesped_2-1727841138102.png


Ideally, I would want to convert all those 185 objects to 'Editable Mesh', but preserving instances.

0 Likes
Message 8 of 10

denisT.MaxDoctor
Advisor
Advisor

first of all the executable code looks as: 

 

 

for node in selection do maxops.collapsenodeto node node.modifiers.count on

 

 

 

second, dependent nodes are not exactly instances. There are other mechanics to find all instances of a node.

 

and third, if you do everything right, I'm pretty sure it will still work in 2027 at least. 

0 Likes
Message 9 of 10

jesped
Enthusiast
Enthusiast

Using 'Edit - Select Instances' didn't work either.

But this other script did:

if selection.count != 0 do
(
local firstInstances = #()
for o in selection do 
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 do 
append firstInstances firstOnly[firstOnly.count-1]
)
if firstInstances.count != 0 do select firstInstances
)
 
 
for obj in $ do
(
addModifier obj (Edit_Mesh())
)
 
 
 
for obj in $ do
(
maxOps.CollapseNodeTo obj 1 off
)
 
Thanks anyway.
0 Likes
Message 10 of 10

denisT.MaxDoctor
Advisor
Advisor

Great if the code above works... Good luck either way.

0 Likes