本文整理汇总了Python中pymel.core.connectAttr函数的典型用法代码示例。如果您正苦于以下问题:Python connectAttr函数的具体用法?Python connectAttr怎么用?Python connectAttr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_dominant_color_shader
def create_dominant_color_shader(dag, tex_name_surfix=['co', 'color', 'diffuse', 'dif', 'base'],
sample_rate=None, max_auto_sample=50,
default_shader='aiStandardSurface', default_channel='baseColor'):
"""
Create an auto average-color lambert shader and assign it to input object.
Maybe does not work with TIFF texture ( cannot extract color ).
"""
if type(dag) == pm.nodetypes.Transform:
mesh = dag.getShape()
if not type(mesh) == pm.nodetypes.Mesh:
return None
elif type(dag) == pm.nodetypes.Mesh:
mesh = dag
else:
return None
avg_color = _detect_dominant_color(mesh, tex_name_surfix, sample_rate,
max_auto_sample, default_shader, default_channel)
if not avg_color:
return None
color_shader, sg = pm.createSurfaceShader('lambert')
color_shader.color.set(avg_color)
pm.connectAttr(color_shader.color, sg.surfaceShader, f=1)
pm.sets(sg, forceElement=mesh)
return color_shader
示例2: createBoundJointConstraintsAndConnectVisibility
def createBoundJointConstraintsAndConnectVisibility(self):
pm.select(cl = True)
#bound joint constraint list
self.boundJointConstraintList = []
#iterate bound joint list and create orient constraint for each
for index in range(len(self.boundJointsList)):
pm.select(cl = True)
self.boundJointConstraintList.append(pm.orientConstraint(self.ikSplineJointsList[index], self.ikDynamicJointsList[index], self.boundJointsList[index], mo = True))
pm.select(cl = True)
#create reverse node
self.orientConstraintWeight_reverse = pm.createNode('reverse')
pm.select(cl = True)
#connect to manip dynamic blend
self.manip_dynamic.manualDynamicBlend >> self.orientConstraintWeight_reverse.inputX
pm.select(cl = True)
#Connect Constraints to manip_dynamic
for index in range(len(self.boundJointConstraintList)):
pm.select(cl = True)
pm.connectAttr(self.orientConstraintWeight_reverse.outputX, self.boundJointConstraintList[index].name() +'.' +self.ikSplineJointsList[index].name() +'W0', f = True)
pm.connectAttr(self.manip_dynamic.manualDynamicBlend, self.boundJointConstraintList[index].name() +'.' +self.ikDynamicJointsList[index].name() +'W1', f = True)
pm.select(cl = True)
#Visibility
self.orientConstraintWeight_reverse.outputX >> self.manipIkSplineTopGrp.visibility
示例3: stretchyBack
def stretchyBack( ikHandleTorso, jntList ):
pymelLogger.debug('Starting: stretchyBack()...')
#Stretchy process
# ArcLen to create curveInfo
curveInfoNodeBack = pm.arclen( ikHandleTorso[2], ch=True )
# add attr to curveinfo Node (normalizedScale)
# this will have a value coming from a multiply divide node that will be
# dividing the current length by the initial length of the curve
# this will be used later to scale the joints
pm.addAttr(curveInfoNodeBack, longName='normalizedScale', attributeType='double')
# get initial length of the curve
iniLen = pm.getAttr( curveInfoNodeBack + '.arcLength' )
# create a node multiplydivide, operation set to division
MDCurveBack = pm.shadingNode( 'multiplyDivide', asUtility=True )
pm.setAttr( MDCurveBack+'.operation', 2 ) # divide
# Connect curve arcLength to input1X
pm.connectAttr( curveInfoNodeBack + '.arcLength', MDCurveBack + '.input1X', force=True )
# Set input2X to initial length of the curve
pm.setAttr(MDCurveBack+'.input2X', iniLen)
# connect outpux x from multiplydivide to normalized scale of the curve info
pm.connectAttr(MDCurveBack + '.outputX', curveInfoNodeBack + '.normalizedScale', force=True)
returnList = [curveInfoNodeBack,MDCurveBack]
pymelLogger.debug('End: stretchyBack()...')
return returnList
示例4: fetch_attr
def fetch_attr(self, source, target):
if source is None:
return
elif isinstance(source, pymel.Attribute):
pymel.connectAttr(source, target)
else:
target.set(source)
示例5: addAOV
def addAOV( aovName, aovType = None ):
"""docstring for addAov"""
if aovType is None:
aovType = aovs.getAOVTypeMap().get(aovName, 'rgba')
if not isinstance(aovType, int):
aovType = dict(aovs.TYPES)[aovType]
aovNode = pm.createNode('aiAOV', name='aiAOV_' + aovName, skipSelect=True)
out = aovNode.attr('outputs')[0]
pm.connectAttr('defaultArnoldDriver.message', out.driver)
filter = aovs.defaultFiltersByName.get(aovName, None)
if filter:
node = pm.createNode('aiAOVFilter', skipSelect=True)
node.aiTranslator.set(filter)
filterAttr = node.attr('message')
import mtoa.hooks as hooks
hooks.setupFilter(filter, aovName)
else:
filterAttr = 'defaultArnoldFilter.message'
pm.connectAttr(filterAttr, out.filter)
aovNode.attr('name').set(aovName)
aovNode.attr('type').set(aovType)
base = pm.PyNode('defaultArnoldRenderOptions')
aovAttr = base.aovs
nextPlug = aovAttr.elementByLogicalIndex(aovAttr.numElements())
aovNode.message.connect(nextPlug)
aov = aovs.SceneAOV(aovNode, nextPlug)
return aov
示例6: addAOV
def addAOV(self, aovName, aovType=None):
'''
add an AOV to the active list for this AOV node
returns the created AOV node
'''
if aovType is None:
aovType = getAOVTypeMap().get(aovName, 'rgba')
if not isinstance(aovType, int):
aovType = dict(TYPES)[aovType]
aovNode = pm.createNode('aiAOV', name='aiAOV_' + aovName, skipSelect=True)
out = aovNode.attr('outputs')[0]
pm.connectAttr('defaultArnoldDriver.message', out.driver)
filter = defaultFiltersByName.get(aovName, None)
if filter:
node = pm.createNode('aiAOVFilter', skipSelect=True)
node.aiTranslator.set(filter)
filterAttr = node.attr('message')
import mtoa.hooks as hooks
hooks.setupFilter(filter, aovName)
else:
filterAttr = 'defaultArnoldFilter.message'
pm.connectAttr(filterAttr, out.filter)
aovNode.attr('name').set(aovName)
aovNode.attr('type').set(aovType)
nextPlug = self.nextAvailableAttr()
aovNode.message.connect(nextPlug)
aov = SceneAOV(aovNode, nextPlug)
addAliases([aov])
return aov
示例7: Connect
def Connect(src, dst):
pm.undoInfo(openChunk=True)
alembics = src
if not isinstance(src, list):
alembics = pm.ls(src, dagObjects=True, type='transform')
targets = dst
if not isinstance(dst, list):
targets = pm.ls(dst, dagObjects=True, type='transform')
attrs = ['translate', 'rotate', 'scale', 'visibility']
for node in targets:
for abc in alembics:
if node.longName().split(':')[-1] == abc.longName().split(':')[-1]:
for attr in attrs:
pm.connectAttr('%s.%s' % (abc, attr),
'%s.%s' % (node, attr),
force=True)
# securing primary shape is connected
pm.connectAttr('%s.worldMesh[0]' % abc.getShape(),
'%s.inMesh' % node.getShape(),
force=True)
pm.undoInfo(closeChunk=True)
示例8: connect_or_set_attr
def connect_or_set_attr(_attr, _val):
if isinstance(_val, list) or isinstance(_val, tuple):
# Note: List attribute and compound attribute don't have the same way of iterating.
if _attr.isArray():
for i, val in enumerate(_val):
connect_or_set_attr(_attr.elementByLogicalIndex(i), val)
elif _attr.isCompound():
children = _attr.getChildren()
for child, val in zip(children, _val):
connect_or_set_attr(child, val)
else:
raise Exception("Can't apply value {0} on attribute {1}, need an array or compound".format(_val, _attr))
'''
for i, pSubValue in enumerate(_val):
ConnectOrSetAttr(_attr.elementByLogicalIndex(i), pSubValue)
'''
else:
if isinstance(_val, pymel.Attribute):
pymel.connectAttr(_val, _attr, force=True)
elif is_basic_type(_val):
_attr.set(_val)
else:
logging.error(
'[ConnectOrSetAttr] Invalid value for attribute {0} of type {1} and value {2}'.format(_attr.name(),
type(_val),
_val))
raise TypeError
示例9: main
def main():
prefRun()
center = pm.ikHandle(name="centerIK", startJoint="center1", endEffector="center13", sol="ikSplineSolver",ns=3)
left = pm.ikHandle(name="leftIK", startJoint="left1", endEffector="left13", sol="ikSplineSolver",ns=3)
right = pm.ikHandle(name="rightIK", startJoint="right1", endEffector="right13", sol="ikSplineSolver",ns=3)
pm.rename(center[2], "center_crv")
pm.rename(left[2], "left_crv")
pm.rename(right[2], "right_crv")
clusterGrp_center = clusterCurve("center_crv")
clusterGrp_left = clusterCurve("left_crv")
clusterGrp_right = clusterCurve("right_crv")
pm.connectAttr("jacketRight1.rz", clusterGrp_right+".rz")
pm.connectAttr("jacketLeft1.rz", clusterGrp_left+".rz")
pm.parent("center_crv", "rig")
pm.parent("left_crv", "rig")
pm.parent("right_crv", "rig")
pm.parent(clusterGrp_center, "world_ctrl")
pm.parent(clusterGrp_left, "world_ctrl")
pm.parent(clusterGrp_right, "world_ctrl")
for i in ["centerIK", "leftIK", "rightIK"]:
pm.setAttr(i+".visibility", 0)
pm.parent(i, "rig")
for i in ['center_crv','left_crv','right_crv','center_crv_cv0_loc', 'left_crv_cv0_loc', 'right_crv_cv0_loc', 'pageTargets_grp', 'pages_grp', 'jacket_grp']:
pm.setAttr(i+".visibility", 0)
示例10: create_render_cam
def create_render_cam(name="RENDER_CAM", exposure=True):
"""
Creates a camera and renames it
str name: name of the camera
bool exposure: connect a mia_exposure_photographic node to the camera
"""
if not pm.objExists(name):
cam = pm.camera()[0]
pm.rename(cam, name)
[cam.renderable.set(cam.name().startswith(name)) for cam in pm.ls(cameras=True)]
cam = pm.PyNode(name)
if exposure:
if not cam.miLensShader.isConnected():
node = pm.createNode("mia_exposure_photographic")
node.film_iso.set(800)
node.f_number.set(1.2)
node.gamma.set(1)
pm.connectAttr(node.message, cam.miLensShader, force=True)
cam.getShape().setDisplayResolution(True)
pm.lookThru(name)
pm.select(cam)
示例11: connectAttr_withLinearDrivenKeys
def connectAttr_withLinearDrivenKeys(attr_src, attr_dst, type='animCurveUU', force=True, kt=(-1.0,0.0,1.0), kv=(-1.0,0.0,1.0), kit=(4,2,4), kot=(4,2,4), pre='linear', pst='linear'):
# Skip if a connection already exist
for node in getAttrOutput(attr_src, plugs=False, skipBlendWeighted=True):
if 'animCurveU' in node.type():
drivenkey_outplugs = getAttrOutput(node.output, plugs=True, skipBlendWeighted=True)
for drivenkey_outplug in drivenkey_outplugs:
if drivenkey_outplug == attr_dst:
if force:
pymel.disconnectAttr(node.input)
pymel.disconnectAttr(node.output)
pymel.delete(node)
else:
print("Can't connect. Attribute {0} is already connected to {1} via {2}".format(
attr_src.longName(),
attr_dst.longName(),
drivenkey_outplug.node().longName()
))
return
animCurve = create_animCurveU('animCurveUU',
kt=kt,
kv=kv,
kit=kit, # Spline/Linear/Spline
kot=kot, # Spline/Linear/Spline
pre=pre,
pst=pst
)
animCurve.rename('{0}_{1}'.format(attr_src.node().name(), attr_src.longName()))
pymel.connectAttr(attr_src, animCurve.input)
return connectAttr_withBlendWeighted(animCurve.output, attr_dst)
示例12: create_compound_ctrl
def create_compound_ctrl(self, cls, inst, suffix, attr_inn_name, attr_out_name, **kwargs):
"""
Initialize and build and connect a controller used in the Compound.
:param cls: The desired class for the controller.
:param inst: The current instance.
:param suffix: A str that identify this controller.
:param attr_inn_name: The name of the network attribute that receive the controller local matrix.
:param attr_out_name: The name of the network attribute that will drive the controller offset world matrix.
:param kwargs: Any keyword argument will be passed to the controller .build() method.
:return: A controller instance of the desired type.
"""
attr_inn = self.grp_inn.attr(attr_inn_name)
attr_out = self.grp_out.attr(attr_out_name)
nomenclature_anm = self.get_nomenclature_anm()
inst = self.init_ctrl(cls, inst)
ref_tm = attr_out.get()
inst.build(
name=nomenclature_anm.resolve(suffix),
geometries=self.rig.get_meshes(),
refs=[ref_tm],
**kwargs
)
inst.setParent(self.grp_anm)
pymel.connectAttr(inst.matrix, attr_inn)
_connect_matrix_attr_to_transform(attr_out, inst.offset)
return inst
示例13: createSubdivApproxNode
def createSubdivApproxNode():
'''
copy of createApproxNode from mentalrayApproxEditor.mel
node will be named "mathildaSubdivApprox"
'''
# delete existing node if exists
nodeName = 'mathildaSubdivApprox'
# make sure mental ray is loaded first
if not pm.pluginInfo('Mayatomr', q=True, loaded=True):
pm.loadPlugin('Mayatomr', qt=True)
# create approx node
approxNode = pm.createNode('mentalraySubdivApprox', n=nodeName)
# get listNode
try:
mrItemsListNode = pm.ls(type='mentalrayItemsList')[0]
except IndexError:
mrItemsListNode = pm.createNode('mentalrayItemsList', n='mentalrayItemsList')
# connect approx to list
pm.connectAttr(approxNode.message, mrItemsListNode.subdivApproxs, na=True)
return approxNode
示例14: create_ibl
def create_ibl(* args):
'''
# creates an ibl
'''
my_ibl = pm.shadingNode('mentalrayIblShape', asLight= True)
pm.connectAttr('%s.message' % (my_ibl),
'mentalrayGlobals.imageBasedLighting', force= True)
pm.setAttr('%s.primaryVisibility' % (my_ibl), 1)
pm.setAttr('%s.visibleInReflections' % (my_ibl), 1)
pm.setAttr('%s.visibleInRefractions' % (my_ibl), 1)
pm.setAttr('%s.visibleInEnvironment' % (my_ibl), 1)
pm.setAttr('%s.visibleInFinalGather' % (my_ibl), 1)
scene_objects = pm.ls(type= ['mesh', 'nurbsSurface', 'volumeLight',
'spotLight', 'directionalLight','areaLight',
'pointLight', 'ambientLight'])
bounding_box = pm.exactWorldBoundingBox(scene_objects)
bounding_box.sort()
ibl_size = bounding_box[-1]
pm.setAttr('%s.scaleX' % (my_ibl), ibl_size)
pm.setAttr('%s.scaleY' % (my_ibl), ibl_size)
pm.setAttr('%s.scaleZ' % (my_ibl), ibl_size)
return my_ibl
示例15: CreateFKControl
def CreateFKControl(self, _joint, _parent, _moduleContainer):
jointName = utils.StripAllNamespaces(_joint)[1]
containedNodes = []
name = "%s_fkControl" %jointName
controlObjectInstance = controlObject.ControlObject()
fkControlInfo = controlObjectInstance.Create(name, "sphere.ma", self, _lod = 1, _translation = False, _rotation = True, _globalScale = False, _spaceSwitching = False)
fkControl = fkControlInfo[0]
pm.connectAttr("%s.rotateOrder" %_joint, "%s.rotateOrder" %fkControl)
orientGrp = pm.group(name = "%s_orientGrp", empty = True, parent = _parent)
containedNodes.append(orientGrp)
pm.delete(pm.parentConstraint(_joint, orientGrp, maintainOffset = False))
jointParent = pm.listRelatives(_joint, parent = True)[0]
orientGrp_parentConstraint = pm.parentConstraint(jointParent, orientGrp, maintainOffset = True, name = "%s_parentConstraint" %orientGrp)
orientGrp_scaleConstraint = pm.scaleConstraint(jointParent, orientGrp, maintainOffset = True, name = "%s_scaleConstraint" %orientGrp)
pm.parent(fkControl, orientGrp, relative = True)
orientConstraint = pm.orientConstraint(fkControl, _joint, maintainOffset = False, name = "%s_orientConstraint" %_joint)
containedNodes.extend([orientGrp_parentConstraint, orientGrp_scaleConstraint, orientConstraint])
utils.AddNodeToContainer(_moduleContainer, containedNodes)
return fkControl