Skip to content

Commit 4787a37

Browse files
mottossoMarcus Ottosson
authored andcommitted
Add printing of mesh attributes
1 parent ea2a1ca commit 4787a37

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ On average, `cmdx` is **140x faster** than [PyMEL](https://github.com/LumaPictur
2323

2424
| Date | Version | Event
2525
|:---------|:----------|:----------
26+
| Jun 2026 | 0.6.5 | Printing an inspection of mesh attributes, support for Maya 2027+
2627
| Dec 2023 | 0.6.3 | Cloning of attributes
2728
| Apr 2020 | 0.6.0 | Stable Undo/Redo, dropped support for Maya 2015-2016
2829
| Mar 2020 | 0.5.1 | Support for Maya 2022

cmdx.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,13 +5222,54 @@ def _plug_to_python(plug, unit=None, context=None):
52225222
# UI-independent units.
52235223
return plug.asMTime(**kwargs).asUnits(unit or Seconds)
52245224

5225+
elif type == om.MFn.kMesh:
5226+
return Mesh(plug)
5227+
5228+
# A generic attribute *could* be a mesh, check it
5229+
elif type == om.MFn.kGenericAttribute:
5230+
try:
5231+
data_obj = plug.asMObject(**kwargs)
5232+
5233+
except RuntimeError:
5234+
raise TypeError("Generic plug '%s' had no data" % plug)
5235+
5236+
if data_obj.isNull():
5237+
raise TypeError("Generic plug '%s' with no data" % plug)
5238+
5239+
api_type = data_obj.apiType()
5240+
5241+
# Mesh case
5242+
if api_type in (om.MFn.kMesh, om.MFn.kMeshData):
5243+
return Mesh(plug)
5244+
else:
5245+
raise TypeError("Generic plug '%s' unsupported" % plug)
5246+
52255247
elif type == om.MFn.kInvalid:
52265248
raise TypeError("%s was invalid" % plug.name())
52275249

52285250
else:
52295251
raise TypeError("Unsupported type '%s'" % type)
52305252

52315253

5254+
class Mesh(object):
5255+
def __init__(self, plug=None):
5256+
self._plug = plug
5257+
5258+
def __repr__(self):
5259+
return "%s (kMesh)" % self._plug
5260+
5261+
def points(self):
5262+
data_obj = self._plug.asMObject()
5263+
5264+
if data_obj.isNull():
5265+
raise RuntimeError(
5266+
"{0} has no points".format(self._plug)
5267+
)
5268+
5269+
mesh_fn = om.MFnMesh(data_obj)
5270+
return mesh_fn.getPoints(om.MSpace.kObject)
5271+
5272+
52325273
def _python_to_plug(value, plug):
52335274
"""Pass value of `value` to `plug`
52345275

run_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@
1111
collections.Callable = collections.abc.Callable
1212

1313

14+
def handle_maya_2025():
15+
# Maya 2025 updated to Python 3.11, which
16+
# removed this deprecated bastard
17+
if sys.version_info >= (3, 10):
18+
import inspect
19+
20+
def getargspec(*args, **kwargs):
21+
res = inspect.getfullargspec(*args, **kwargs)
22+
return res[:4]
23+
24+
inspect.getargspec = getargspec
25+
26+
1427
if __name__ == "__main__":
1528
print("Initialising Maya..")
1629
from maya import standalone, cmds
1730
standalone.initialize()
1831
cmds.loadPlugin("matrixNodes", quiet=True)
1932

33+
handle_maya_2025()
34+
2035
argv = sys.argv[:]
2136
argv.extend([
2237
"--verbose",

0 commit comments

Comments
 (0)