Home Website Youtube GitHub

Function from rigbits crashes with exception

Hello there!

I’m using mGear 5.2.1 - just recently updated.

We are calling a few functions from mGear-rigbits from within our custom Maya tools (Python code) directly, to help us customizing rigs to our special needs - for example “replaceShape()”. This worked before the update, but now it is throwing an exception in Maya - for example this:

File “D:\p4\ArtTools\Maya\Modules\External\mGear\scripts\mgear\rigbits_init_.py”, line 426, in replaceShape
source2 = pm.duplicate(source)[0]
File “D:\p4\ArtTools\Maya\Modules\External\mGear\scripts\mgear\pymaya\cmd.py”, line 266, in wrapper > raise RuntimeError(
RuntimeError: Error occurred while calling wrapped function ‘maya.cmds.duplicate’: Object is invalid
Arguments: (nt.Transform(‘BreakFlap_R_Ctl_temp’),)
Keyword Arguments: {}
Command for debugging: maya.cmds.duplicate(nt.Transform(‘BreakFlap_R_Ctl_temp’), )

I tracked it down to the fact, that - as I believe - many commands (not only “duplicate”, but also “connectAttr”, “disconnectAttr” and a few more) in the new “mgear.pymaya” implementation require strings instead of PyNodes as input, now. However, even when I try to fix all the different places where this occurs by changing them to something like this “pm.duplicate(source.name())[0]”, I only get to the point, where I get an API error at the end - without any callstack, unfortunately.

For now I worked around that issue by changing the module import back to “import pymel.core as pm”. This works for us, because lots of other tools are still using pymel and we got it installed anyway.

Is this a known issue? Is there any other way to fix it, maybe?

Thanks for any feedback and your support!

Cheers
René

mGear started moving away from PyMel and it seems you are passing the command a PyNode, right?

So you’ll have to change it to a string name or whatever other mgear object that might be compatible.

But your code pm.duplicate(source.name())[0] has an input as a name but still an output as a PyNode. So you’ll can still use the PyNode in the duplicate. But you need to get the name from the output of that command.

pm.duplicate(source)[0].name() or similar.

(I’m on a phone so I am reading your code as best I can.)

Thanks a lot for the quick response!

And sorry for not being clear on this - I changed the duplicate command INSIDE of “mGear.rigbits.replaceShape()” - not in my own tools.
So yes, what you said is totally true, but it is a mismatch in the rigbits functions themselves. If I fix the “duplicate”, e.g. “disconnectAttr” fails next, because - as you pointed out - “duplicate” still returns a PyNode.

If I actually call “mGear.rigbits.replaceShape()” with strings as input and not PyNode objects, I get the following exception.

File “D:\p4\ArtTools\Maya\Modules\External\mGear\scripts\mgear\rigbits_init_.py”, line 427, in replaceShape
shape = target.getShapes()
AttributeError: ‘str’ object has no attribute ‘getShapes’

I just think there is some confusion between the input and output of the commands, which needs to be fixed…

Thanks again!

1 Like