Hi everybody !
I just want to share with some script I've made for improv my workflow with ziva.
Some script are just an upgrade from script I've found on the forum.
for moderator : this post is very long and my english isn't correct so, don't hesitate to correct me !!!!
for other : please edit, upgrade and share your script work for helping ziva vfx workflow !!!
mel script on my ziva toolbar:
enable/disable the zsolver :
global proc invertZsolver()
{
$solverTab = `ls -type "zSolver"`;
$solver = "zSolver1";
if(`getAttr(($solver +".enable" ))`)
{
setAttr ($solver +".enable" ) 0;
inViewMessage -smg "solver disable" -pos topRight -bkc 0x00000000 -fade;
}
else
{
setAttr ($solver +".enable" ) 1;
inViewMessage -smg "solver enable" -pos topRight -bkc 0x00000000 -fade;
}
}
invertZsolver;
enable/disable zCache as double click command
global proc invertZCache()
{
$solverTab = `ls -type "zCacheTransform"`;
$solver = $solverTab[0];
if(`getAttr(($solver +".cache" ))`)
{
setAttr ($solver +".cache" ) 0;
inViewMessage -smg "zCache disable" -pos topRight -bkc 0x00000000 -fade;
}
else
{
setAttr ($solver +".cache" ) 1;
inViewMessage -smg "zCache enable" -pos topRight -bkc 0x00000000 -fade;
}
}
invertZCache;
combined with this command as simple click :
zCache -c;
Python script :
this one is used for creating cluster along the curve for line of action. It will rename the cluster with the tag : "nameOfTheCurve" + "_In_cls" or "Out_cls".
import maya.cmds as mc
def attachZivaCurve():
sel = mc.ls(sl = True)
for obj in sel:
curve = obj
clusterName = curve.strip('_cv')
print clusterName
cluster0 = mc.cluster((curve + ".cv[0]"),name=(clusterName + "In_cls"))
mc.rename(cluster0[1], clusterName + "In_clsh")
cluster1 = mc.cluster((curve + ".cv[1]"),name=(clusterName + "Out_cls"))
mc.rename(cluster1[1],clusterName + "Out_clsh")
attachZivaCurve()
and this one is an upgrade from andy's script for attaching a rivet on the closest face of a mesh and parent the cluster on the rivet.
The upgrade will rename all node connected to the rivet and his hierarchy with the name of the cluster.
for using this script you will have to save the script on your maya script location (mostly "%user%/Documents/maya/2016/scripts") as zLineOfActionUtils.py
and call the script with the second part
for myself I've create a button on my shelf where I call the attachZivaCurve() with a simple click and the auto_rivet_transforms_to_meshes() as double click !
this is a really good tool to work very fast with the zlineOfAction.
first part :
import maya.mel as mm
import maya.cmds as mc
import maya.OpenMaya as om
def get_mdagpath_from_object_name( object_name ):
'''
Returns the corresponding MDagPath object based on the objectName as a string.
Accepts:
objectName - string
Returns:
MDagPath object
'''
selList = om.MSelectionList()
selList.add( object_name )
dagPath = om.MDagPath()
it = om.MItSelectionList( selList )
it.getDagPath(dagPath)
return dagPath
def auto_rivet_transforms_to_meshes( everything_list ):
'''
TO DO: This script assumes you have rivet.mel in your scripts directory
'''
'''
Description:
Given a list containing transforms and meshes, find the closest point on mesh from all
given meshes (so the closest of all closest points) And build a rivet on that mesh at
that point. Parent the transform under the rivet locator.
Accepts:
A list of tauto_rivet_transforms_to_meshesransforms and meshes.
Returns: None
'''
lookupMeshes_dict = dict()
transforms_list = list()
for item in everything_list:
shapes = mc.listRelatives( item, shapes=True )
if shapes != None:
if mc.objectType( shapes[0] ) == 'mesh':
mesh_mfnMesh = om.MFnMesh( get_mdagpath_from_object_name( shapes[0] ) )
lookupMeshes_dict[item] = mesh_mfnMesh
else:
transforms_list.append(item)
for transform in transforms_list:
closestDistance = 10e10
closestMesh = None
closestPolygon = None
p = mc.xform( transform, q=True, rp=True, ws=True, a=True )
lookup_mPoint = om.MPoint( p[0], p[1], p[2] )
lookup_mFloatPoint = om.MFloatPoint( lookup_mPoint.x, lookup_mPoint.y, lookup_mPoint.z )
closestPolygon_mScriptUtil = om.MScriptUtil()
for lookupMesh in lookupMeshes_dict.keys():
currMesh_mfnMesh = lookupMeshes_dict[ lookupMesh ]
closest_mPoint = om.MPoint()
closest_mScriptUtil = om.MScriptUtil()
closestPolygon_ptr = closest_mScriptUtil.asIntPtr()
currMesh_mfnMesh.getClosestPoint( lookup_mPoint, closest_mPoint, om.MSpace.kWorld, closestPolygon_ptr )
closestPolygon_currIndex = closest_mScriptUtil.getInt(closestPolygon_ptr)
closest_mFloatPoint = om.MFloatPoint( closest_mPoint.x, closest_mPoint.y, closest_mPoint.z )
d = closest_mFloatPoint.distanceTo( lookup_mFloatPoint )
if d < closestDistance:
closestDistance = d
closestMesh = lookupMesh
closestPolygon = closestPolygon_currIndex
prevIndex_util = om.MScriptUtil()
meshName_mItMeshPolygon = om.MItMeshPolygon( get_mdagpath_from_object_name( closestMesh ) )
meshName_mItMeshPolygon.setIndex( closestPolygon, prevIndex_util.asIntPtr() )
edges_mIntArray = om.MIntArray()
meshName_mItMeshPolygon.getEdges( edges_mIntArray )
mc.select( closestMesh+'.e[%i]' % edges_mIntArray[0], r=True )
mc.select( closestMesh+'.e[%i]' % edges_mIntArray[2], add=True )
rivetLocator_str = mm.eval('rivet;')
rivetLocator_str = mc.rename( rivetLocator_str, transform+'_rivet' )
mc.select(rivetLocator_str)
renameRivetObject(transform,rivetLocator_str,closestMesh)
mc.parent( transform, rivetLocator_str )
def renameRivetObject(transform="",rivetLocator_str="",closestMesh=""):
print (closestMesh)
mc.select(hi = True)
hiSel = mc.ls(sl=True)
print hiSel
for obj in hiSel:
if mc.objExists(obj):
if not transform in obj:
if not closestMesh in obj:
newName = mc.rename(obj,transform + obj)
obj = newName
renameRivetConnections(obj,transform,closestMesh)
def renameRivetConnections(obj="", transform="",closestMesh=""):
connections = mc.listConnections(obj,scn=True,s=True,d=False,sh=False)
try:
len(connections)
for con in connections :
if mc.objExists(con):
if not transform in con:
if not closestMesh in con:
renameRivetConnections(con, transform,closestMesh)
newConName = mc.rename(con,transform + con)
except :
print ""
second part :
import zLineOfActionUtils as loa
import maya.cmds as mc
loa.auto_rivet_transforms_to_meshes( mc.ls(sl=True) )