ScriptSpot

Forum topic · General Scripting

Rotate UVWMap gizmo a selection of object

By Michele71 · 2011-01-25

Description

Hello everyone :)

How do I rotate the gizmo a modifier UVWMap in a selection of object?

Scenario:

I have 10 box and I apply to each a modifier UVWMap.
I want rotate the gizmo UVWmap to each object of 90° (or other
value) randomly pressing a button so as to have 10 objects with different rotation mapping.

My example dont work...


rollout t "Test"
(
	local mymod = (UVWMap())
	
	button b "Create UVWMap"
	button b2 "Random"

	on b pressed do
	(
	addmod =  for i in selection do addModifier i (UVWMap()) ui:on
         )

        on b2 pressed do 
              (
	     giz = mymod.gizmo
             giz.rotation = (angleaxis -90 [0,0,1]) as quat
                 )
	
)
createdialog t

If I select only one object the script works in half (the button dont refresh the value every time I press it) and if I select all object, i have this error message:

>> MAXScript Rollout Handler Exception: -- Unknown property: "gizmo" in Uvwmap:UVW Mapping <<

Can you help me? I can not find a solution....

Thanks

Comments (4)

Michele71 · 2011-01-26

Yes Joker it's all right !! :) Thanks!!!!!!!!

The only problem is:

How to If I want rotate the uvwmap a defined value (es. 90° or 45° ecc.)always random
for all object?

Anyway thanks again! :)

Anubis · 2011-01-26

Hi Michele,
if I see, you need to choose random value between concrete vals like 45 and 90. If so, put them to array and use random index to select an item from.

a = #(-90, -45, 45, 90)
r = a[random 1 4]

Michele71 · 2011-01-26

Hi Anubis, Thanks for you reply :)

Yes, now it's all right! I never thought of using an array to construct a random
value...this advice I will be very useful, this is a great tip that I will always remember ;)

Thanks again Anubis

Here you go!

JokerMartini · 2011-01-26


rollout t "Test"
(
local mymod = (UVWMap())

button b "Create UVWMap"
button b2 "Random"

on b pressed do
(
mapMod = UVWMap maptype:4
addmod = for i in selection do addModifier i (mapMod) ui:on
)

on b2 pressed do
(
for i = 1 to selection.count do
(
obj = selection[i]
giz =obj.modifiers[1].gizmo
val = (random -360 360)
giz.rotation = (angleaxis val [1,1,1]) as quat
)
)

)
createdialog t