I'm trying to creat locators on selected vertices and make them a group. And then creat a new display layer with that group. But this doesn't work after form and I don't know why. Can I get some help?
import maya.cmds as cmds
sel = cmds.ls(sl=True, fl=True)
for i in range(len(sel)):
pos = cmds.pointPosition(sel[i])
c = cmds.spaceLocator(n="loc01" , p=(0, 0, 0) )
d = cmds.xform(c, a=True, t=(pos[0], pos[1], pos[2]) )
cmds.select(d[0])
g = cmds.group(d, n = 'loc')
cmds.select(g[0])
cmds.createDisplayLayer( noRecurse=True, name='LocLayer' )
I agree with haggi krey. Furthermore, you should create some naming convention or use long name because it will keep creating loc01 every loop.
You should avoid cmds.select and just fill commands with arguments.
Also if you are a beginner in scripting, you may comment every line describing what you are doing as : # Group the locator 'c' ; # set the locator position ...etc
import maya.cmds as cmds
sel = cmds.ls(sl=True, fl=True)
x=1
for i in sel:
pos = cmds.pointPosition(i)
c = cmds.spaceLocator(n="loc{0}".format(x) , p=(0, 0, 0) )
x+=1
d = cmds.xform(c[0], a=True, t=(pos[0], pos[1], pos[2]) )
g = cmds.group(c, n = 'loc_grp_{0}'.format(c[0][-2:]))
dspL = cmds.createDisplayLayer( noRecurse=True, name='LocLayer_{0}'.format(c[0]))
cmds.editDisplayLayerMembers(dspL, g, noRecurse=True)