Home Website Youtube GitHub

Build mgear withuout ui

Hi, I’m trying to work out the code Id need to run to build a component without using the shifter ui.
I’ve been working on getting Spine IK 01 module to run via the maya script editor.
Id like be able to build a guide with code, have a user adjust the guides, and run code to do the actual build.
I’ve been trying different import statements all morning

from mgear.shifter_classic_components import  spine_ik_01 
from spine_ik_01 import guide
#Build the guide
spine_guide_object = guide.Guide()
spine_guide_object.parent = "??" # im not sure what this parent is supposed to be
spine_guide_object.postInit()
spine_guide_object.addParameters()
spine_guide_object.addObjects() #this builds the guide? I get the following error - 

# Error: 'str' object has no attribute 'addChild'
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "C:/Users/Admin/Documents/maya/modules/scripts/mgear/shifter_classic_components\spine_ik_01\guide.py", line 51, in addObjects
#     self.root = self.addRoot()
#   File "C:\Users\Admin\Documents\maya\modules\scripts\mgear\shifter\component\guide.py", line 580, in addRoot
#     "root"), color=13, m=self.tra["root"])
#   File "C:\Users\Admin\Documents\maya\modules\scripts\mgear\core\icon.py", line 1062, in guideRootIcon
#     rootIco = null(parent, name, width, color, m, pos_offset, rot_offset)
#   File "C:\Users\Admin\Documents\maya\modules\scripts\mgear\core\icon.py", line 937, in null
#     node = curve.addCurve(parent, name, points, False, 1, m)
#   File "C:\Users\Admin\Documents\maya\modules\scripts\mgear\core\curve.py", line 88, in addCurve
#     parent.addChild(node)
# AttributeError: 'str' object has no attribute 'addChild'

#Build the component based on the modified guide - havent made much progress here
from mgear.shifter import component ##?

spine_component_object = spine_ik_01.Component(??) #Im getting the following beacuse im not sure what to pass here
# TypeError: __init__() takes exactly 3 arguments (2 given) #   

Anyone have experience doing something like this?

(Edited to fix code formatting)

I don’t exactly grasp what you’re trying to recreate here.

The command that runs when you run Build From Selection from the menu can just be run from script. You don’t need the UI:

import pymel.core as pm
from mgear.shifter import guide_manager
guide_manager.build_from_selection()

If you are trying to recreate some kind of custom subset of the build process, I think you’d be better to begin from that point. That function imports the shifter module, and runs code from there. I think you might be starting too far down the chain of events. (But again, I’m not clear on what you’re trying to do.)

../scripts/mgear/shifter/__init__.py
../scripts/mgear/shifter/guide_manager.py
and so forth.

The shifter module also has a Rig class, with a method shifter.Rig.buildFromDict(conf_dict) which I guess can take the dictionary of a guide as an argument for what to build, instead of your selection. (Not sure how to do that. But it’s likely a more direct starting point.)

1 Like

Chris,
Thank you, I was able to build what I was after with:

 import pymel.core as pm
 from mgear.shifter import guide_manager

 guide_manager.draw_comp("spine_ik_01", parent=None, showUI=False)
 pm.select("spine_C0_root")
 guide_manager.build_from_selection()
1 Like