Random visible object every full rotation?



Trying to solve a xpresso setup were the following should happen:
An object rotates several revolutions and each time it hits a full 360 it should trigger one of several objects to be visible for the entire coming revolution. Next time the object hits a full 360 rotation another random object should be visible and the rest hidden.

My approach right now is to use a Modulo function of 360 on the rotation and feed that into the Equal node giving me one frame of True when the rotation is 360. I now want to feed that into a Python script that generates one of several objects to be visible every time this occurs.

Any suggestion how to solve this is greatly appreciated.


Here’s some ideas. Bear in mind that a random number can be the same as the last one. If you want a different number to the previous, you need something a bit more fancy.

rnd obj.c4d (267.6 KB)


thanks a bunch. neetly done. I have to learn more about how to use Python in C4D… any suggestions on where to start on that journey?

if I would consider expanding it to always showing a different number from the previous, how would I go about it?


An unforeseen problem with this approach: if I’m upping the total number of revolutions it seems as the exact moment where the rotation is one full 360 happens on a subframe. Can I take this into account with the xpresso?


Here I rotate the object an integer multiple of 360. Also the random number is calculated by addition and modulo to prevent duplication.

rnd obj2.c4d (224.0 KB)


Hmmm, nothing happens when I start the sequence, Do I need to enable something ?

To comment on the OP … why wouldn’t a visibility tag work ? TIA


@martinlofqvist member Cairyn has a C4D python course


@vid2k2 Display tag is probably a better method

rnd obj3.c4d (208.1 KB)


thanks a bunch. Why would Display tag be a better method? Does it compute easier?


I just meant it looked a bit neater in the code - less repetition etc.


ok! gotcha.

A question with the setup is that the editor and the render window is not showing the same result. Why is it executed this way - and is there possible to get the same result in both the editor and renderer?
I’m using Arnold if that might be affecting it.


Possibly random is being too random and giving a different set of integers every run. Random is based on a seed value, if you specify a seed you get the same set of random numbers every time.

Try putting the line


before random is called (can be any seed).

Without a specified seed, Python generates a random one - based on clock time IIRC - giving different integers every time.