#NEWLINE# def rivet( ) : #NEWLINE# #INDENT# 'the python version of the famous rivet setup from Bazhutkin\n    ' #NEWLINE# selection_list = pm . filterExpand ( sm = 32 ) #NEWLINE# if ( ( selection_list is not None ) and ( len ( selection_list ) > 0 ) ) : #NEWLINE# #INDENT# size = len ( selection_list ) #NEWLINE# if ( size != 2 ) : #NEWLINE# #INDENT# raise pm . MayaObjectError ( 'No two edges selected' ) #NEWLINE# #UNINDENT# edge1 = pm . PyNode ( selection_list [ 0 ] ) #NEWLINE# edge2 = pm . PyNode ( selection_list [ 1 ] ) #NEWLINE# edge1Index = edge1 . indices ( ) [ 0 ] #NEWLINE# edge2Index = edge2 . indices ( ) [ 0 ] #NEWLINE# shape = edge1 . node ( ) #NEWLINE# cFME1 = pm . createNode ( 'curveFromMeshEdge' , n = 'rivetCurveFromMeshEdge#' ) #NEWLINE# cFME1 . setAttr ( 'ihi' , 1 ) #NEWLINE# cFME1 . setAttr ( 'ei[0]' , edge1Index ) #NEWLINE# cFME2 = pm . createNode ( 'curveFromMeshEdge' , n = 'rivetCurveFromMeshEdge#' ) #NEWLINE# cFME2 . setAttr ( 'ihi' , 1 ) #NEWLINE# cFME2 . setAttr ( 'ei[0]' , edge2Index ) #NEWLINE# loft = pm . createNode ( 'loft' , n = 'rivetLoft#' ) #NEWLINE# loft . setAttr ( 'ic' , s = 2 ) #NEWLINE# loft . setAttr ( 'u' , 1 ) #NEWLINE# loft . setAttr ( 'rsn' , 1 ) #NEWLINE# pOSI = pm . createNode ( 'pointOnSurfaceInfo' , n = 'rivetPointOnSurfaceInfo#' ) #NEWLINE# pOSI . setAttr ( 'turnOnPercentage' , 1 ) #NEWLINE# pOSI . setAttr ( 'parameterU' , 0.5 ) #NEWLINE# pOSI . setAttr ( 'parameterV' , 0.5 ) #NEWLINE# ( loft . attr ( 'os' ) >> pOSI . attr ( 'is' ) ) #NEWLINE# ( cFME1 . attr ( 'oc' ) >> loft . attr ( 'ic[0]' ) ) #NEWLINE# ( cFME2 . attr ( 'oc' ) >> loft . attr ( 'ic[1]' ) ) #NEWLINE# ( shape . attr ( 'w' ) >> cFME1 . attr ( 'im' ) ) #NEWLINE# ( shape . attr ( 'w' ) >> cFME2 . attr ( 'im' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# selection_list = pm . filterExpand ( sm = 41 ) #NEWLINE# if ( ( selection_list is not None ) and ( len ( selection_list ) > 0 ) ) : #NEWLINE# #INDENT# size = len ( selection_list ) #NEWLINE# if ( size != 1 ) : #NEWLINE# #INDENT# raise pm . MayaObjectError ( 'No one point selected' ) #NEWLINE# #UNINDENT# point = pm . PyNode ( selection_list [ 0 ] ) #NEWLINE# shape = point . node ( ) #NEWLINE# u = float ( point . name ( ) . split ( '][' ) [ 0 ] . split ( '[' ) [ 1 ] ) #NEWLINE# v = float ( point . name ( ) . split ( '][' ) [ 1 ] . split ( ']' ) [ 0 ] ) #NEWLINE# pOSI = pm . createNode ( 'pointOnSurfaceInfo' , n = 'rivetPointOnSurfaceInfo#' ) #NEWLINE# pOSI . setAttr ( 'turnOnPercentage' , 0 ) #NEWLINE# pOSI . setAttr ( 'parameterU' , u ) #NEWLINE# pOSI . setAttr ( 'parameterV' , v ) #NEWLINE# ( shape . attr ( 'ws' ) >> pOSI . attr ( 'is' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise pm . MayaObjectError ( 'No edges or point selected' ) #NEWLINE# #UNINDENT# #UNINDENT# locator = pm . spaceLocator ( n = 'rivet#' ) #NEWLINE# aimCons = pm . createNode ( 'aimConstraint' , p = locator , n = ( locator . name ( ) + '_rivetAimConstraint#' ) ) #NEWLINE# aimCons . setAttr ( 'tg[0].tw' , 1 ) #NEWLINE# aimCons . setAttr ( 'a' , ( 0 , 1 , 0 ) ) #NEWLINE# aimCons . setAttr ( 'u' , ( 0 , 0 , 1 ) ) #NEWLINE# aimCons . setAttr ( 'v' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'tx' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'ty' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'tz' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'rx' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'ry' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'rz' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'sx' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'sy' , k = 0 ) #NEWLINE# aimCons . setAttr ( 'sz' , k = 0 ) #NEWLINE# ( pOSI . attr ( 'position' ) >> locator . attr ( 'translate' ) ) #NEWLINE# ( pOSI . attr ( 'n' ) >> aimCons . attr ( 'tg[0].tt' ) ) #NEWLINE# ( pOSI . attr ( 'tv' ) >> aimCons . attr ( 'wu' ) ) #NEWLINE# ( aimCons . attr ( 'crx' ) >> locator . attr ( 'rx' ) ) #NEWLINE# ( aimCons . attr ( 'cry' ) >> locator . attr ( 'ry' ) ) #NEWLINE# ( aimCons . attr ( 'crz' ) >> locator . attr ( 'rz' ) ) #NEWLINE# pm . select ( locator ) #NEWLINE# return locator