# More VRay Scene Access… or some more random tidbits

Following on from the last post. Here are another example of how you can mess around with VRay scenes using Python.

This collection of cubes was created using only one cube, it’s been instanced 2500 times and moved about randomly, to do this I’ve used the random module in Python which is handy for doing random number things.

```# figure 1
from vray.utils import *

import random as r
r.seed(1)

l=findByType("Node") # Get all Node plugins
v=Vector(0.0, 0.0, 0.0)
for x in range(2500):
dupl = l[0].duplicate('dup' + str(x))
t=dupl.get('transform')
v = Vector(r.random()*2, r.random()*2, r.random()*2)
t.offs += v
dupl.set("transform", t)```

The r.send(1) is used to create a seed point for any future calls to random module, this means that the random numbers chosen are going to be the same each time we render the image – if we’re making changes to the render we don’t want the position of the cubes to change each time we render.

The v variable is used to store the random number we’re using to offset the transform, at the moment this is just is using random.random() which produces random values between 0 and 1, in the above example this has the effect of moving the cubes only along the positive xyz axis. There is also random.uniform(min,max) which produces random values between the min and max numbers we give it.

Here the effect moves the cubes along positive and negative XZ. I’ve keep the Y axis in positive space so that the cubes don’t go through the ground plane.

```# figure 2
from vray.utils import *

import random as r
r.seed(1)

l=findByType("Node") # Get all Node plugins
v=Vector(0.0, 0.0, 0.0)
for x in range(20):
dupl = l[0].duplicate('dup' + str(x))
t=dupl.get('transform')
v = Vector(r.uniform(-1,1)*2, r.random()*2, r.uniform(-1,1)*2)
t.offs += v
dupl.set("transform", t)```

## 2 thoughts on “More VRay Scene Access… or some more random tidbits”

1. cool Tutorial !! .. do you have any idea of how to change rotations of each cube ?

1. earlyworm says:

Not off the top of my head. There is most likely a ‘rotation’ attribute that you could query and set similar to the transformation attribute.