Skip to content

Commit

Permalink
Removes try/excepts and implements test case for string plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
chelloiaco committed Feb 27, 2024
1 parent 73f1aef commit 8da17d3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions cmdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ def __setitem__(self, key, value):
... else:
... assert False
>>>
>>> node["myString"] = String()
>>> node["myString"]
cmdx.Plug("myNode", "myString") == ""
>>> node["myString"] = "Hello, world!"
>>> node["myString"]
cmdx.Plug("myNode", "myString") == "Hello, world!"
>>>
>>> delete(node)
"""
Expand Down Expand Up @@ -2674,24 +2681,21 @@ def __str__(self):
return str(self.read())

def __repr__(self):
try:
# Delegate the value reading to __str__
read_result = str(self)
valid = True
except:
valid = False

cls_name = '{}.{}'.format(__name__, self.__class__.__name__)
msg = '{}("{}", "{}")'.format(cls_name,
self.node().name(),
self.name())
if valid:
try:
if self.typeClass() == String:

if not self.isCompound and not self.isArray:
# Delegate and include the value result from __str__
read_result = str(self)
attr = self._mplug.attribute()
typ = attr.apiType()
if typ == om.MFn.kTypedAttribute:
typ = om.MFnTypedAttribute(attr).attrType()
if typ == om.MFnData.kString:
# Add surrounding quotes, indicating it is a string
read_result = '"{}"'.format(read_result)
except TypeError:
pass
msg += ' == {}'.format(read_result)

return msg
Expand Down

0 comments on commit 8da17d3

Please sign in to comment.