Monday, July 31, 2017

Some interesting Pymel Attribute Functions





isFreeToChange(checkParents=TruecheckChildren=True)
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.

Sunday, July 2, 2017

Vectors in Maya 2: Nodes

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

normalizeNode = pm.createNode('vectorProduct')
normalizeNode.attr('operation').set(0)
normalizeNode.attr('normalizeOutput').set(1)

# Scale to any length, Lock in one axis if needed

multiplyNode = pm.createNode('multiplyDivide')
multiplyNode.attr('input2').set(3,3,0)

# connect nodes
obj1.translate >> normalizeNode.input1
normalizeNode.output >> multiplyNode.input1
multiplyNode.output >> obj2.translate




# Vector Magnitude (length)


To get a vectors length in Maya we 1. normalize it and 2. create dot product of normalized and non normalized

obj1, obj2 = pm.PyNode('pSphere1'), pm.PyNode('pSphere2')

# normalize node
normalizeNode = pm.createNode('vectorProduct')
normalizeNode.attr('operation').set(0)
normalizeNode.attr('normalizeOutput').set(1)

# vector length node
dotNode = pm.createNode('vectorProduct')

# connect
normalizeNode.output >> dotNode.input1
obj1.t >> dotNode.input2
dotNode.output >> multiplyNode.input1





Syntax Highlighting in Blogger

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.

https://android-expert-blog.blogspot.com/2015/12/how-to-integrate-syntaxhighlighter-to.html

Vectors in Maya 1: OpenMaya

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

Maya 2018 Auto Retopo Function

I just found this handy hidden function in Maya 2018 to turn your Mesh into even Quads or Triangles. // MEL //  turn selected mesh int...