Exemplo n.º 1
0
def unitConversion(plug,conversionFactor=1.0,conversionFactorSourcePlug='',plugIsSource=True,prefix=''):
	'''
	Create a unit conversion node for the given destination attribute
	@param plug: Plug to be connected to the unitConversion node
	@type plug: str
	@param conversionFactor: Conversion factor value
	@type conversionFactor: float
	@param conversionFactorSourcePlug: Plug to supply incoming connection for conversion factor
	@type conversionFactorSourcePlug: str
	@param plugIsSource: Specifies the plug as either the source or destination of the unitConversion
	@type plugIsSource: bool
	@param prefix: Name prefix for newly created nodes
	@type prefix: str
	'''
	# Check plug
	if not mc.objExists(plug): raise UserInputError('Plug '+plug+' does not exist!!')
	if not plug.count('.'): raise UserInputError('Object '+plug+' is not a valid plug (node.attr)!!')
	
	# Check conversionFactorSourcePlug
	if conversionFactorSourcePlug:
		if not mc.objExists(conversionFactorSourcePlug):
			raise UserInputError('Conversion factor source plug '+conversionFactorSourcePlug+' does not exist!')
	
	# Check prefix
	if not prefix: prefix = stringUtils.stripSuffix(control.split('.')[0])
	
	# Get existing plug connections
	conns = mc.listConnections(plug,s=not plugIsSource,d=plugIsSource,p=True)
			
	# Create unitConversion node
	unitConversion = mc.createNode('unitConversion',n=prefix+'_unitConversion')
	mc.setAttr(unitConversion+'.conversionFactor',conversionFactor)
	
	# Connect conversion factor
	if conversionFactorSourcePlug:
		mc.connectAttr(conversionFactorSourcePlug,unitConversion+'.conversionFactor',f=True)
	
	# Connect plug
	if plugIsSource:
		mc.connectAttr(plug,unitConversion+'.input',f=True)
	else:
		if conns: mc.connectAttr(conns[0],unitConversion+'.input',f=True)
	
	# Connect to destination plugs
	if plugIsSource:
		if conns:
			for conn in conns: mc.connectAttr(unitConversion+'.output',conn,f=True)
	else:
		mc.connectAttr(unitConversion+'.output',plug,f=True)
	
	# Return result
	return unitConversion
Exemplo n.º 2
0
def group_old(control,groupType=1,center=True,orient=True):
	'''
	Create a group centered and oriented to the specified control.
	@param control: Control to group
	@type control: str
	@param groupType: Specify type of buffer. 0=Group:"*_grp", 1=Buffer:"*_buf", 2=BufferJoint:"*_bfj"
	@type groupType: int
	@param center: Match group pivot to transform
	@type center: bool
	@param orient: Orient group to transform
	@type orient: bool
	'''
	# Check groupType
	if not range(3).count(groupType):
		raise UserInputError('Invalid groupType value supplied!!('+str(groupType)+')')
	
	# Generate group name
	prefix = stringUtils.stripSuffix(control)
	grp = prefix+'_'+grpType
	
	# Create Group
	if groupType == 2: grp = mc.createNode('joint',n=grp)
	else: grp = mc.createNode('transform',n=grp)
	
	# Align to object
	grp = mc.parent(grp,control)[0]
	mc.makeIdentity(grp,apply=True,t=1,r=orient,s=1,jo=1,n=0)
	
	# Correct heirarchy
	parent = mc.listRelatives(control,p=True,pa=True)
	if parent: grp = mc.parent(grp,parent[0])[0]
	else: grp = mc.parent(grp,w=1)[0]
	# Reset transform scale values
	mc.makeIdentity(grp,apply=True,t=0,r=0,s=1,n=0)
	control = mc.parent(control,grp)[0]
	
	# Center pivot
	if center:
		piv = mc.xform(control,q=True,ws=True,rp=True)
		mc.xform(grp,piv=piv,ws=True)
	
	# Return group name as result string
	return grp