[Maya-Python] Re: Distance Constraint

2019-05-27 Thread Rémi Deletrain
Hi Cedric,

Yes I know that you should not read an output attribute in a copute.
For this moment I don't found solution and it's for show the desired result.

A second matrix ? For write the last position of constrained node ?

-- 
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/d3a74e65-ff63-462a-a725-4f8a418f300e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Distance Constraint

2019-05-24 Thread Cedric Bazillou
you should not read an output attribute that you write somewhere else in 
the same node( at least most of time, once you get more experience with 
attributeAffects internal attributes etc you can have some fun)
Are you not missing a second matrix attribute to do the distance clamping? 
( it will solve   self._mv_last_anchor , self._mv_point design issue) 

Le vendredi 24 mai 2019 00:23:25 UTC-7, Rémi Deletrain a écrit :
>
> 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/b5497ba2-8000-4e1e-b296-00d8eb6332e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: Distance Constraint

2019-05-24 Thread Rémi Deletrain
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:

[Maya-Python] Re: Distance Constraint

2019-05-23 Thread Michael Boon
What do you mean by "output" - what data are you having trouble storing?
Things like the "Source" and "Distance" in your screenshot, I think Maya 
will store automatically, assuming you are using attributes (eg 
MFnNumericAttribute.create) for them.
I have never created a constraint node though.


On Monday, 20 May 2019 17:18:38 UTC+10, Rémi Deletrain wrote:
>
> Hi everyone,
>
> I try to create a distanceConstraint node. For this moment I used MPxNode.
> The node works fine but I have problem when I reload my node... I d'ont 
> know how I store output and reload it...
> Anyone have solution ? MPxConstraint node make this ?
>
> [image: DistanceConstraint.gif]
>
>

-- 
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/ac3af61e-3359-41d7-a34a-cf29883f974f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.