Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

rotate 1 or more selected objects randomly, in steps of 90 degrees

grue1970
Collaborator

rotate 1 or more selected objects randomly, in steps of 90 degrees

grue1970
Collaborator
Collaborator

hello.  i've used this for many years to randomly rotate selected objects:

 

For i in selection do i.rotation.z_rotation = random 0.0 360.0

 

is there a way to change this so that it only rotates in steps of 90 degrees?

 

thank you

3ds Max all versions past and present | GPU Rendering on 2 machines | Standard, MentalRay, MentalRay IRAY, IRAY+, VRAY, Arnold
0 Likes
Reply
Accepted solutions (1)
4,032 Views
9 Replies
Replies (9)

grue1970
Collaborator
Collaborator

i was thinking i should clarify a bit.

 

so the selected objects in this case are squares.  carpet squares.  i have modeled carpet squares and applied materials to them.  right now they all are the same orientation.  so i'd like to grab them, and randomly rotate them in steps of 90 degrees - but not rotate the whole thing, just the individual squares that make up the whole carpet area. thanks.

3ds Max all versions past and present | GPU Rendering on 2 machines | Standard, MentalRay, MentalRay IRAY, IRAY+, VRAY, Arnold
0 Likes

miauuuu
Collaborator
Collaborator
Accepted solution

Maybe this will help you:

 

(	
	for o in selection do
	(
		case (random 1 4) of
		(
			1: o.rotation.z_rotation = 0
			2: o.rotation.z_rotation = 90
			3: o.rotation.z_rotation = 180
			4: o.rotation.z_rotation = 270
		)
	)
)
https://miauu-maxscript.com/
0 Likes

denisT.MaxDoctor
Advisor
Advisor

@grue1970 wrote:

 

so the selected objects in this case are squares.  carpet squares.  i have modeled carpet squares and applied materials to them. 


the rotating UVs makes more sense for me

0 Likes

grue1970
Collaborator
Collaborator

i kept seeing that come up even in the documentation for scripting and thought it would be too complicated so i just kept thinking about the rotate object.  i suppose i should look at it though.

3ds Max all versions past and present | GPU Rendering on 2 machines | Standard, MentalRay, MentalRay IRAY, IRAY+, VRAY, Arnold
0 Likes

grue1970
Collaborator
Collaborator

thanks. i was looking at that, how to define a set of variables like A B C D and assign a rotation to them then randomly apply. but i didn't think it would work.  but this helps - i'll read up on it to.

3ds Max all versions past and present | GPU Rendering on 2 machines | Standard, MentalRay, MentalRay IRAY, IRAY+, VRAY, Arnold
0 Likes

denisT.MaxDoctor
Advisor
Advisor

randomization at the bottom of the snippet. (everything else is my practice in MXS)

 

 

delete objects

/**************** make a pattern piece */
ad =
(
	a = tube radius1:25 radius2:15 height:10 slice:on sliceto:270 sides:12  pos:[-20,0,0]
	b = tube radius1:25 radius2:15 height:10 slice:on slicefrom:90 sides:12 pos:[20,0,0]
	c = box width:10 length:40 lengthsegs:12 height:10 pos:[0,20,0] 
	
	d = tube radius1:25 radius2:15 height:10 slice:on slicefrom:90 sides:12 pos:[20,-40,0]
	e = tube radius1:25 radius2:15 height:10 slice:on slicefrom:270 sliceto:180 sides:12 pos:[-20,00,0]

	converttomesh a 
	a += b
	a += c
	delete b 
	delete c
	
	a.wirecolor = orange
	centerpivot a
	
	converttomesh a 
	d += e
	delete e
	centerpivot d
	d.wirecolor = brown
	
	#(a, d)
)

/************ clone pieces and collect */
targets = #()
for y=1 to 9 do for x=1 to 9 do append targets (copy ad[random 1 2] pos:[40*x, 40*y, 5] wirecolor:green)

/******** randomize pieces z-rotations */
(
	in coordsys local about pivot (for target in targets do rotate target (angleaxis (random 0 3 * 90) z_axis))
)

 

 

 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

but usually ordinary random is not interesting in such tasks. it's interesting to make a random pattern with periodic repetitions.

0 Likes

grue1970
Collaborator
Collaborator

i couldn't get this to work.  kept getting an error.  i was tried to go through it an  mxscript online help but couldn't figure it out.

 

edit: i'm now in max 2020 (gotta update my sig) if that matters? screen shot of error is attached

 

 

3ds Max all versions past and present | GPU Rendering on 2 machines | Standard, MentalRay, MentalRay IRAY, IRAY+, VRAY, Arnold
0 Likes

obaida_ds
Contributor
Contributor

You can use this for specific rotation angel :

(
	step = 30
	rot_angle = for i = 1 to (360/step) collect (step*i)
	for i in selection do (
		r = random 1 rot_angle.count
		rot = rot_angle[r]
		rotate i (angleaxis rot z_axis)
	)
)
0 Likes