Operation on array not working

Hello,
I have the following script so far but it doesn't work the way i want it to.
The idea is to have a selection of objects that gets auto unwrapped and automatically exported to fbx.

It works on a selection of one object but doesn't work when multiple objects are selected. I'm not a great scripter so if its rubbish, please let me know.
Thanks!
Stefan

rollout autounwrap "AutoUnwrap"
(
button theButton icon:#("autounwrapicon",1) iconSize:[24,24] width:48 height:48
button theBorderlessButton "UnWarpMe" border:false

on theButton pressed do (

sel = selection as array
for obj in sel do
(
addModifier obj (Unwrap_UVW ()) ui:on
subobjectLevel = 3
$.modifiers[#unwrap_uvw].unwrap.move ()
$.modifiers[#Unwrap_UVW].texMapList.count = 0
$.modifiers[#Unwrap_UVW].texMapIDList.count = 0
$.modifiers[#Unwrap_UVW].baseMaterial_list.count = 1
$.modifiers[#Unwrap_UVW].baseMaterial_list[1] = meditMaterials[1]
$.modifiers[#Unwrap_UVW].texMapList.count = 2
$.modifiers[#Unwrap_UVW].texMapIDList.count = 2
$.modifiers[#Unwrap_UVW].texMapList.count = 3
$.modifiers[#Unwrap_UVW].texMapIDList.count = 3
$.modifiers[#Unwrap_UVW].texMapList[1] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[1] = -1
$.modifiers[#Unwrap_UVW].texMapList[2] = meditMaterials[1].texmap_diffuse
$.modifiers[#Unwrap_UVW].texMapIDList[2] = -1
$.modifiers[#Unwrap_UVW].texMapList[3] = meditMaterials[1].texmap_displacement
$.modifiers[#Unwrap_UVW].texMapIDList[3] = -1
actionMan.executeAction 0 "40021"
subobjectLevel = 0
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
)

actionMan.executeAction 0 "40373" -- File: Export Selected

)

)

createDialog autounwrap 150 60

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ijzerman86's picture

Soo, my array wasnt working

Soo, my array wasnt working the way it was, with the help of this snippet i fixed it.
http://www.scriptspot.com/forums/3ds-max/general-scripting/loop-through-...

Result:
rollout autounwrap "AutoUnwrap"
(
button theButton icon:#("autounwrapicon",1) iconSize:[24,24] width:48 height:48
button theBorderlessButton "UnWarpMe" border:false

on theButton pressed do (
theObjs = selection as array
clearSelection()
max modify mode

for obj in theObjs do
(
select obj
macros.run "Modifier Stack" "Convert_to_Poly"
addModifier obj (Unwrap_UVW ()) ui:on
subobjectLevel = 3
$.modifiers[#unwrap_uvw].unwrap.move ()
$.modifiers[#Unwrap_UVW].texMapList.count = 0
$.modifiers[#Unwrap_UVW].texMapIDList.count = 0
$.modifiers[#Unwrap_UVW].baseMaterial_list.count = 1
$.modifiers[#Unwrap_UVW].baseMaterial_list[1] = meditMaterials[1]
$.modifiers[#Unwrap_UVW].texMapList.count = 2
$.modifiers[#Unwrap_UVW].texMapIDList.count = 2
$.modifiers[#Unwrap_UVW].texMapList.count = 3
$.modifiers[#Unwrap_UVW].texMapIDList.count = 3
$.modifiers[#Unwrap_UVW].texMapList[1] = Checker ()
$.modifiers[#Unwrap_UVW].texMapIDList[1] = -1
$.modifiers[#Unwrap_UVW].texMapList[2] = meditMaterials[1].texmap_diffuse
$.modifiers[#Unwrap_UVW].texMapIDList[2] = -1
$.modifiers[#Unwrap_UVW].texMapList[3] = meditMaterials[1].texmap_displacement
$.modifiers[#Unwrap_UVW].texMapIDList[3] = -1

actionMan.executeAction 0 "40021"
subobjectLevel = 0
modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]

)

actionMan.executeAction 0 "40021" -- Selection: Select All
actionMan.executeAction 0 "40373" -- File: Export Selected
)
)

createDialog autounwrap 150 60

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.