Hi Everyone,Is it possible to use closestpointonmesh node to connect to an sdk to achieve a rigged action when something is close to the point.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5d67740c-ad07-42a1-9646-93a1339fd878%40googlegroups.com.
It sounds like he means to have a function called whenever something comes close, like a trigger or callback. If so, then yes, but not directly. The node itself doesn’t have any notion of a callback, but you can instead monitor (poll) the output of that node at some rate to roll your own callback mechanism.

from PySide2 import QtCore
from maya.api import OpenMaya as om
# Track triggered status
triggered = False
def monitor_distance(point1, point2):
"""Call some Python commands when the distance reaches some value
Arguments:
point1 (str): Path to a position attribute
point2 (str): ...
"""
# Leverage the Maya API to compute distance between two positions
p1 = om.MPoint(*cmds.getAttr(point1))
p2 = om.MPoint(*cmds.getAttr(point2))
distance = p1.distanceTo(p2)
# Avoid being called twice
global triggered
if distance < 2.0:
if not triggered:
print("In range..")
cmds.setAttr("blinn1.color", 1, 0.5, 0.5, type="double3")
triggered = True
else:
if triggered:
print("..out of range")
cmds.setAttr("blinn1.color", 0.5, 0.5, 0.5, type="double3")
triggered = False
point1 = "cpConstraintInShape.worldPosition"
point2 = "cpConstraintPosShape.worldPosition"
monitor = QtCore.QTimer()
monitor.setInterval(100) # Poll every 100 ms
monitor.timeout.connect(lambda: monitor_distance(point1, point2))
monitor.start()
#monitor.stop()
Hopefully the code makes clear where you’ve got your calls to Python/API, and where to edit the distance and so forth.
This particular example polls every 100 ms, but if you’ve got some sort of rig or animation where you need something to happen on the exact frame where the distance reaches the goal then this might miss the mark; in that case you could instead poll whenever the frame changes. There are various callbacks for that in both the API and the Maya script node you could use.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADHeb2ZPuug8R1r3-vBJLX4zrmh2nkzQvQ7Wkznspd4sg_qgMQ%40mail.gmail.com.