Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks #44

Merged
merged 5 commits into from
Nov 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cmdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,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

Expand Down Expand Up @@ -1761,6 +1774,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
Expand Down Expand Up @@ -3878,6 +3892,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): # type: (str) -> Node
"""Convert relative or absolute `path` to cmdx Node

Expand Down Expand Up @@ -4153,6 +4179,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

Expand Down Expand Up @@ -4414,6 +4445,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):
Expand Down