Search This Blog

Monday, 20 December 2021

BPY SCRIPT TO POSITION AN OBJECT AT RANDOM LOCATION.

 The script below positions the monkey object at random position between _20 and +20 units along the X and Y axis. Along Z axis the location varies between -2 and +2 units.

----------------------------------------------------------------------------------------------------------------------------

'''POSITIONS MONKEY OBJECT AT RANDOM LOCATIONS BETWEEN -20 AND +20 UNITS ALONG X & Y AXIS, -2 TO +2 UNITS ALONG Z AXIS '''

import bpy

bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete(use_global=False)


from random import randint
number=200
for i in range(0,number):
    x=randint(-20,20)
    y=randint(-20,20)    
    z=randint(-2,2)
    bpy.ops.mesh.primitive_monkey_add(location=(x,y,z))

----------------------------------------------------------------------------------------------------------------------------
  

No comments:

Post a Comment

Please send your comment as to what extent these topics are explained clearly. If you want any new topic explained, just put up a message in the comment, we shall address it.

TO SET UNIT OF MEASUREMENT - METRIC/IMPERIAL

Instruction as applicable to Blender Version  3.00 and above.  In Blender, we can set the dimensions of Rotation, Length, Mass, Time and Tem...