Skip to content

broken when imported before maya initialisation in mayapy #81

@p0las

Description

@p0las

maya 2024 on windows 10.

run mayapy
import cmdx
this breaks however:
from cmdx import ContainerNode

with this error:
ImportError: cannot import name 'ContainerNode' from 'cmdx' (cmdx.py)

since there is no maya cmds yet the version check fails:

try:
    __maya_version__ = int(cmds.about(version=True))
except (AttributeError, ValueError):
    __maya_version__ = 2015  # E.g. Preview Release 95

and it is set to maya 2015. this in turn disables ContainerNode:

if __maya_version__ >= 2017:
    class ContainerNode(Node):

which makes the code fail in commandline tools that initialise maya after cmdx was imported.

2024-07-25 18:24:17:  0: STDOUT:   File "cmdx.py", line 7357, in listRelatives
2024-07-25 18:24:17:  0: STDOUT:     _parent = node.parent(type=type)
2024-07-25 18:24:17:  0: STDOUT:   File "cmdx.py", line 1853, in parent
2024-07-25 18:24:17:  0: STDOUT:     return cls(mobject)
2024-07-25 18:24:17:  0: STDOUT:   File "cmdx.py", line 480, in __call__
2024-07-25 18:24:17:  0: STDOUT:     sup = ContainerNode
2024-07-25 18:24:17:  0: STDOUT: NameError: name 'ContainerNode' is not defined

it is not always easy to control the order of imports in more complicated pipelines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions