ScriptSpot

Forum topic · Scripts Wanted

Apply Turbosmooth modifier to selection

By IxenonI · 2016-09-01

Description

Hey guys,

I`m looking for a script that does the following:

When you run the script on your selection of objects, check if there are any turbosmooth modifiers already applied. If there are any applied, do nothing.

If there aren`t any applied, apply two turbosmooth modifiers. The first one with two iterations and seperate by smoothing groups turned on, the second one with one iteration and seperate by smoothing groups turned off.

It would be awesome if someone could help with this.

Thank you very much!

Comments (2)

fajar · 2016-09-08

try this ....the different from miauu is , it will not add turbosmooth modifier to instanced nodes


fn collectTrueObject sel:(selection as array) nodes:#() =
(
	local allObj = #()
	local inst=InstanceMgr.GetInstances
	for i in sel where  (findItem allObj i ==0 )do 
	(
		inst i &theNodes
		join allObj theNodes
		append nodes i 
	)
	nodes
)

fn myTurboSmooth =
(
	ts =TurboSmooth iterations:2 sepBySmGroups:true
	ts
)	

mapped fn addModToSelection nodes =
(
	local found=false
	for i in nodes.Modifiers where (isKindOf i TurboSmooth) do found =true 
	if found==false do addmodifier nodes (myTurboSmooth())
)

max create mode
with redraw off
objs=collectTrueObject()
addModToSelection objs
free objs
-- please select some nodes first

Hope this'll work

( function

miauu · 2016-09-02


(
	function AddTurboSmootModifier obj =
	(
		tsMod = TurboSmooth()
		tsMod.iterations = 2
		tsMod.sepBySmGroups = true
		addModifier obj tsMod
		tsMod = TurboSmooth()
		tsMod.iterations = 1
		tsMod.sepBySmGroups = false
		addModifier obj tsMod
	)
	
	if selection.count != 0 do
	(
		selObjsArr = selection as array
		for o in selObjsArr do
		(
			if o.modifiers.count != 0 then
			(
				tsModExist = false
				stopLoop = false
				for m = 1 to o.modifiers.count while stopLoop == false do
				(
					if classOf o.modifiers[m] == TurboSmooth do
					(
						stopLoop = true
						tsModExist = true
					)
				)
				if tsModExist == false do
				(
					AddTurboSmootModifier o
				)
			)
			else
			(
				AddTurboSmootModifier o
			)
		)
	)
)