Home Website Youtube GitHub

Creating guides by script

this is my first post, so if anything is messed up, please be gentle and help me improve :slight_smile:

I have come across an issue where i would love to create a bunch of guides in a pre_script.
This is semi working, since i have heavily leaned on posts from this forum (thanks Chris Lesage, your contributions are a blessing).
However, when ever I am creating a guide the ‘chain_initializer’ window is popping up. As far as I see it atm, this one is hard scripted into the classes of the guides itself?

I thought of a workaround but it is not something i am able to do without much research:
since the window pops up in a process i do not want to modify locally for continuity issues and closes before I can interact with it I could…
run the process on multiple threads and let one script check for if the window pops up in the maya ui and then get the information from the other script into that window and press enter…

but this feels very janky.

is there a way around this?

here is the code i have:

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

def get_index_as_int(elem):
    return int(elem.split('_')[-2])

def guide_from_curves(curves):
    for crv in curves:
        cvs = crv.getShape().getCVs(space='world')
        cv_zero = cvs[0]
        cv_rest = cvs[1:]
        # this is just here for me, to read the input i would love to apply automatically
        if pm.objExists('guide'):
        guide_manager.draw_comp("lite_chain_01", parent=None, showUI=False)
        root_comp = pm.selected()[0]
        # the window name, i can not use because after draw_comp is finished, the window is dead
        # print(pm.objExists('lite_chain_01ChainGuideInitializer'))
        # me doublechecking if it is really dead
        #pm.lsUI (wnd = True)
        guide_subs = list()
        guide_locs = [x for x in root_comp.listRelatives(allDescendents=True, type="transform") if '_loc' in str(x.shortName())]
        for iteration_, sub in enumerate(guide_subs):
            sub.setTranslation(cvs[iteration_], space='world')
        decomposed_curve_name = str(crv.shortName()).split('_')
        if len(decomposed_curve_name) == 4:
            name_, side_, index_ = decomposed_curve_name[0:-1]
            raise errors.NamingError
        guide.Rig().updateProperties(root_comp, name_, side_, int(index_))
1 Like

Hi welcome,

I don’t really have time to look closely. But it sounds like you’re trying to edit the window that is popping up. And I agree, that does feel a bit janky, but points for being creative! :slight_smile:

A better way might be to clone the component as a custom component. And modify its code so that its methods can take some arguments, without needing to launch the GUI.

You might have to spend some time comparing components, and compare one that does respect the showUI=False flag.

I’ve never created guides via code, so I don’t personally know the best starting place to point you to. There might even be an easier way. Or maybe not obeying showUI=False is a bug. Or maybe it was never implemented. I’m not sure!