ScriptSpot

Forum topic · General Scripting

collapse to problem

By titane357 · 2011-01-04

Description

hello
I made a little script to add an edit poly modifier at bottom of the stack of selected objects, so I can move for eg vertexes of all the objects in same time, AND when I have made my modifs in edit poly modifier I can "collapse to" the instanced edit poly modifier without touching modifiers on top of the stack.
But when I "collapse to" in the attached example (.png) I loose a modifier.
I can't manage to make a script to collapse just the lower modifier....
Anybody ?

Attachments
Comments (8)

---------

Ruramuq · 2011-01-05

if youre sure that all objects have the modifier you want to delete,after the baseobject then:
--
for o in selection do maxops.CollapseNodeTo o o.modifiers.count true
--

@Anubis, coping/instancing , does not always preserve all the data, in mods like editpoly..

Anubis · 2011-01-05

yep, batch processing collapse in this manner hide some weakness :) i think the function can be modified to select the desirable modifier and collapse when. it w'd be more slower but more correct (no backup copies).

titane357 · 2011-01-05

waow ! really cool ! I don't understand the script itself, but it works :-)

thanks for reminder

Anubis · 2011-01-05

Oh, i was forgot about maxOps.CollapseNodeTo
The Ruramuq code collapse most bottom modifier

[edit] here is a macro script with ui, cheers

Attachments

titane357 · 2011-01-05

hello anubis.
If you select lower modifier in the stack and "collapse to", you keep all other modifiers.
Now, with your script I'm the king : it works like a charm !!! Thanks.

titane357 · 2011-01-05

argh ! is it possible to remove just lowest editpoly modifier ?

Anubis · 2011-01-05

Sure it possible, i think so.
Now the function 'scan' from top and stop then find the 1st searched mod's, but you can rewrite it to 'scan from bottom.

u'r lucky man

Anubis · 2011-01-04

Haha, you are lucky then some mod's survive after collapse, how you achieve this?

Else, to keep certain mod's on top of the stack, you need to backup them, remove too, collapse and then re-apply saved mods.

here you go a function...
(you can use it for other modifiers types)

fn CollapseToModClass objOwner modClass = (
	if objOwner.modifiers.count > 0 do ( --if there mod's at all
		local backMods = #(), run = true
		while run do ( -- backup mod's
			if ClassOf objOwner.modifiers[1] != modClass then (
				append backMods objOwner.modifiers[1]
				deleteModifier objOwner 1
			) else ( run = false )
			if objOwner.modifiers.count == 0 do run = false
		)
		collapseStack objOwner -- collapse
		if backMods.count > 0 do ( -- restore mod's
			for m = backMods.count to 1 by -1 do
				addModifier objOwner backMods[m]
		)
	)
)
-- usage:
for obj in selection do
	CollapseToModClass obj Edit_Poly