I am new to Maya and Python Scripting. Here is my question, Need to get all nodes of the objects (there can be multiple objects) from the scene, to identify the non-smooth node and to update the division values (0, 1 or 2) for the objects using python scripting. I searched regarding this in the. Python 例 import maya.cmds as cmds cmds.sphere( n='sphere' ) # Set a simple numeric value cmds.setAttr( 'sphere.translateX', 5 ) # Lock an attribute to prevent further modification cmds.setAttr( 'sphere.translateX', lock=True ) # Make an attribute unkeyable cmds.setAttr( 'sphere.translateZ', keyable=False ) # Set an entire list of multi.
Import maya.cmds as mc from math import pow def chboxspeed ( HUD,. args ): v = mc.
HudSliderButton ( HUD, query = True, v = True ) nv = pow ( 10, v ) mc. ChannelBox ( 'mainChannelBox', edit = True, spd = nv ) if nv 0: mc. ChannelBox ( 'mainChannelBox', edit = True, spd = chboxspeedvalue ) mc. HeadsUpDisplay ( 'HUDchboxspeed', rem = 1 ) chboxspeedvalue = mc. ChannelBox ( 'mainChannelBox', query = True, spd = 1 ) hud = mc.
HudSliderButton ( 'HUDchboxspeed', s = 2, b = 5, vis = True, sl = 'speed', value = 0, type = 'int', min =- 6, max = 6, slw = 50, vw = 50, sln = 100, si = 1, bl = 'reset&delete', bw = 80, bsh = 'rectangle', brc = lambda: chboxspeed ( 'HUDchboxspeed', 'delete' ), sdc = lambda: chboxspeed ( 'HUDchboxspeed' )) Reconnect motion paths. ' reconnects selected objects with motion paths to a a given curve select objects driven by motion path and path last ' import maya.cmds as mc objs = mc.
Ls ( sl = 1, l = 1 ) curveShp = mc. ListRelatives ( objs - 1 ) 0 for o in objs : - 1 : mp = mc. ListConnections ( o + '.specifiedManipLocation' ) 0 if mc. NodeType ( o ) 'motionPath': mp = o if mc. NodeType ( mp ) 'motionPath': mc.
ConnectAttr ( curveShp + '.worldSpace0', mp + '.geometryPath', f = 1 ) else: warning ( ' n No motion path found on ' + o ) Match translates and pivotsSets translates/rotates/scales and pivots of selected objects to the last selected object. # sets the pivots and transforms of objects to last object of selection, using parents and freeze transforms # remember to delete history import maya.cmds as mc objs = mc. Ls ( sl = 1 ) target = objs - 1 targetPivot = mc. Xform ( target, q = 1, ws = 1, rp = 1 ) for o in objs : - 1 : parentObj = mc. ListRelatives ( o, parent = 1 ) mc.
Parent ( o, target ) mc. MakeIdentity ( o, a = 1,) mc.
Xform ( o, ws = 1, rp = targetPivot 0 , targetPivot 1 , targetPivot 2 ) mc. Xform ( o, ws = 1, sp = targetPivot 0 , targetPivot 1 , targetPivot 2 ) if parentObj: mc. Parent ( o, parentObj ) else: mc. Parent ( o, w = 1 ) print ( 'You might need to delete histories' ) No-flip flow motion path object using curve normalsWell, not really no-flip, but you can easily modify the motion path loft.
#select object and curve and run code import maya.cmds as mc def curveOnSurfaceFromCurve ( curveObj, offsetDistance =. 5 ): offset1 = mc. OffsetCurve ( curveObj, ugn = 0, d = offsetDistance ) offset2 = mc. OffsetCurve ( curveObj, ugn = 0, d =- offsetDistance ) loftObj = mc. Loft ( offset1, offset2, u = 1, ch = 1 ) 0 loftShp = mc. ListRelatives ( loftObj, s = 1 ) 0 v = mc. GetAttr ( loftShp + '.minMaxRangeV.maxValueV' ) cOs = mc.
CurveOnSurface ( loftObj, d = 3, uv = ((. 5, 0 ),( 0.5, 1. v / 3 ), ( 0.5, 2. v / 3 ), ( 0.5, v ))) return cOs def motionPathWithNormalsAndFlow ( object, motionPathCurve, useTimeline = True, flowSpans = 10 ): mc. Xform ( object, a = True, ro = ( 0, 0, 0 ) ) bbox = mc. Xform ( object, q = 1, os = 1, bb = 1 ) axes = sorted (( bbox 3 - bbox 0 , 'x', 0 ),( bbox 4 - bbox 1 , 'y', 1 ),( bbox 5 - bbox 2 , 'z', 2 )) if useTimeline: mc. PathAnimation ( object, c = motionPathCurve, wut = 'normal', f = 1, ua = axes 0 1 , fa = axes - 1 1 , fm = 1, stu = mc.
PlaybackOptions ( q = 1, minTime = 1 ), etu = mc. PlaybackOptions ( q = 1, maxTime = 1 )) else: mc. PathAnimation ( object, c = motionPathCurve, wut = 'normal', f = 1, ua = axes 0 1 , fa = axes - 1 1 ) flowLatticeSides = 3, 3, 3 flowLatticeSides axes - 1 2 = flowSpans mc. Flow ( object, dv = flowLatticeSides ) selectedCurve = mc.
Ls ( sl = 1, tl = 1 ) object = mc. Ls ( sl = 1, hd = 1 ) motionPathCurveOnSurface = curveOnSurfaceFromCurve ( selectedCurve ) motionPathWithNormalsAndFlow ( object, motionPathCurveOnSurface ) zDepth control tool. Import maya.cmds as mc def oneCurveGrid ( rezx = 10, rezy = 10, scalex = 1, scaley = 1 ): points = sx = 1.0 / ( rezx - 1 ) sy = 1.0 / ( rezy - 1 ) for i in range ( rezx / 2 ): for j in range ( rezy ): points.
Append ( ( 2.0. i. sx. 5 ). scalex, ( j. sy.
5 ). scaley, 0 ) for j in reversed ( range ( rezy )): points. Append ( ( ( 2.0. i + 1 ). sx. 5 ).
scalex,( j. sy. 5 ). scaley, 0 ) for i in range ( rezy / 2 ): for j in reversed ( range ( rezx )): points. Append ( ( j. sx.
5 ). scalex, ( i. 2.0. sy.
5 ). scaley, 0 ) for j in range ( rezx ): points. Append ( ( j. sx. 5 ).
scalex, ( ( i. 2.0 + 1 ). sy. 5 ).
scaley, 0 ) for i in reversed ( range ( rezx )): points. Append ( (( i.
sx. 5 ). scalex ),(( i. sx. 5 ). scaley ), 0 ) return points def createZDistanceTool : 'creates controllers to help with the focus distance. Plugs into 'focusDistance' of camera shape' # choose cam selection = mc.
Ls ( sl = True ) chosenCamera = False if len ( selection ) 0: selShp = ( selection 0 , mc. ListRelatives ( selection 0 , s = True )) mc.
NodeType ( selection 0 ) 'transform' #gives us the shape if mc. NodeType ( selShp ) 'camera': chosenCamera = selShp else: currentPanel = mc. GetPanel ( withFocus = True ) if mc. GetPanel ( typeOf = currentPanel ) 'modelPanel': chosenCamera = mc. ModelPanel ( currentPanel, q = True, cam = True ) chosenCamera = mc. ListRelatives ( chosenCamera, s = True ) if not chosenCamera: mc. Warning ( 'Select camera or run in a perspective viewport' ) else: camObj = mc.
ListRelatives ( chosenCamera, p = 1 ) 0 camShape = chosenCamera 0 confirm = mc. ConfirmDialog ( title = 'Confirm', message = 'Create z-depth controller for ' + camObj + '?' , button = 'Yes', 'No' , defaultButton = 'Yes', cancelButton = 'No', dismissString = 'No' ) if confirm 'Yes': #spaghetti code below #floating locator system floatingZLoc = mc. Import maya.cmds as mc from decimal import. getcontext. Prec = 5 shp = mc.
ListRelatives ( mc. Ls ( sl = 1 ) 0 , s = 1 ) 0 cvs = mc. GetAttr ( shp + '.cv.'
) cvsSimple = for c in cvs: cvsSimple. Append ( float ( Decimal ( '%.3f '% c 0 )), float ( Decimal ( '%.3f '% c 1 )), float ( Decimal ( '%.3f '% c 2 ))) out = ' nn ### run python: ################# nn import maya.cmds as mc n mc.curve(p=' out += '%s '% ', '.
Join ( map ( str, cvsSimple )) out += ',d=' + str ( mc. GetAttr ( shp + '.degree' )) + ') nn #################################' print outResult. Import maya.cmds as mc from math import sqrt, fabs def attachThingsToThingsUI (. kwargs ): 'simple ui wrapper for 'attachThingsToThings' function. No error checking or fancy stuff' if len ( kwargs ) 0: #ui if mc. WindowPref ( 'AttachStuffWindow', ex = 1 ): mc.
WindowPref ( 'AttachStuffWindow', remove = 1 ) if cmds. Window ( 'AttachStuffWindow', exists = True ): cmds. DeleteUI ( 'AttachStuffWindow', window = True ) window = mc. Window ( 'AttachStuffWindow', title = 'Attach stuff to stuff', iconName = 'Short Name', widthHeight = ( 80, 55 ), rtf = 1 ) mc. FrameLayout ( mh = 10, mw = 10, bv = 0, l = ' ) mc.
ColumnLayout ( adjustableColumn = True ) textInfo1 = 'This script attaches objects to other objects using follicles. Parent objects require non-overlapping UVs.' TextInfo2 = 'Objects will be attached from their pivot to the closest point on parent mesh. In case of multiple parents, the script will try to figure out which is the closest' textInfo3 = 'Tips: if attached objects ' jump ' when on animated objects, or are not stuck precisely, you need more polygons on your parent object(s)' mc. Text ( ww = 1, label = textInfo1 ) mc. Separator ( st = 'none', h = 4 ) mc. Text ( ww = 1, label = textInfo2 ) mc.
Separator ( st = 'none', h = 8 ) mc. Separator ( st = 'in', h = 4 ) mc. Separator ( st = 'none', h = 8 ) mc.
Text ( ww = 1, label = textInfo3 ) mc. Separator ( st = 'none', h = 8 ) mc. Separator ( st = 'in', h = 4 ) mc. Separator ( st = 'none', h = 8 ) cb1 = mc.
CheckBox ( 'cboxZero', label = 'Add ' zero out ' parents to all objects', v = 1, rs = 1, annotation = 'creates a group above each object that takes the constrains, so that your object is still free to move - won't work with references' ) mc. CheckBox ( 'cboxCtrl', label = 'Add controllers to all objects', v = 0, rs = 1, annotation = 'creates ' zero-out ' controls that constrain your objects. Use if you have references and want to animate', onc = ( 'mc.checkBox('cboxZero',e=1,ed=0)' ), ofc = ( 'mc.checkBox('cboxZero',e=1,ed=1)' ) ) mc. Separator ( st = 'none', h = 8 ) mc.
Button ( label = 'Set object(s) to attach', command = ( 'mc.sets(n= ' tmpchildrenObjectsset ' )' ) ) mc. Separator ( st = 'none', h = 2 ) mc. Button ( label = 'Set parent object(s)', command = ( 'mc.sets(n= ' tmpparentObjectsset ' )' ) ) mc. Separator ( st = 'none', h = 10 ) mc. Button ( label = 'Apply', command = ( 'attachThingsToThingsUI(1)' ) ) mc.
ShowWindow ( window ) else: children = mc. ListConnections ( 'tmpchildrenObjectsset', s = 1, d = 0, p = 0, c = 0 ) parents = mc. ListConnections ( 'tmpparentObjectsset', s = 1, d = 0, p = 0, c = 0 ) useZeroOut = mc. CheckBox ( 'cboxZero', q = 1, v = 1 ) useCtrl = mc. CheckBox ( 'cboxCtrl', q = 1, v = 1 ) attachThingsToThings ( children, parents, 1, useZeroOut, useCtrl ) mc.
Delete ( 'tmpchildrenObjectsset', 'tmpparentObjectsset' ) def attachThingsToThings ( objects, targets, keepHierachy = True, useZeroOut = True, useCtrl = False ): 'requires closestUV closestDistanceToMesh mag python math - and non overlapping UVs ' selectedObjects = for o in objects: parents = mc. ListRelatives ( o, p = 1, f = 1 ) smallest = 99999.9 closest = u' outPos = p = mc. Xform ( o, ws = 1, q = 1, rotatePivot = True ) ro = mc. Xform ( o, ws = 1, q = 1, ro = True ) bbox = mc.
Xform ( o, ws = 1, q = 1, bb = True ) ctrlscale = (( bbox 3 - bbox 0 ) + ( bbox 4 - bbox 1 ) + ( bbox 5 - bbox 2 )) / 3.0 for r in targets: dist = closestDistanceToMesh ( p, r ) if dist. Import maya.cmds as mc def attachToClosestPointOnCurve : #last element should be curve, no error checking - snaps to cloest point on mesh using motionPath sel = mc.
Ls ( sl = 1 ) curveObj = sel len ( sel ) - 1 sel. Pop npc = mc. CreateNode ( 'nearestPointOnCurve' ) mc.
ConnectAttr ( mc. ListRelatives ( curveObj, s = 1 ) 0 + '.worldSpace0', npc + '.inputCurve', f = 1 ) for ob in sel: #parm = jcclosestPointOnCurve(mc.xform(ob, q=1, ws=1, t=1), curveObj) pos = mc. Xform ( ob, q = 1, ws = 1, t = 1 ) mc. SetAttr ( npc + '.inPosition', pos 0 , pos 1 , pos 2 , type = 'double3' ) parm = mc.
GetAttr ( npc + '.parameter' ) #loc = mc.spaceLocator(n=ob+'pointOnCurve') pathAnim = mc. PathAnimation ( ob, c = curveObj ) inputs = mc.
ListConnections ( pathAnim + '.uValue', s = 1 ) mc. DisconnectAttr ( inputs 0 + '.output', pathAnim + '.uValue' ) mc. SetAttr ( pathAnim + '.uValue', parm ) mc. Delete ( npc ) Make UV Check lambert.
Import urllib2 import os import maya.cmds as cmds tempDir = cmds. InternalVar ( userTmpDir = True ) uvFile = tempDir + 'uv1024bis.jpg'; f = open ( uvFile, 'wb' ) err = f. Write ( urllib2.
Urlopen ( '). Close shader = cmds.
ShadingNode ( 'lambert', asShader = True, name = 'UVlambert' ) filenode = cmds. ShadingNode ( 'file', asTexture = True ) filetext = cmds. ShadingNode ( 'place2dTexture', asUtility = True ) shadinggroup = cmds. Sets ( renderable = True, noSurfaceShader = True, empty = True ) cmds. ConnectAttr ( '%s.outColor'% shader, '%s.surfaceShader'% shadinggroup ) cmds. ConnectAttr ( '%s.outColor'% filenode, '%s.color'% shader ) cmds.
ConnectAttr ( '%s.coverage'% filetext, '%s.coverage'% filenode ) cmds. ConnectAttr ( '%s.translateFrame'% filetext, '%s.translateFrame'% filenode ) cmds.
ConnectAttr ( '%s.rotateFrame'% filetext, '%s.rotateFrame'% filenode ) cmds. ConnectAttr ( '%s.mirrorU'% filetext, '%s.mirrorU'% filenode ) cmds. ConnectAttr ( '%s.mirrorV'% filetext, '%s.mirrorV'% filenode ) cmds. ConnectAttr ( '%s.stagger'% filetext, '%s.stagger'% filenode ) cmds. ConnectAttr ( '%s.wrapU'% filetext, '%s.wrapU'% filenode ) cmds.
ConnectAttr ( '%s.wrapV'% filetext, '%s.wrapV'% filenode ) cmds. ConnectAttr ( '%s.repeatUV'% filetext, '%s.repeatUV'% filenode ) cmds. ConnectAttr ( '%s.offset'% filetext, '%s.offset'% filenode ) cmds. ConnectAttr ( '%s.rotateUV'% filetext, '%s.rotateUV'% filenode ) cmds. ConnectAttr ( '%s.noiseUV'% filetext, '%s.noiseUV'% filenode ) cmds.
ConnectAttr ( '%s.vertexUvOne'% filetext, '%s.vertexUvOne'% filenode ) cmds. ConnectAttr ( '%s.vertexUvTwo'% filetext, '%s.vertexUvTwo'% filenode ) cmds. ConnectAttr ( '%s.vertexUvThree'% filetext, '%s.vertexUvThree'% filenode ) cmds. ConnectAttr ( '%s.vertexCameraOne'% filetext, '%s.vertexCameraOne'% filenode ) cmds. ConnectAttr ( '%s.outUV'% filetext, '%s.uv'% filenode ) cmds.
ConnectAttr ( '%s.outUvFilterSize'% filetext, '%s.uvFilterSize'% filenode ) cmds. SetAttr ( '%s.fileTextureName'% filenode, uvFile, type = 'string' ) Check if latest ref. Import maya.cmds as mc import maya.mel as mel from functools import partial from os import listdir from os.path import split, isfile, join, dirname import subprocess class refCheckWindow ( object ): onlyMissing = True def init ( self ): print ' n Processing! Be patient =)' self. BuildWin def reinitWin (. args ): w = refCheckWindow def buttonPush (.
args ): refPath = dirname ( args 1 ) refPath = refPath. Replace ( '/', ' ' ) subprocess. Popen ( 'explorer '%s '% refPath ) def buildWin ( self ): scene = mc. File ( query = True, sn = True ) allrefs = mc. File ( query = True, list = True, withoutCopyNumber = True ) fileRefs = sorted ( list ( set ( item for item in allrefs if item. Endswith ( '.ma' ) or item.
Endswith ( '.mb' )))) if mc. Window ( 'checkRefs', ex = 1 ): mc. DeleteUI ( 'checkRefs', window = 1 ) mc. Window ( 'checkRefs', title = 'Check latest Refs', resizeToFitChildren = 1, w = 600 ) scrollLayout = cmds. ScrollLayout ( horizontalScrollBarThickness = 16, verticalScrollBarThickness = 16 ) mc. ColumnLayout ( adjustableColumn = True, columnAlign = 'center', rowSpacing = 10 ) mc. RowLayout ( numberOfColumns = 3 ) mc.
Text ( label = ' Checking if you have latest refs: ', align = 'left' ) mc. CheckBox ( 'cbox', label = 'Only show missing refs ', v = 1 ) mc. Button ( w = 55, l = 'Refresh', c = self.
ReinitWin ) mc. SetParent ( upLevel = True ) mc. Separator for ref in fileRefs: if ref!= scene: curRefNamespace = mc. ReferenceQuery ( ref, rfn = 1 ) curRefParent = mc.
ReferenceQuery ( curRefNamespace, rfn = 1, p = 1 ) onlyfiles = f for f in listdir ( split ( ref ) 0 ) if isfile ( join ( split ( ref ) 0 , f )) and f. Endswith (( '.mb', '.ma' )) #beautiful code below refFileName = ref. Rpartition ( '/' ) 2 refStepName = ref. Rpartition ( '/' ) 0.
Rpartition ( '/' ) 2 ; refChar = ref. Rpartition ( '/' ) 0.
Rpartition ( '/' ) 0. Rpartition ( '/' ) 0 ; refCharName = refChar. Rpartition ( '/' ) 0. Rpartition ( '/' ) 2 + ' / ' + refChar. Rpartition ( '/' ) 2 ; refCharName = refCharName. Lower ; latestRef = sorted ( onlyfiles ) - 1 ; col =.
3 ; if ( refFileName!= latestRef ): col =. 1 ; print '.' CheckBox ( 'cbox', q = 1, v = 1 ) and refFileName!= latestRef ): mc.
RowLayout ( numberOfColumns = 6, ann = curRefParent ) mc. Separator mc. Button ( w = 50, l = refStepName, en = 0 ) if curRefParent: col = ( col 0 +. 6 ) / 2,( col 1 +. 6 ) / 2,( col 2 +. 6 ) / 2 mc. Button ( w = 150, l = refCharName, bgc = col ) mc.
Text ( w = 370, l = ' ' + refFileName + ' - ' + latestRef + ' ' ) mc. Button ( w = 55, l = 'browse', c = partial ( self. ButtonPush, ref )) mc. Separator mc.
SetParent ( upLevel = True ) mc. Separator mc. ShowWindow w = refCheckWindow.
From on.Download This Free Maya Snake Rig From CreativeCrash:Now this tool is available for sale. For details, contact: [email protected]:-00:05 - Stretch Along Path01:01 - Hair Snakes Stretching From The Head & Traveling01:10 - Travel On Path (Path Animation)01:12 - File 'asEasySnakev1.2' rig download information01:52 - Multiple Snakes traveling on body which is in motion (R&D)02:00 - Multiple Snakes traveling on Uneven ground (R&D)02:37 - Rig Scaling & Path Animation Tutorial (Travel On Path)04:42 - CreditsVarious Other Tools for Snakes:-1. AsEasySnake.py (Auto Snake Rigging Tool)2. AsPathAnim (To Animate Snake Along Path)3. AsSnakePaths (To Create Multiple Snake Paths)4. AsMultiSnakes(To Animate Multiple Snakes Along Multiple Paths on Ground or Human Body etc.)Advanced Snake Features will be shown in my next video.Features:-1.
Various Types of Ctrl Shapes2. Selection of No. Of Joints and No. Flexibility at both ends4. Initial Selection Type: Curve or Jnts5. Ctrl Type: Grouped or Cluster Ctrl6. Ctrl Parent Style: Individual or Parented to Next Ctrl7.
Random Ctrl Colors8. Path Animation: Easy Snake Animation Along Path9.
Crawling Setup for Snake motion10. Hyper Smooth for SkinningNew Updates:-1. Create Basic Hierarchy2.
Tongue SetupasEasySnake Usage: Watch Following Demo (Usage In Movie)-You Can Watch: Advanced Hyper Skinning System. Node.addSuffix('Sph') # Now it adds 'Sph' suffix to the ball, But still node is updated with all these changesDownload:-Available for free download here:node is the key module in maya rigging process. One node for the most of the rigging process.asNode is still going to include many general methods required for rigging / animation process. It played key role in hyper skinning system as shown in below video:asNode was developed with the inspiration from PyNode in PyMel, But with extended support to Rigging process.And this doesn't depend on PyNode in PyMel. Its purely depends only on Maya api and maya.cmds.Features:-1. One node for most of the general process in Maya Rigging2.
AsNode was developed with the inspiration from PyNode in PyMel3. It has extensive support to Rigging and General Pipeline.4. Doesn't depend on any external modules like PyMel5. Purely depends on maya.cmds and maya python api6.
Increase programming speed in rigging & pipeline upto 3-4 times7. A Node with true Object Oriented Programming (OOP)8. Auto completion list varies with change in node type 9. Tight Integration With All Auto Rig tools like (asEasyBird, asEasyRig, asEasyQuad etc.)Updates:-2014.09.08 - Updated asNode.rar with help file on all methods by adding 'asNode.pypredef'. Open it with wordpad2014.09.21 - Test files are added in asNode.rar for asN.addChild, asN.mConstrain etc2015.02.05 - Auto completion methods will update and change according the selection type of object2015.02.06 - Fixed the method: asN.jntOrient and added new methods: asN.get2PosExtn, asN.get2PosVect. And added new example maya filesFuture Updates:-1.
A GUI by for Maya cloth artists that allow them to streamline their workflow by placing all commonly used commands in a simplified GUI - no more menu searching! Includes a few scripts that create wind and gravity controllers and plugs them into the associated nucleus attributes - no more animating individual X, Y, Z point vectors! Includes a dynamic amplitude attribute that can scale and or multiply these settings(can also be scaled negatively).More info and Script for download can be found on his.