Randomize

Randomize

GeoffKornfeld
Advocate Advocate
862 Views
9 Replies
Message 1 of 10

Randomize

GeoffKornfeld
Advocate
Advocate

I have several dozen proxies that I want to randomize the the animation offset of. I know how to change the parameter to a specific number on a selection, but I don't know how to tell maxcript to enter random numbers between 1 and 570.

 

Thanks.

0 Likes
Accepted solutions (2)
863 Views
9 Replies
Replies (9)
Message 2 of 10

denisT.MaxDoctor
Advisor
Advisor

@GeoffKornfeld wrote:

I don't know how to tell maxcript to enter random numbers between 1 and 570.


 

either the question is not accurate or the answer is obvious:

 

 

random 1 570

 

 

... and of course you can specify a seed value (see random and seed in the MXS Help)

 

0 Likes
Message 3 of 10

GeoffKornfeld
Advocate
Advocate

Thanks, but that command gives everything in the selection the exact same random number. I want each object to get a different number.

0 Likes
Message 4 of 10

GeoffKornfeld
Advocate
Advocate

I guess I should specify that these are VRay Proxy objects, and I just entered the command:
($). anim_offset = random 1 570

0 Likes
Message 5 of 10

denisT.MaxDoctor
Advisor
Advisor

@GeoffKornfeld wrote:

I guess I should specify that these are VRay Proxy objects, and I just entered the command:
($). anim_offset = random 1 570



if all your VRay proxy objects have a unique name, we can generate a random offset value based on the name:

(
	hashcode = gethashvalue <vray_proxy_obj>.name 0
	seed hashcode
	<vray_proxy_obj>.anim_offset = random 1 570
)

where <vray_proxy_obj> is a "pseudo node" variable

 

0 Likes
Message 6 of 10

GeoffKornfeld
Advocate
Advocate

Sorry, I'm not understanding. And I'm not clear on how to modify what you typed to to work. Each of my objects is called "Goat 001, Goat 002.... etc." (they are grazing goats on a field). Should the name matter? Can't there just be a script that finds the parameter in the selected objects one by one and put a random value in there?

0 Likes
Message 7 of 10

denisT.MaxDoctor
Advisor
Advisor

1. select all vray proxy objects

2. run this script:

for vray_proxy_obj in selection do
(
	hashcode = gethashvalue vray_proxy_obj.name 0
	seed hashcode
	vray_proxy_obj.anim_offset = random 1 570
)

every time you do it each object will get exactly the same but random number based on seed value generated using the object's name. of course all names must be unique.  the objects with the same name will get the same random number

 

0 Likes
Message 8 of 10

denisT.MaxDoctor
Advisor
Advisor

how many objects do you have and want to randomize?

0 Likes
Message 9 of 10

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

simple using of random method cannot for sure guaranty exactly unique numbers for all objects. 

if the number of objects is less than the number of possible "offsets" I would probably use shuffle method instead of random

 

 

0 Likes
Message 10 of 10

GeoffKornfeld
Advocate
Advocate
Accepted solution

Oh I see. My problem was that I was trying to run the script from the listener. I dragged it to the toolbar and it worked great. Thank you!

0 Likes