Hi Michael,
Normaly picture is a GIF. I think Google get just first frame au GIF...
I try to store output value "outTranslate" for use it when i load my scene.
I set "outTranslate" attribute to storable and in line 116 of my script I
get attribute value for initialize one variable. I not sure this solution
is really good beacause cause an error in first compute.
# RuntimeError: maximum recursion depth exceeded in cmp //
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/92fc610c-e995-427f-b53b-cfc74814a5d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
distanceConstraint.ma
Description: Binary data
# coding=ascii
"""
!@Brief Maya animation node.
"""
#
# Initialize Plugin
#
import math
from maya import OpenMaya, OpenMayaMPx
#
# Initialize Plugin
#
class DistanceConstraint(OpenMayaMPx.MPxNode):
"""
!@Brief Implementation of distance constraint node.
"""
kPluginNode = "distanceConstraint"
kPluginNodeID = OpenMaya.MTypeId(0x2051339)
kPluginNodeType = OpenMayaMPx.MPxNode.kDependNode
SOURCE = OpenMaya.MObject()
DISTANCE = OpenMaya.MObject()
OUT_TRANSLATE_X = OpenMaya.MObject()
OUT_TRANSLATE_Y = OpenMaya.MObject()
OUT_TRANSLATE_Z = OpenMaya.MObject()
OUT_TRANSLATE = OpenMaya.MObject()
# ==
# Node Init
# ==
@classmethod
def creator(cls):
return OpenMayaMPx.asMPxPtr(cls())
def __init__(self):
super(DistanceConstraint, self).__init__()
self._mv_last_anchor = None
self._mv_point = None
@classmethod
def initializer(cls):
a_in_attributes = list()
a_out_attributes = list()
# Input
source_attr = OpenMaya.MFnMatrixAttribute()
cls.SOURCE = source_attr.create('source', 's')
source_attr.setStorable(True)
source_attr.setKeyable(False)
a_in_attributes.append(cls.SOURCE)
distance_attr = OpenMaya.MFnNumericAttribute()
cls.DISTANCE = distance_attr.create('distance', 'd', OpenMaya.MFnNumericData.kDouble, 1.0)
distance_attr.setStorable(True)
distance_attr.setKeyable(True)
a_in_attributes.append(cls.DISTANCE)
# Output
out_translate_X_attr = OpenMaya.MFnNumericAttribute()
cls.OUT_TRANSLATE_X = out_translate_X_attr.create("outTranslateX", "otx", OpenMaya.MFnNumericData.kDouble, 0.0)
out_translate_y_attr = OpenMaya.MFnNumericAttribute()
cls.OUT_TRANSLATE_Y = out_translate_y_attr.create("outTranslateY", "oty", OpenMaya.MFnNumericData.kDouble, 0.0)
out_translate_z_attr = OpenMaya.MFnNumericAttribute()
cls.OUT_TRANSLATE_Z = out_translate_z_attr.create("outTranslateZ", "otz", OpenMaya.MFnNumericData.kDouble, 0.0)
out_translate_attr = OpenMaya.MFnNumericAttribute()
cls.OUT_TRANSLATE = out_translate_attr.create("outTranslate", "ot", cls.OUT_TRANSLATE_X, cls.OUT_TRANSLATE_Y, cls.OUT_TRANSLATE_Z)
out_translate_attr.setKeyable(False)
out_translate_attr.setStorable(True)
a_out_attributes.append(cls.OUT_TRANSLATE)
# Add attribute
for mo_attribute in (a_in_attributes + a_out_attributes):
cls.addAttribute(mo_attribute)
# Attribute dependencies
for mo_out_attribute in a_out_attributes:
for mo_in_attribute in a_in_attributes:
cls.attributeAffects(mo_in_attribute, mo_out_attribute)
# ==
# Compute
# ==
def compute(self, plug, data):
# Set valid plugs
a_valid_output = [self.OUT_TRANSLATE_X, self.OUT_TRANSLATE_Y, self.OUT_TRANSLATE_Z, self.OUT_TRANSLATE]
if plug in a_valid_output:
# Get Data
mm_source = data.inputValue(self.SOURCE).asMatrix()
f_distance = data.inputValue(self.DISTANCE).asDouble()
mtr_source = OpenMaya.MTransformationMatrix(mm_source)
mv_anchor = mtr_source.getTranslation(OpenMaya.MSpace.kWorld)
# Compute only if current anchor is different of last anchor
if self._mv_last_anchor is not None and mv_anchor == self._mv_last_anchor:
return
# Get output point
if self._mv_point is None: