Passing Maya Python Variable to API Deformer, is it possible?

Just wondering if it’s possible to execute something like this in the python script editor:


import maya.OpenMaya as OpenMaya

select = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( select )

etc… Then pass the variable to the MPxDeformerNode to use the variable inside of the deform definition.

Basicly I just want to remove some variable computation currently inside of the Deformer that only really needs to gathered once and not every time the Deformer Node updates. Constantly recalculating the static information is a big bottleneck on the current deformer I’m working on.

Can you calculate the data inside the postConstructor and store it in the node attributes?

Haven’t used that before, but it looks like I can declare a global variable and pass it to the deform. Awesome!

Now I need it to get one of the Node’s inputs, I take it the postConstructor can’t call on the data block, so any ideas on how I would get the attributes?

Nevermind, I found another way to get the data I needed. Thanks for the suggestion, just as I thought it made a huge difference.

If you find a solution for a problem you should always post it, not just mention that you found a solution, which might help others in the future :slight_smile:

I’m certainly not holding back on any finds here, I still don’t know how you would go about doing what I asked about 2 posts up, or even what I initially asked for. Should have made that clearer.

I’m just now gathering the info I needed through an MGlobal instead. Just like I did in the first post for the active selection. Luckily in this case it’s a workaround that meets my current needs, but I’m still very interested if someone knows the answer. I’ll post it if I figure it out.

Thanks to the Tiddlyspot Wiki, I was able to piece together how to pass a global Mel variable to the Python API:

in Mel:

global string $Variable;
$Variable = "Yes";

in your Python API Plugin:

import maya.mel as mm
env = {}
allMelVars = mm.eval('env()')
variable = mm.eval('%s_ = %s'%("$Variable","$Variable"))
print variable

Pretty handy info to have if you’re doing any API + scripting stuff. If you’re using C++ the process is outlined here.

Alright, ran into another road block. The code above lets me pass say a simple string, int, or float just fine. But what I really want to do is pass a pure python variable so I’m not limited to the variables types mel can handle.

The ultimate goal is to pass Python API variables from the script editor directly to the Python plugin. Again it is another attempt to remove some computation that only really needs to be run once, only under a little different circumstances.

Any help would be greatly appreciated if you have any ideas.

Hello Christopher

Just a quick question.
You want to pass around outside information into your python node?

The rule for a node is to process data gathered from its input attributes and to write the result into the output attributes.

Sometimes you must go outside your node to grab an MObject ( lets say you need to read an image or an animCurve node ).

But you must be wary of what you do in this cas.

I’m certainly aware of that being the common practice, but circumventing the need for an input is not the problem here. It’s removing some calculations that follow on a particular static mesh from the API plug-in entirely. I don’t want the deformer to have to recalculate it every time one is created. Want a python script with some API calls to handle it, then pass it to the plug-in.

What I would need is a way to somehow import the python variables directly from Maya without dismantling their type, or somehow pickle a PySwigObject. Thus far I have not had sucess with either, but maybe that gives someone an idea.

Maybe it’d be possible to make another node and take care of it there, then pass it to the deformer node through the input? Think I’ll try that next.