ScriptSpot

Forum topic · Scripts Wanted

Smarter Collapsing

By hippiearchitect · 2013-01-30

Description

collapse stack without collapsing the Meshsmooth, Turbosmooth, UVW or Unwrap UWV modifiers while preserving instances.

Comments (4)

artrender.info · 2013-11-12

hey, Anubis! I like your idea with collapsing only upper modifiers, but your script has a lot of errors!

.

miauu · 2013-11-12

Fix the errors and post the result. :)

hi Daniel

Anubis · 2013-01-31

Are all this modifiers on top of the stack? And there also not other kind of modifiers in-between, rihgt? If not, the final result would be unexpected, actually undesirable.

I'll presume that the modifiers you want to preserve are on top of the stack, and will post something (UNtested), and can't say is it better than Branko's idea :))

fn customCollapse force:off = if selection.count > 0 do
(
	local modClasses = filterString (
		@"TurboSmooth
		MeshSmoothMod
		MapMod
		Unwrap UVW"), "\n\t"

	local arrObj = #(), oldSel, modIndex, run
	local rptInstances = #(), trueInstances
	
	max create mode
	oldSel = selection as array
	
	while selection.count > 0 do
	(
		InstanceMgr.GetInstances $ &rptInstances
		trueInstances = for n in rptInstances where \
		(areNodesInstances selection[1] n) collect n
		append arrObj selection[1]
		deselect trueInstances
		deselect selection[1]
	)
	
	if force do
	(
		for obj in arrObj where \
		obj.modifiers.count == 0 do
		(
			if validModifier obj Turn_To_Mesh do
			(addModifier obj (Turn_To_Mesh());
			collapseStack obj)
		)
	)
	
	arrObj = for obj in arrObj where \
	obj.modifiers.count > 0 collect obj
	
	for obj in arrObj do
	(
		modIndex = obj.modifiers.count
		run = (modIndex > 1)
		while run do
		(
			if findItem modClasses (getClassName \
			obj.modifiers[modIndex]) == 0 then
			(modIndex -= 1) else (run = false)
			if run do run = (modIndex > 0)
		)
		modIndex += 1
		if modIndex <= obj.modifiers.count do
		maxOps.CollapseNodeTo obj modIndex off

		if obj.modifiers.count == 1 and \
		findItem modClasses (getClassName \
		obj.modifiers[1]) == 0 do
		collapseStack obj
	)
	select oldSel
)

-- Usage:
customCollapse force:on -- collapse all selected
customCollapse() -- skip selected without modifiers

try this

barigazy · 2013-01-30


fn smartCollaps = if selection.count != 0 do
(
max create mode
local modClasses = #("TurboSmooth","MeshSmoothMod","MapMod","Unwrap UVW")
local modArr = #(), ins = #()
while selection.count > 0 do
(
obj = if (InstanceMgr.GetInstances selection[1] &ins) > 0 then ins[1] else selection[1]
if (modCnt = obj.modifiers.count) > 0 do
(
for m = modCnt to 1 by -1 where findItem modClasses (getClassName obj.modifiers[m]) != 0 do
(
append modArr obj.modifiers[m] ; deleteModifier obj m
)
if (modCnt = obj.modifiers.count) > 0 do maxOps.CollapseNodeTo obj 1 off
if (maCnt = modArr.count) != 0 do for c = 1 to maCnt do addModifier obj modArr[c]
if ins.count != 0 then deselect ins else deselect obj
)
if ins.count != 0 then deselect ins else deselect obj
free modArr ; free ins
)
)