Re: [Maya-Python] How can I use a Dependency Node plug-in inside Maya?

398 views
Skip to first unread message

Joe Weidenbach

unread,
Jan 13, 2015, 2:16:22 PM1/13/15
to python_in...@googlegroups.com
Hi Carlos,

Dependency Nodes are basically (once created) like other dependency nodes in Maya.  So, you can (once the plugin is loaded, either through script or through the plugins manager) call createNode('<your plugin's node name>"), which will create your node, and then you just connect and/or set attrs on that node.  It's identical to, say, a multiplyDivide node or a plusMinusAverage.

Hope that helps,

Joe

On Tue, Jan 13, 2015 at 1:32 AM, Carlos Montes <carlos...@gmail.com> wrote:
Hello, everyone. I have just finished Robert Galanakis' "Practical Maya Programming with Python" book, where in its Chapter 8 a dependency graph plug-in is developed. My problem is, I don't know how it can be used or invoked inside Maya; using plug-ins for this software is new for me. I will provide some code from the book to try to expose where my doubtfulness resides, but the question remains the

In Chapter 7, he teaches us a Command plug-in can be called with pymel.core's loadPlugin in the Script Editor, and then a plugin_name variable that was defined inside the Python plugin file can be used as a method that invokes the plugin.

This is what it would look like in the Script Editor's Python tab, for a Command plug-in to be used :

import pymel.core as pmc                 
pmc.loadPlugin('playsoundplugin.py')  
pmc.playSound()              
                 

Inside 'playsoundplugin.py', that variable called plugin_name is defined as the method you invoke to play a Sound in Maya, by using a creator function and initializing the plugin with registerCommand.

plugin_name = 'playSound'

def create_plugin():
    return OpenMayaMPx.asMPxPtr(SoundPlayer())

def initializePlugin(mobject):
   plugin = OpenMayaMPx.MFnPlugin(mobject)
   plugin.registerCommand(plugin_name, create_plugin)


It's very straightforward, and it all makes sense with has been taught in the book; he even offers a very interesting way to add flags to the command call.
For Chapter 8, though, he doesn't show how we can use the quite complex Dependency Node plugin where he creates a node and its attributes with specifications and concrete subclasses. The plugin takes three input values, and a compute function takes care of determining two output attributes.

Similar to the Command plugin creation, the node plugin also uses similar creator and initialization functions; but this time, a new type with the 'circler' name is created:

def register_circler(fnplugin):
    inputnames = ['input', 'scale', 'frames']
    reg, dereg = create_node(NT_DEPENDSNODE, 'circler', 0x60005, [ value1, value2, value3 ])
    reg(fnplugin)

def initializePlugin(mobject):
    register_circler(OpenMayaMPx.MFnPlugin(mobject))


And here is where my question is; Command plug-ins can be called with the plugin_name variable, but how can I use a Dependency Node plugin then? How can I create this dependency node with input and output attributes inside Maya? Do all Dependency Node plugins share the same procedure to be used?

I hope the question is not too vague or non understandable. Thank you for reading.

--
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/4ca53150-27e0-46bb-9e71-ff2afbe69e24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carlos Montes

unread,
Jan 13, 2015, 10:13:27 PM1/13/15
to python_in...@googlegroups.com
I see, so it will become visible in, say, the Hypergraph or the Connection Editor, and I can then manipulate its inputs like I do with other nodes.

That makes a lot of sense! Thank you. I also found this helpful read from Autodesk that describes what we can do with the Dependency Graph and how it works.

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

Joe Weidenbach

unread,
Jan 14, 2015, 11:40:32 AM1/14/15
to python_in...@googlegroups.com
No Problem, Carlos!

Glad I could help!  Also, now that I think about it, it will also show up just fine in the node editor as well :)  Good find on the dependency graph!

Joe
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/56ecaf12-006e-4143-8dda-af80874f4246%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




This email is free from viruses and malware because avast! Antivirus protection is active.


Reply all
Reply to author
Forward
0 new messages