Randomly select SOP by name for animation

I have a multiple SOP and I want to select them randomly to apply specific transformation. How do I do that only with SOP or it will be easy by name of the SOP.

welcome to the Forum!

You could use a Switch SOP and control the Select Input parameter of the Switch SOP via a random number generated for example with the Pattern CHOP.

cheers
Markus

Hi Markus, here is a bit more info what I’m trying to do. I need to select random SOP (ore anything with specific name) to rotate for example, this is like a rubik’s cube.

Are you working out the full logic for a rubik’s cube? What I have here won’t be necessarily the right approach but for what you are showing I would look at using a Fan CHOP. From the docs:

Its first operation, Fan Out , takes one channel and generates 2 or more channels. It sets to 1 one of the output channels while all others are 0, based on the input channel’s value. The first output channel is index value 0, the second, 1, and so on. If the input value is above N-1 or below 0, the value can be clamped, cycled or ignored.
For example, if the value of the input channel at a certain frame is 4, and if the CHOP outputs 8 channels, the fifth channel will have a value of 1, and all other channels will have a zero value at that frame.

The incoming value to the Fan CHOP could be a random number that corresponds to the rows in your table. This way each row get’s it’s own channel that can be used in the various Transform CHOPs.

fanCHOP.tox (2.4 KB)

cheers
Markus

Thanks for reply. I am trying to build a rubik’s cube but not only it. I want to make base node that you can use in different ways, but the question is if it’s possible to make in a elegant way. I don’t know that good TD and don’t know how many ways to do that and which one is right way to do that. So this is why I’m curious about that. Thanks for file example I will try to use it. Also, I thought of make a list with all side of cube and put them in to the list. [All the possible side that can be rotated] After that I need to use random selection of this name to target rotation. Rotation will be a Beat and each cube will be a Point. Main question is, is it passable to do that that way in TD or I need to thing about other way?

The Rubik’s Cube is a bit a tricky one but doable. The tricky part comes from doing additive transforms - meaning you kind of want to reset your coordinate system after each transform. So the easiest I can think of would be doing this with matrices and apply the rotation on these.
The basic idea is that you have a reference object (a Null COMP) which you retrieve a transformation matrix from:

transMat = op('nullComp').localTransform

Then you can apply a new rotation to it without having to deal with changed coordinate systems:

transMat.rotate(0,90,0)

The transformation matrix can be written back to the reference object for storage until the next rotation and also be exploded to retrieve the resulting total rotation angles:

op('nullComp').setTransform(transMat)
s, r, t = transMat.decompose()

s, r and t stand for scale, rotate and transform. The rotate part can now be applied to the cube you want to rotate.

I packed this all up into a component with an extension and custom parameters to initiate a rotation. The next trick I guess for you to figure out is how to do a rotation on all cubes that are in a certain plane. (The computeBounds Method might come in useful here)

Hope this helps a bit?
cube1.tox (2.9 KB)
Cheers
Markus

Hey Markus, thank you for respond. Also thanks for example I will check out.!