Character Essences, Research & Coding

Curious Cones

This little project aims to create a random set of cones that “look at” a shiny red sphere passing by. The reference below shows the original maya + python youtube tutorial. The code that follows was saved as 2 shelf tools which can be used with any mesh.

The first script ( creates 30 instances of the first object selected in the scene. These instances are then randomly positioned, rotated and scaled.
import maya.cmds as cmds
import random
result = = True)
print 'result: %s ' %(result)
transformName = result[0]
instanceGroupName = = True, name = transformName + '_instance_grp#')
for i in range(0, 30):
   instanceResult = cmds.instance(transformName, name = transformName + '_instance#')
   cmds.parent(instanceResult, instanceGroupName)
   tx = random.uniform(-10, 10)
   ty = random.uniform(0, 20)
   tz = random.uniform(-10, 10)
   rotX = random.uniform(0, 360)
   rotY = random.uniform(0, 360)
   rotZ = random.uniform(0, 360)
   sXYZ = random.uniform(0.1, 1.25)
   cmds.move(tx, ty, tz, instanceResult)
   cmds.rotate(rotX, rotY, rotZ, instanceResult)
   cmds.scale(sXYZ, sXYZ, sXYZ, instanceResult)
cmds.xform(instanceGroupName, centerPivots = True)

The second script( takes the first elements selected and sets it as a target, while the rest of the elements selected are set as sources, looking at this target along their Y axis. At least one source and one target must be selected in order for the algorithm to work.

selectionList = = True)
if len(selectionList) >= 2:
   print 'Selected items: %s ' % (selectionList)
   targetName = selectionList[0]
   for objectName in selectionList:
      print 'Constraining %s towards %s ' %(objectName, targetName)
      cmds.aimConstraint(targetName, objectName, aimVector = [0, 1, 0])
   print 'Please select 2 or more objects'

Reference: Autodesk Scripting on Youtube


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s