randomly pick objects from a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I have a list with 5 objects in it. Based on vertex/face selection I can instance and attach 1 of these 5 objects to the surface of another object (for example a tile on a floor). My problem so far is that I want to use all 5 objects and randomly place them on my selection of vertices.
can someone help please?
I do really appreciate
my code so far:
from maya import cmds
import random as rand
tileSel = ['tile_01', 'tile_02', 'tile_03', 'tile_04', 'tile_05']
def init():
selectedItems = cmds.ls(sl=True, fl=True)
selectionSize = len(selectedItems)
if not selectedItems:
return #get out of the function and do nothing
else: #if either vertex, edges or faces are selected
performSelection(selectedItems)
def performSelection(selectedItems):
grp = cmds.group(em=True, n='Cloner_GRP')
if not selectedItems:
cmds.select(clear=False)
else:
cmds.select(clear=True)
for all in selectedItems:
cmds.select(all)
clst = cmds.cluster()
cloneObj = cmds.instance(cmds.ls(tileSel)) #instaning Custom Objects
selectedItems = cmds.xform(clst, q=True, rp=True)
cmds.xform(cloneObj, t=selectedItems, ws=True)
# Constrain cloneObj to floor at the closest point.
gConst = cmds.geometryConstraint( 'floor', cloneObj )
cmds.delete(gConst)
# Constrain cloneObj to floor at the face normals.
nConst = cmds.normalConstraint('roof', cloneObj, worldUpType="scene", aimVector=(0, 1, 0), upVector=(0, 1, 1), weight=1)
cmds.delete(nConst)
cmds.delete(clst)
cmds.parent(cloneObj, grp)
init()