[Maya-Python] Custom Manipulator

541 views
Skip to first unread message

Marcus Ottosson

unread,
Jun 2, 2018, 2:24:45 PM6/2/18
to python_in...@googlegroups.com

Hi all,

I’m scratching my head over trying to get a manipulator to influence an attribute.

For example, I’ve got a composeMatrix node with an .inputTranslate attribute that I’d like to add a manipulator for.


I’ve been looking at the MFnFreePointTriadManip which has got a .connectToPointPlug() method taking an MPlug.

from maya.api import OpenMaya as om, OpenMayaUI as omui

composeMatrix = cmds.createNode("composeMatrix")
msel = om.MSelectionList()
msel.add(composeMatrix)
mobj = msel.getDependNode(0)
fn = om.MFnDependencyNode(mobj)
mplug = fn.findPlug("inputTranslate", False)

fn = omui.MFnFreePointTriadManip()
fn.connectToPointPlug(mplug)

# Error: (kFailure): Object does not exist
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
# RuntimeError: (kFailure): Object does not exist #

This happens for both API 1.0 and 2.0.

My understanding is that this function set is only usable during the creation of a plug-in, is that right? If so, is there any way of using this, or anything like it, to instantiate a custom manipulator “on-demand”, for a native Maya node and attribute such as composeMatrix.inputTranslate?

Serguei Kalentchouk

unread,
Jun 2, 2018, 5:42:55 PM6/2/18
to python_in...@googlegroups.com
Hey Marcus,

Not sure if creating manipulator outside of the relevant plugin callback is even valid but besides that, in your example  omui.MFnFreePointTriadManip() is just a function set that is not bound to to any actual maya object hence the error.


--
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/CAFRtmOBVj8ZMYdOkDxV62PL_jG-hjwLPPMqCTYSh7WAr3VjshQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jun 2, 2018, 6:07:33 PM6/2/18
to python_in...@googlegroups.com

omui.MFnFreePointTriadManip() is just a function set that is not bound to to any actual maya object hence the error.

I figure maybe it’d work like the function sets for other things.

from maya.api import OpenMaya as
 om

fn = om.MFnDependencyNode()
mobj = fn.create("composeMatrix")

Especially as it also has a .create() method. But alas, it does not seem to be the case.

What other ways are there? Could it be a placeholder plug-in (like we did for undo)? What I’m looking for is just a manipulator for an attribute that normally does not have one.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPCVZ5Mku9qb8h%2B-T0fz4QzL4y2oQ9W0hvKsAapmDOtC9ss%3D%2Bg%40mail.gmail.com.

Joe Weidenbach

unread,
Jun 2, 2018, 7:58:27 PM6/2/18
to python_in...@googlegroups.com

Hey Marcus,

I’ve not done it myself (yet), but I believe that what you’re looking for is a custom context. This context can be set up (through MMessages) to become active on selection of specific nodes, and then it can assign/control the necessary manipulators:

Basically you’d implement a MPxContext that handles the clicks to send commands to your manipulator, then a MPXContextCommand to create the context and add the manipulators, and finally set up an MMessage Handler (or a scriptjob in the userSetup.py) to call your context command to set things up.  The other option (potentially, again, haven't tried, but just looking at the docs) is to create a custom selection context (using MPxSelectionContext) and set things up to use it instead of the default selection context (probably through hacking the base scripts).

Maya API: MPxContext

Hope that at least points you in the right direction,

Joe


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
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.

--
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/CAFRtmOAZLgMpcxrdR_QUQObOdcocSYOoa9%3DXh0eZrhbb1NSfkA%40mail.gmail.com.

Marcus Ottosson

unread,
Jun 3, 2018, 4:14:45 AM6/3/18
to python_in...@googlegroups.com
Thanks Joe! Investigating those next.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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+unsub...@googlegroups.com.

--
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+unsub...@googlegroups.com.

--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da7dem%3DSpX0MYdbDwAhtG4oXKWiUE5tvi15b8K8j_7bxag%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages