ScriptSpot home

Forum topic · General Scripting

collapse to problem

By titane357 · 2011-01-04

Downloads
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 ?

Comments (8)
Ruramuq

---------

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..

Reply to Ruramuq
Panayot Karabakalov

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

Reply to Ruramuq
titane357

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

Reply to titane357
Panayot Karabakalov

thanks for reminder

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

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.

Reply to titane357
titane357

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

Reply to titane357
Panayot Karabakalov

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.

Panayot Karabakalov

u'r lucky man

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