Maya snippets

Selection

Action if selection has item or not

1
import maya.cmds as cmds
2
target = cmds.ls(sl=True)
3
if target:
4
print('yes')
5
else:
6
print('no')
Copied!

Adding objects

To a curve

1
import maya.cmds as cmds
2
from random import uniform
3
delta = 1.0/10
4
for n in range(40):
5
if uniform(0,1) > 0.5:
6
x,y,z = cmds.pointOnCurve( 'curve44', pr=(delta * n), p=True )
7
cmds.sphere(r=uniform(0.01, 0.04))
8
cmds.move(x,y,z)
Copied!
1
import maya.cmds as cmds
2
from random import uniform
3
delta = 1.0/10
4
for n in range(40):
5
if uniform(0,1) > 0.5:
6
x,y,z = cmds.pointOnCurve( 'curve44', pr=(delta * n), p=True )
7
cmds.sphere(r=uniform(0.01, 0.04))
8
cmds.move(x,y,z)
9
10
#----------------------------------------
11
import maya.cmds as cmds
12
from mesh_utils import *
13
from random import uniform
14
15
positions = get_faces_midpoint('pPlane1', False)
16
for x,y,z in positions:
17
inst = cmds.instance('pCone1')[0]
18
y_angle = uniform(0, 360)
19
20
cmds.rotate(0, y_angle, 0, inst, relative=True)
21
cmds.move(x,y,z, inst)
22
#----------------------------------------
23
Copied!