random script

random script

Anonymous
Not applicable
1,398 Views
7 Replies
Message 1 of 8

random script

Anonymous
Not applicable
hi. does anyone here know how to make a random script. for exp. random scale and rotation
0 Likes
1,399 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
hi. does anyone here know how to make a random script. for exp. random scale and rotation


The RANDOM() method is implemented for most values, which includes Floats, Integers, Colors, Point3 Values and so on.
So it is relatively easy to apply to properties like position, rotation, scale, color, typical Float or Integer value properties etc.

You generally have two choices - apply an absolute value or increment the existing value with a random value.

For example,
for o in selection do o.scale = random  

will set the scale of all selected objects at object level between 50 and 200 percent for EACH axis separately, while
for o in selection do o.scale += random  

will add between -10 and 10 % to the existing value of each axis.
If you want to do Uniform scaling, you will have to get a single random number and use it for all 3 components, for example
 for o in selection do o.scale =  * (random 0.5 2.0) 

will set the scale of all 3 axes to a random value between 50 and 200%, different for each object.
If you apply the scale to a selection of objects without a for loop, a single random value will be assigned to ALL objects at once (so-called mapped function):
selection.scale =  * random 0.5 2.0


You can do something similar for position and for rotations - positions use the same Point3 values, while for rotations you would have to use Euler angles, AngleAxis or Quats and the rotate() method which will perform the rotation in the local space of the object. Assigning to the rotation property will change the scale in parent (or world, if no parent) space and will cause the objects to move relatively to the origin.

For example,
for o in selection do rotate o (random (EulerAngles 0 0 0) (EulerAngles 180 180 180) ) 

will rotate each selected object about its pivot using a random angle about each of the 3 axes, while
for o in selection do o.rotation = (random (EulerAngles 0 0 0) (EulerAngles 180 180 180) )  as quat

will rotate each object about the parent (or world) origin at a random angle about each axis.
You can specify a coordinate system explicitly, for example
in coordsys local for o in selection do o.rotation = (random (EulerAngles 0 0 0) (EulerAngles 180 180 180) )  as quat
will do the same as the first rotate() example above - each object will rotate about its local pivot.

There are many more things that could be said about the topic, but this should give you a start...
0 Likes
Message 3 of 8

Anonymous
Not applicable
You can also try randomTransform here...

http://www.neilblevins.com/soulburnscripts/soulburnscripts.htm

- Neil
0 Likes
Message 4 of 8

Anonymous
Not applicable
thanks alot soulburn and Borislav Petrov. it helps alot
0 Likes
Message 5 of 8

grue1970
Collaborator
Collaborator

hey bobo.  i have been using undo on (for  obj in selection do obj.scale *= (random 0.85 1.0)) which has worked awesome for me for a few years!  i believe i found it from one of your posts, like the one in this thread haha.

 

i'd like to use one that does just z-axis scale.  so if i have 30 trees, all the same height, and i'd like to change the z-axis scale randomly between .6 and 1.2 how does that work?

 

thanks,

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

har1sf0x
Advocate
Advocate

Hello there,

 

try obj.scale.z = (random .6 1.2) or obj.scale.z *= (random .6 1.2)

 

Enjoy,

har1sf0x

0 Likes
Message 7 of 8

grue1970
Collaborator
Collaborator

i get: unknown property "scale" in undefined.

 

i did find a cool tutorial, maybe i can glean something from that.  seems to me that i've run into that problem before - unknown property.  hm.

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

grue1970
Collaborator
Collaborator

undo on (for obj in selection do obj.scale.z *= (random 0.2 3.0))

 

that worked.  i think maybe i had an issue where i was doing something wrong with $ and which objs i had selected.

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