Skip to content

Commit

Permalink
Fix tests and do PEP8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Feb 28, 2022
1 parent a86ef34 commit dae2b4c
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions cmdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,13 @@ def clone(self, name, shortName=None, niceName=None):
>>> cam["fClone"].read()
5.6
# Can clone enum attributes
>>> cam["myEnum"] = Enum(fields=["a", "b", "c"])
>>> clone = cam["myEnum"].clone("cloneEnum")
>>> cam.addAttr(clone)
>>> fields = cam["cloneEnum"].fields()
>>> assert fields == ((0, "a"), (1, "b"), (2, "c")), fields
"""

assert isinstance(self, Plug)
Expand Down Expand Up @@ -2862,22 +2869,7 @@ def clone(self, name, shortName=None, niceName=None):
)

if isinstance(fn, om.MFnEnumAttribute):
kwargs["fields"] = []

for index in range(fn.getMax() + 1):
try:
field = fn.fieldName(index)

except RuntimeError:
# Indices may not be consecutive, e.g.
# 0 = Off
# 2 = Kinematic
# 3 = Dynamic
# (missing 1!)
continue

else:
kwargs["fields"].append((index, field))
kwargs["fields"] = self.fields()

else:
if hasattr(fn, "getMin") and fn.hasMin():
Expand Down Expand Up @@ -2984,6 +2976,33 @@ def index(self):
"%s is not a child or element" % self.path()
)

def fields(self):
"""Return fields of an Enum attribute, if any"""

fn = self.fn()

assert isinstance(fn, om.MFnEnumAttribute), (
"%s was not an enum attribute" % self.path()
)

fields = []

for index in range(fn.getMax() + 1):
try:
field = fn.fieldName(index)

except RuntimeError:
# Indices may not be consecutive, e.g.
# 0 = Off
# 2 = Kinematic
# 3 = Dynamic
# (missing 1!)
continue

else:
fields.append((index, field))

return tuple(fields)

def nextAvailableIndex(self, startIndex=0):
"""Find the next unconnected element in an array plug
Expand Down Expand Up @@ -3280,16 +3299,19 @@ def findAnimatedPlug(self):
>>> parent = createNode("transform")
>>> _ = cmds.parentConstraint(str(parent), str(node))
>>> blend = ls(type="pairBlend")[0]
>>> node["tx"].findAnimatedPlug().path() == blend["inTranslateX1"].path()
>>> animPlug = node["tx"].findAnimatedPlug().path()
>>> animPlug == blend["inTranslateX1"].path()
True
# Animation layers
>>> layer = encode(cmds.animLayer(at=node["tx"].path()))
>>> node["tx"].findAnimatedPlug().path() == blend["inTranslateX1"].path()
>>> animPlug = node["tx"].findAnimatedPlug().path()
>>> animPlug == blend["inTranslateX1"].path()
True
>>> cmds.animLayer(str(layer), e=True, preferred=True)
>>> animBlend = ls(type="animBlendNodeBase")[0]
>>> node["tx"].findAnimatedPlug().path() == animBlend["inputB"].path()
>>> animPlug = node["tx"].findAnimatedPlug().path()
>>> animPlug == animBlend["inputB"].path()
True
# Animation layer then constraint
Expand All @@ -3299,10 +3321,12 @@ def findAnimatedPlug(self):
>>> parent = createNode("transform")
>>> _ = cmds.parentConstraint(str(parent), str(node))
>>> animBlend = ls(type="animBlendNodeBase")[0]
>>> node["tx"].findAnimatedPlug().path() == animBlend["inputA"].path()
>>> animPlug = node["tx"].findAnimatedPlug().path()
>>> animPlug == animBlend["inputA"].path()
True
>>> cmds.animLayer(str(layer), e=True, preferred=True)
>>> node["tx"].findAnimatedPlug().path() == animBlend["inputB"].path()
>>> animPlug = node["tx"].findAnimatedPlug().path()
>>> animPlug == animBlend["inputB"].path()
True
"""
Expand All @@ -3329,7 +3353,10 @@ def findAnimatedPlug(self):
plug = plug[self.index()] if plug.isCompound else plug

# Search for more pair blends or anim blends
con = plug.input(type=AnimBlendTypes + (MFn.kPairBlend,), plug=True)
con = plug.input(
type=AnimBlendTypes + (MFn.kPairBlend,),
plug=True
)

# If no animation layers or pair blends then plug is self
plug = plug if plug is not None else self
Expand Down Expand Up @@ -5057,6 +5084,9 @@ def _python_to_plug(value, plug):

# Native Maya types

elif isinstance(value, om.MObject):
plug._mplug.setMObject(value)

elif isinstance(value, om1.MObject):
node = _encode1(plug._node.path())
shapeFn = om1.MFnDagNode(node)
Expand Down

0 comments on commit dae2b4c

Please sign in to comment.