本文整理汇总了Python中maya.cmds.sets函数的典型用法代码示例。如果您正苦于以下问题:Python sets函数的具体用法?Python sets怎么用?Python sets使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sets函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: importSculpt
def importSculpt(path, sel=None):
'''
Provide the full path:eg. home/user/exportfile.txt .txt in the name is critical.
sel = <Transform> Provide the transform that the sculpts are connected to, recommened through script
sel = <None>(Default), recommended through User Interface calls
'''
if sel == None:
sel = validateSelection()
if sel != None:
# get a list of all the files
path = os.path.join(path, 'sculpt_set')
if os.path.exists(path):
files = os.listdir(path)
for f in files:
# It's expected that only the sculpt files will be in here
if os.path.splitext(f)[1] == '.txt':
# get the shape
shape = pm.ls(sel)[0].getShape().name()
_file = file(os.path.join(path, f), 'r')
info = _file.readlines()
_file.close()
deformer = info[0].strip('\n')
vertex = eval(info[1])
sculptset = cmds.listConnections(deformer + '.message', s=False, d=True)[0]
# clear the set
cmds.sets(cl=sculptset)
# add vertex to the set
cmds.sets(vertex, fe=sculptset)
示例2: creatSphere
def creatSphere(*args):
circleSel = mc.ls(sl=1)[0]
radiusCircle = mc.circle(circleSel, q=1, r=1)
radiusSpere = radiusCircle*.75
particleSphere = mc.polySphere(n='%s_Sphere'%circleSel, r=radiusSpere, sx=float(radiusSpere), sy=float(radiusSpere), ax=[0, 1, 0])[0]
mc.parentConstraint(circleSel, particleSphere, mo=0, w=1)
#mc.parent(particleSphere, circleSel)
mc.setAttr('%s.tx'%particleSphere, 0)
mc.setAttr('%s.ty'%particleSphere, 0)
mc.setAttr('%s.tz'%particleSphere, 0)
mc.setAttr('%s.rx'%particleSphere, 0)
mc.setAttr('%s.ry'%particleSphere, 0)
mc.setAttr('%s.rz'%particleSphere, 0)
mc.setAttr('%s.v'%particleSphere, 0)
mc.select(particleSphere, r=1)
mc.emitter(type='surface', r=4, dx=1, dy=0, dz=0, n='%s_emitter'%circleSel )
mc.particle( n='%s_Particles'%circleSel )
mc.connectDynamic( '%s_Particles'%circleSel, em='%s_emitter'%circleSel )
particlesShape = mc.listRelatives('%s_Particles'%circleSel, s=1)[0]
mc.setAttr('%s.lifespanMode'%particlesShape, 1)
mc.setAttr('%s.lifespan'%particlesShape, 0.4)
mc.setAttr('%s.startFrame'%particlesShape, 1001)
mc.connectControl( 'numText', '%s.rate'%('%s_emitter'%circleSel) )
mc.shadingNode('blinn', n='%s_blinn'%circleSel, asShader=1)
mc.sets( n='%s_blinnSG'%circleSel, renderable=True, noSurfaceShader=True, empty=1)
mc.connectAttr('%s.outColor'%('%s_blinn'%circleSel), '%s.surfaceShader'%('%s_blinnSG'%circleSel))
mc.connectControl( 'myColorIndex', '%s.color'%('%s_blinn'%circleSel) )
mc.connectControl( 'lifeText', '%s.lifespan'%particlesShape )
mc.sets('%s_Particles'%circleSel, e=1, forceElement='%s'%('%s_blinnSG'%circleSel))
示例3: importPolyMesh
def importPolyMesh(name, identifier, jobInfo, parentXform=None, isConstant=False, useDynTopo=False):
cmds.ExocortexAlembic_profileBegin(f="Python.ExocortexAlembic._import.importPolyMesh")
try:
reader = ""
shape = fnt.alembicCreateNode(name, "mesh", parentXform)
cmds.sets(shape, e=True, forceElement="initialShadingGroup")
topoReader = cmds.createNode("ExocortexAlembicPolyMesh")
cmds.connectAttr(topoReader+".outMesh", shape+".inMesh")
cmds.connectAttr(jobInfo.filenode+".outFileName", topoReader+".fileName")
cmds.setAttr(topoReader+".identifier", identifier, type="string")
cmds.setAttr(topoReader+".normals", jobInfo.useNormals)
cmds.setAttr(topoReader+".uvs", jobInfo.useUVs)
if jobInfo.useFaceSets:
cmds.ExocortexAlembic_createFaceSets(o=shape, f=jobInfo.filename, i=identifier)
if useDynTopo:
cmds.connectAttr(jobInfo.timeCtrl+".outTime", topoReader+".inTime")
reader = topoReader
elif not isConstant:
reader = cmds.deformer(shape, type="ExocortexAlembicPolyMeshDeform")[0]
setupReaderAttribute(reader, identifier, isConstant, jobInfo)
#if not useDynTopo:
# setupReaderAttribute(topoReader, identifier, isConstant, jobInfo)
except Exception as ex:
shape = "?importPolyMesh --> exception: \"" + str(ex.args) + "\" of type " + str(type(ex));
apix.MPxCommand.setResult(shape)
cmds.ExocortexAlembic_profileEnd(f="Python.ExocortexAlembic._import.importPolyMesh")
return shape
示例4: perform
def perform(**kwargs):
sel = cmds.ls(sl=True)
sel3=[]
for s in sel:
sel3+=cmds.xform(s,q=True, ws=True, t=True)
pointset=[]
for i in xrange(len(sel3)/3):
pointset+=[Vector(sel3[i*3],sel3[i*3+1],sel3[i*3+2])]
bbox = BBox()
bbox.obbFromPointSet(pointset)
t = Transform(bbox.axis[0],bbox.axis[1],bbox.axis[2])
t = t.transpose()
z = t.getEuler()
cube = cmds.createNode("polyCube")
cubeShape = cmds.createNode("mesh")
cubeTrans = cmds.listRelatives(cubeShape,p=True)[0]
cmds.connectAttr(cube+".output",cubeShape+".inMesh")
cmds.setAttr(cubeTrans+".tx",bbox.center[0])
cmds.setAttr(cubeTrans+".ty",bbox.center[1])
cmds.setAttr(cubeTrans+".tz",bbox.center[2])
cmds.setAttr(cubeTrans+".rz",degrees(z[2]))
cmds.setAttr(cubeTrans+".ry",degrees(z[1]))
cmds.setAttr(cubeTrans+".rx",degrees(z[0]))
cmds.setAttr(cube+".width",bbox.max[0]-bbox.min[0])
cmds.setAttr(cube+".height",bbox.max[1]-bbox.min[1])
cmds.setAttr(cube+".depth",bbox.max[2]-bbox.min[2])
cmds.sets(e=True,forceElement="initialShadingGroup")
cmds.select(sel)
示例5: __setup_sculpt_shader
def __setup_sculpt_shader(self):
#--- this method setups the sculpt shader color
#--- list all the shader names
shader_list = ['sculptShaderGreen']
#--- check if shader exists, else create a new one
for s in range(len(shader_list)):
if cmds.objExists(shader_list[s]):
#--- check which mesh is selected
self.shader = shader_list[0]
self.shader_set = shader_list[0] + '3SG'
else:
#--- create the lambert shader
self.shader = cmds.shadingNode('lambert',
asShader = True,
name = shader_list[0])
self.shader_set = cmds.sets(self.shader,
renderable = True,
noSurfaceShader = True,
empty = True,
name = shader_list[0] + '3SG')
cmds.connectAttr(self.shader + '.outColor',
self.shader_set + '.surfaceShader',
force = True)
#--- change the color
cmds.setAttr(self.shader + '.color', 0, 1, 1)
#--- assign the shader to the sculpt_mesh
cmds.sets(self.sculpt_mesh, forceElement = self.shader_set)
示例6: setDeformerMembership
def setDeformerMembership(self,geoList=[]):
'''
'''
# Check geometry list
if not geoList: geoList = self.deformerData.keys()
# Check deformer
deformer = self.deformerName
if not glTools.utils.deformer.isDeformer(deformer):
raise Exception('Deformer "'+deformer+'" does not exist!')
# Get deformer set
deformerSet = glTools.utils.deformer.getDeformerSet(deformer)
for geo in geoList:
# Get current and stored membership
setMembers = self.deformerData[geo]['membership']
currMembers = glTools.utils.deformer.getDeformerSetMemberIndices(deformer,geo)
removeMembers = list(set(currMembers)-set(setMembers))
# Determine component type
pt = 'cv'
if self.deformerData[geo]['geometryType'] == 'mesh': pt = 'vtx'
# Remove unused
if removeMembers:
mc.sets([geo+'.'+pt+'['+str(i)+']' for i in removeMembers],rm=deformerSet)
# Add remaining members
mc.sets(self.getMemberList([geo]),fe=deformerSet)
示例7: importPolyMesh
def importPolyMesh(name, identifier, jobInfo, parentXform=None, isConstant=False, useDynTopo=False):
cmds.ExocortexAlembic_profileBegin(f="Python.ExocortexAlembic._import.importPolyMesh")
# TODO: set isConstant properly elsewhere when there are no transforms but are
# animated attributes
isConstant = False
try:
reader = ""
shape = fnt.alembicCreateNode(name, "mesh", parentXform)
cmds.sets(shape, e=True, forceElement="initialShadingGroup")
topoReader = cmds.createNode("ExocortexAlembicPolyMesh")
cmds.connectAttr(topoReader+".outMesh", shape+".inMesh")
cmds.connectAttr(jobInfo.filenode+".outFileName", topoReader+".fileName")
cmds.setAttr(topoReader+".identifier", identifier, type="string")
cmds.setAttr(topoReader+".normals", jobInfo.useNormals)
cmds.setAttr(topoReader+".uvs", jobInfo.useUVs)
if jobInfo.useFaceSets:
cmds.ExocortexAlembic_createFaceSets(o=shape, f=jobInfo.filename, i=identifier)
if useDynTopo:
cmds.connectAttr(jobInfo.timeCtrl+".outTime", topoReader+".inTime")
reader = topoReader
elif not isConstant:
reader = cmds.deformer(shape, type="ExocortexAlembicPolyMeshDeform")[0]
setupReaderAttribute(reader, identifier, isConstant, jobInfo)
#if not useDynTopo:
# setupReaderAttribute(topoReader, identifier, isConstant, jobInfo)
except:
return [traceback.format_exc()]
finally:
cmds.ExocortexAlembic_profileEnd(f="Python.ExocortexAlembic._import.importPolyMesh")
return [shape, reader]
示例8: makeStreetTree
def makeStreetTree(shaders):
'''
Creates a tree on a circular platform and with a circular fence around it.
shaders: A list of shaders for the tree crowns.
On exit: A tree has been created using makeTree(...), a circular platform
has been created underneath it and a fence around it. Appropriate
shaders have been assigned. Everything is united into one polygonal
object and returned as a tuple with the object name and the node
name.
'''
tree = makeTree(shaders)
platform = cmds.polyCylinder(name = "platform",h = 0.1, r = 0.8)
cmds.move(0.25, y = True)
cmds.sets(platform[0], edit=True, forceElement="fountainMaterialGroup")
pole = cmds.polyCube(name = "pole", h = 0.6, w = 0.04, d = 0.04)
cmds.xform(pole, t = (0.7,0.45,0))
angle = 360/10.0
for i in range(1,10):
pole1 = cmds.polyCube(name = "pole", h = 0.6, w = 0.04, d = 0.04)
cmds.rotate(angle * i, y = True)
cmds.move(0.7,0.45,0, os = True)
pole = cmds.polyUnite(pole, pole1)
bar = cmds.polyPipe(name = "bar", h = 0.1, r = 0.65, t = 0.04)
cmds.move(0.65, y = True)
bar1 = cmds.duplicate(bar[0])
cmds.move(-0.2, y = True, r = True)
fence = cmds.polyUnite(pole, bar, bar1)
cmds.sets(fence[0], edit=True, forceElement="blackMetalGroup")
streetTree = cmds.polyUnite(tree,platform, fence)
cmds.delete(streetTree, ch = True)
return streetTree
示例9: set_isolate_set
def set_isolate_set(selected):
set_name = get_isolate_set_name()
# Trying to hide visible children in hierarchy to get wanted isolate
# behavior.
for sel in selected:
for child in sel.iterchildren():
if child in selected or not child.type == MFn.kTransform:
continue
# Only work on visible children
if child.attr['visibility']:
child.attr['visibility'] = False
HIDDEN_CHILDREN.add(child)
hilited = DagpathList(
[dag for dag in mampy.daglist(hl=True) if dag not in selected]
)
if hilited:
cmds.hilite(hilited.cmdslist(), toggle=True)
# In case the dag object was a child of unhilited object rehilite it.
for dag in selected:
cmds.hilite(str(dag))
if not set_name:
for dag in selected:
cmds.isolateSelect(get_active_panel(), addDagObject=str(dag))
return
cmds.sets(clear=set_name)
cmds.sets(selected.cmdslist(), include=set_name)
示例10: makeFountain
def makeFountain():
'''
Creates a fountain.
On exit: A fountain shaped polygonal object has been created, assigned a shader
and is returned as a tuple with the object name and node name. The
procedure uses random numbers in order to create different looking fountains
every time it is called.
'''
steps = random.randint(1,3)
fountain = cmds.polyCylinder(name = "Fountain", h = 0.1)
cmds.xform(fountain, translation = (0, 0.25, 0))
cmds.select(fountain[0] + ".f[40:59]")
for i in range(steps):
scale_ = random.uniform(0.6, 0.95)
cmds.polyExtrudeFacet(scale = (scale_, scale_, scale_))
translation = random.uniform(0.1, 0.6)
cmds.polyExtrudeFacet(translate = (0, translation, 0))
cmds.polyExtrudeFacet(scale = (0.9,0.9,0.9))
cmds.polyExtrudeFacet(translate = (0, -0.3,0))
scale_ = random.uniform(0.3,0.6)
cmds.polyExtrudeFacet(scale = (scale_,scale_,scale_))
translation = random.uniform(0.2,0.4)
cmds.polyExtrudeFacet(translate = (0,translation,0))
stepsUp = random.randint(1,3)
for i in range(stepsUp):
scale_ = random.uniform(0.4,0.9)
cmds.polyExtrudeFacet(scale = (scale_,scale_,scale_))
translation = random.uniform(0.05,1)
cmds.polyExtrudeFacet(translate = (0,translation,0))
top = fountainTop(fountain) # Create a top for the fountain.
fountain = cmds.polyUnite(top[0],fountain)
cmds.sets(fountain[0], edit=True, forceElement="fountainMaterialGroup")
return fountain
示例11: makeTree
def makeTree(shaders):
'''
Creates a tree.
shaders: A list of shaders for the tree crown.
On exit: A tree has been modeled, and is returned as a tuple
containing the object name and the node name. Some of the
variables are chosen randomly to create different results.
'''
height = random.uniform(0.3,1.5)
trunk = cmds.polyCylinder(name = "trunk", h = height, r = 0.07)
cmds.sets(trunk[0], edit=True, forceElement="trunkMaterialGroup")
cmds.xform(trunk, translation = (0,height/2.0 + 0.2,0))
crown = cmds.polySphere(name = "crown", r = 0.5)
cmds.xform(crown, translation = (0,height + 0.6,0))
cmds.softSelect(sse = True, ssd = 0.86)
cmds.select(crown[0] + ".vtx[381]")
translation = random.uniform(0.3,1.5)
cmds.move(translation, y = True, r = True)
cmds.softSelect(sse = False)
shader = random.choice(shaders)
scale_ = random.uniform(0.7,1.8)
cmds.select(crown)
cmds.scale(scale_, scale_, scale_, pivot = (0,height,0))
cmds.sets(crown[0], edit=True, forceElement= shader[1])
tree = cmds.polyUnite(trunk[0],crown[0])
cmds.delete(tree[0], ch = True)
return tree
示例12: addLocators
def addLocators(factory=None, group="", locators=[]):
if not factory: factory = MayaFactory.MayaFactory()
if not group and not locators:
selection = mc.ls(sl=True)
if len(selection) < 2:
raise Errors.BadArgumentError("Please select some objects to turn into Massive locators, and a massive group.")
group = selection[-1]
locators = selection[0:-1]
addLocators(group, locators)
else:
if not group or not locators:
raise Errors.BadArgumentError("Please select some objects to turn into Massive locators, and a massive group.")
if not isGroup(group):
raise Errors.BadArgumentError("%s is not a massive group." % group)
if factory.isGroupsSet(group):
raise Errors.BadArgumentError("%s can not have locators added to it." % group)
for locator in locators:
try:
mc.xform(locator, query=True, worldSpace=True, translation=True)
except:
raise Errors.BadArgumentError("%s can not be turned into a Massive locator.\n" +
"Please select items whose transformation is accessible through the 'xform' command." % locator)
if not mc.objExists("%s.massive" % locator):
mc.addAttr(locator, longName="massive", attributeType="long")
mc.sets(locators, add=group)
示例13: combineShader
def combineShader( shaderList ):
cmds.undoInfo( ock=1 )
targetObjs = []
for shader in shaderList:
cmds.hyperShade( objects = shader )
targetObjs += cmds.ls( sl=1 )
shadingEngines = cmds.listConnections( shaderList, s=0, d=1, type='shadingEngine' )
if not shadingEngines: return None
shadingEngines = list( set( shadingEngines ) )
targetShadingEngine = shadingEngines[0]
cmds.sets( targetObjs, e=1, forceElement = targetShadingEngine )
cmds.delete( shadingEngines[1:] )
for shader in shaderList:
shadingEngines = cmds.listConnections( shader, s=0, d=1, type='shadingEngine' )
if not shadingEngines:
cmds.delete( shader )
elif not targetShadingEngine in shadingEngines:
cmds.delete( shader, shadingEngines )
Window_global.nodeInfomation = {}
cmds.undoInfo( cck=1 )
示例14: load_shader
def load_shader(self, look_file, shader_file, ref=True):
if not os.path.isfile(look_file) and not os.path.isfile(shader_file):
return False
asset_ref_name = self.asset_name()
asset_ref_name += '_Shad'
# 用引用的方式导入材质文件,如果引用已经存在,无需导入
if not mc.objExists(asset_ref_name + 'RN'):
if ref:
mc.file(shader_file, r=True, ignoreVersion=True, mergeNamespacesOnClash=False, gl=True,
namespace=asset_ref_name, options='v=0;p=17;f=0', typ='mayaBinary', pr=True)
else:
mc.file(shader_file, i=True, ignoreVersion=True, mergeNamespacesOnClash=False,
namespace=asset_ref_name, options='v=0;p=17;f=0', typ='mayaBinary', pr=True)
else:
print('Shader is loaded.')
# 读入材质链接信息,讲材质赋给模型
with open(look_file) as f:
data = json.loads(f.read())
link_list = data['shader_link']
for k in link_list.keys():
for s in link_list[k]:
sg_name = '%s:%s' % (asset_ref_name, s)
if mc.objExists(k):
mc.sets(k, e=1, forceElement=sg_name)
print("Assign shader %s to %s." % (sg_name, k))
else:
asset_n = k.split('|')[0]
this_obj = k.replace(asset_n, self.__name)
if mc.objExists(this_obj):
mc.sets(k, e=1, forceElement=sg_name)
print("Assign shader %s to %s." % (sg_name, this_obj))
print('Load shader for %s successful.' % self.name())
return True
示例15: copyShader_multi
def copyShader_multi( inputFirst, inputSeconds ):
first = pymel.core.ls( inputFirst )[0]
if not pymel.core.objExists( first ): return None
try:firstShape = first.getShape()
except:firstShape = first
engines = firstShape.listConnections( type='shadingEngine' )
if not engines: return None
engines = list( set( engines ) )
copyObjAndEngines = []
seconds = [ pymel.core.ls( inputSecond )[0] for inputSecond in inputSeconds ]
for engine in engines:
srcCons = filter( lambda x : x.longName() in ['message', 'outColor'], engine.listConnections( s=1, d=0, p=1 ) )
if not srcCons: continue
pymel.core.hyperShade( objects = srcCons[0].node() )
selObjs = pymel.core.ls( sl=1 )
targetObjs = []
for selObj in selObjs:
if selObj.node() != firstShape: continue
if selObj.find( '.' ) != -1:
for second in seconds:
targetObjs.append( second+'.'+ selObj.split( '.' )[-1] )
else:
for second in seconds:
targetObjs.append( second )
if not targetObjs: continue
for targetObj in targetObjs:
cmds.sets( targetObj, e=1, forceElement=engine.name() )
copyObjAndEngines.append( [targetObj, engine.name()] )
return copyObjAndEngines