From 349d50b26d61dae64e4e7606818d019c075615e2 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 26 Nov 2020 08:24:46 +0000 Subject: [PATCH 1/4] Add Node.exists --- cmdx.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmdx.py b/cmdx.py index 49c51c3..7051cd1 100644 --- a/cmdx.py +++ b/cmdx.py @@ -3861,6 +3861,18 @@ def _python_to_mod(value, plug, mod): return True +def exists(path): + """Return whether any node at `path` exists""" + + selectionList = om.MSelectionList() + + try: + selectionList.add(path) + except RuntimeError: + return False + return True + + def encode(path): """Convert relative or absolute `path` to cmdx Node From 0d504d3824fd483786eb76314320f179b07c3b00 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 26 Nov 2020 08:24:58 +0000 Subject: [PATCH 2/4] Add DagNode.childCount --- cmdx.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmdx.py b/cmdx.py index 7051cd1..f1678da 100644 --- a/cmdx.py +++ b/cmdx.py @@ -1332,6 +1332,19 @@ def show(self): """Set visibility to True""" self["visibility"] = True + def childCount(self, type=None): + """Return number of children of a given optional type + + Compared to `MFnDagNode.childCount`, this function actually returns + children, not shapes, along with filtering by an optional type. + + Arguments: + type (str): Same as to .children(type=) + + """ + + return len(list(self.children(type=type))) + def addChild(self, child, index=Last, safe=True): """Add `child` to self @@ -1744,6 +1757,7 @@ def setLimit(self, typ, value): if ENABLE_PEP8: shortest_path = shortestPath add_child = addChild + child_count = childCount dag_path = dagPath map_from = mapFrom map_to = mapTo From 5b307e1336818d6cf3679b20f788b2170a8fe865 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Fri, 27 Nov 2020 10:26:11 +0000 Subject: [PATCH 3/4] Improve error reporting done by DagModifier --- cmdx.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmdx.py b/cmdx.py index f1678da..5fc0ef4 100644 --- a/cmdx.py +++ b/cmdx.py @@ -4162,6 +4162,11 @@ def doIt(self): self.undoIt() raise ModifierError(self._history) + else: + + # Facilitate multiple calls to doIt, whereby only + # the latest, actually-performed actions are reported + self._history[:] = [] self.isDone = True From 9ed04f72ec73a1543d1d93ea55452ef27f4227f9 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Fri, 27 Nov 2020 10:26:26 +0000 Subject: [PATCH 4/4] Add cmdx.connect for convenience with undo --- cmdx.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmdx.py b/cmdx.py index 5fc0ef4..e248327 100644 --- a/cmdx.py +++ b/cmdx.py @@ -4428,6 +4428,12 @@ def parent(self, node, parent=None): create_node = createNode +# Convenience functions +def connect(a, b): + with DagModifier() as mod: + mod.connect(a, b) + + class DGContext(om.MDGContext): def __init__(self, time=None, unit=None):