[PyMel] MayaNode error on PyUI class

Hi Guys,

I am trying to get the parent layouts of the time control, but am getting an error and I am unsure why.

import pymel.core as pm

defaultTimeControl = pm.lsUI(type ='timeControl')[0]
print defaultTimeControl
print type(defaultTimeControl)
listTimeParents = pm.listRelatives(defaultTimeControl, allParents = True)

yields this information;

MayaWindow|toolBar6|MainTimeSliderLayout|formLayout9|frameLayout2|timeControl1
<class 'pymel.core.uitypes.PyUI'>

but gives the following error;

# Error: 
# Traceback (most recent call last):
#   File "<maya console>", line 6, in <module>
#   File "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\pymel\core\general.py", line 892, in listRelatives
#     results = map(PyNode, _util.listForNone(cmds.listRelatives(*args, **kwargs)))
#   File "C:\Program Files\Autodesk\Maya2013\Python\Lib\site-packages\pymel\internal\pmcmds.py", line 140, in wrappedCmd
#     raise pymel.core.general._objectError(obj)
# MayaNodeError: Maya Node does not exist: u'MayaWindow|toolBar6|MainTimeSliderLayout|formLayout9|frameLayout2|timeControl1' # 

Can anyone explain why this is please? Sorry for a noobish question :slight_smile:

Thanks, Chris

listRelatives only works with DAG objects. ui control/layout commands have flags for accessing the parent of a control/layout.

If you want to use pymel:

defaultTimeControl = pm.lsUI(type ='timeControl')[0]
timeParent = defaultTimeControl.getParent()

Or using the standard commands:

defaultTimeControl = cmds.lsUI(type ='timeControl')[0]
timeParent = cmds.timeControl(defaultTimeControl, query=True, parent=True)

Thanks capper!

I knew about .parent() method, what I am tring to put the whole parent hierarchy into a list. What would be the best way to do that?

Thanks for the reply!

Chris

You mean you want every parent as a separate item in a list?

pymel:

widget = pm.lsUI(type='timeControl')[0]
parents = []
while True:
    widget = widget.getParent()
    if not widget:
        break
    parents.append(widget)

maya.cmds

        
widget = cmds.lsUI(type='timeControl')[0]
parents = []
while '|' in widget:
    widget = widget.rsplit('|', 1)[0]
    parents.append(widget)