Working on more complex scripting projects in Maya, the time spent debugging grows.
Time is precious and having a clean debug workflow is the big bang here. I switched to VS Code recently and found
setting up the Maya debugging connection quite simple, thanks to this great blog post by iwonderwhatjoeisworkingon
http://iwonderwhatjoeisworkingon.blogspot.com/2017/04/debugging-maya-using-visual-studio-code.html
Print 'Done'. print 'value is 10'.. so many prints and those make script slow and take long to clean up once we done debugging. So i've been going slowly to other, I find better solutions to debugging and showing infos to unser.
>>> 1 Showing infos to user.
There are three types of infos we can print directly into the Maya Status Line. So User has no need to open script editor to see the note.
pm.error('This will be printed as error in in Status line')
pm.warning('This will be printed as warning in in Status line')
pm.displayInfo('This will be printed as info in in Status line')
>>> 2. Debugging
Logging is great because we can choose between different levels and can turn them off/on for the entire file by modifying one line
# set up
_logger = logging.getLogger(__name__)
# set level
logging.basicConfig(level=logging.INFO)
# throughout the script - logg
_logger.warning('There is a odd value returned %s'%value)
_logger.info('IK switch0isfk is %s'%switch0isfkTfb )
_logger.debug('snapping slaveDup')
# to turn / on
logger.disabled = False
Level
When it’s used
DEBUG
Detailed information, typically of interest only when diagnosing problems.
INFO
Confirmation that things are working as expected.
WARNING
An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
ERROR
Due to a more serious problem, the software has not been able to perform some function.
CRITICAL
A serious error, indicating that the program itself may be unable to continue running.
Returns true if the plug’s value is allowed to be set directly. A plug isFreeToChange if it is not locked, and it is not a destination or if it is a destination, then it must be a special case (such as connected to an anim curve).
Parameters:
checkParents :bool
Check parent plugs.
checkChildren :bool
Check child plugs.
Return type:
PyNode.FreeToChangeState
isFromReferencedFile()
This method determines whether this plug came from a referenced file. A plug is considered to have come from a referenced file if it is connected and that connection was made within a referenced file.
Return type:
bool
numConnectedElements()
Return the total number of connected element plugs belonging to this array plug.
Return type:
int
connected element plugs belonging to this array plug.
When using Vector Match in Rigs, we need life update. Creating custom Maya nodes can be done via API scripting but Maya comes with a number of built-in Vector Nodes we can use (even sometimes with a workaround)
Define the objects
obj1, obj2 = pm.PyNode('locator1'), pm.PyNode('locator2')
# see how i connect the objecsts at the end
# Normalize
Maya hs node vectorProduct, if we set it to Operation 'None' and Enable 'Normalize' it simple acts as a normalize
Had to stop here figure out how to Blogger can deal with syntax highlight first before writing this first blog. Here is the step by step guide i used to get it to work in a few minutes.
If you using aim/point constraints in Maya, you are not using a combination of Vector and Trigonometry calculations under the hood the software does for you. Using Vector math directly can allow you to work not only smarter but also faster and easier, once you get hang of it.
If you aim to do some calculation using Vector math in Python, scripting to get a value is probably the fastest way. However, if you want to implement Vector math into your Rig, we can use do the same calculations using Nodes (Expressions would be another alternative, but I avoid using those).
This post discusses using OpenMaya MVectors class.
# Creating MVectors in Maya
import pymel.core as pm
import maya.api.OpenMaya as om
import math
obj1, obj2 = pm.PyNode('locator1'), pm.PyNode('locator2')
obj1.t.set(2,2,2)
v1, v2 = om.MVector(obj1.t.get()), om.MVector(obj2.t.get()
# Length
Uses - Distance Between two Points
om.MVector(v2-v1).length()
# Normalize
The Vector direction at a length of one. This normalizes the Vectors,
Uses - make comparisons based on direction only.
om.MVector(v2-v1).normal()
# DOT Product / Angle Between Two Vectors
The Dot product multiplies two vectors and returns a Scalar number (no Vector).
If we normalize one Vector, returns a number between 0 and 1
> very useful to calculate Angles between Vectors, see if they face the same direction, etc
> find out what angle something is pointing
dot = v1*v2 # returns degreee in radiants
dot = v1*v2.normal() # returns value between 0 and 1, 0=parallel
print om.MAngle(math.acos(dot)).asDegrees() # returns the degree
Source and Resources:
http://www.naughtynathan.co.uk/?p=296
Short overview of MVector operations