Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…chMoveSolver into develop
  • Loading branch information
david-cattermole committed Nov 28, 2024
2 parents 688eb4f + 024254e commit 8c91e41
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 3 deletions.
31 changes: 30 additions & 1 deletion python/mmSolver/_api/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def __init__(self, name=None, node=None, attr=None):
# Long and short names must be checked.
attr_list_long = maya.cmds.listAttr(node, shortNames=False) or []
attr_list_short = maya.cmds.listAttr(node, shortNames=True) or []
if attr not in (attr_list_long + attr_list_short):
alias_pairs = maya.cmds.aliasAttr(node, query=True) or []
all_attrs = attr_list_long + attr_list_short + alias_pairs
if attr not in all_attrs:
msg = 'Attribute not found on node. node=%r attr=%r'
LOG.error(msg, node, attr)
raise RuntimeError(msg % (node, attr))
Expand Down Expand Up @@ -176,6 +178,33 @@ def get_attr(self, long_name=True):
)
return name

def get_attr_alias_name(self):
# Alias attributes are a little tricky. Alias attributes are
# not real attributes, they are a trick. Alias attributes do
# not have a "Nice Name" like regular attributes.
#
# This method was added to allow the user of the API to get
# the alias attribute name, but internally it's all referenced
# relative to the "real" attribute, and we must look up the
# alias name - if it exists.
node = self.get_node()
if node is None:
return None

alias_pairs = maya.cmds.aliasAttr(node, query=True) or []
if len(alias_pairs) == 0:
return None

attr = self.get_attr()
attr_names = alias_pairs[1::2]
if attr not in attr_names:
return None

alias_names = alias_pairs[0::2]
index = attr_names.index(attr)
alias_name = alias_names[index]
return alias_name

def get_attr_nice_name(self):
nice_name = None
node = self.get_node()
Expand Down
8 changes: 6 additions & 2 deletions python/mmSolver/tools/solver/ui/convert_to_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ def attributesToUINodes(col, attr_list, show_anm, show_stc, show_lck):
node_data = maya_node.data()
node_data['data'].append(attr)
maya_node.setData(node_data)
a = attr.get_attr_nice_name()
attr_node = attr_nodes.AttrNode(a, data=data, parent=maya_node)

attr_name = attr.get_attr_alias_name()
if attr_name is None:
attr_name = attr.get_attr_nice_name()

attr_node = attr_nodes.AttrNode(attr_name, data=data, parent=maya_node)
attr_node.setNeverHasChildren(True)
e = time.time()
LOG.debug('attributesToUINodes: %r seconds', e - s)
Expand Down
46 changes: 46 additions & 0 deletions scripts/test_mmSolver_windows64_maya2020.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
SETLOCAL
::
:: Copyright (C) 2024 David Cattermole.
::
:: This file is part of mmSolver.
::
:: mmSolver is free software: you can redistribute it and/or modify it
:: under the terms of the GNU Lesser General Public License as
:: published by the Free Software Foundation, either version 3 of the
:: License, or (at your option) any later version.
::
:: mmSolver is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU Lesser General Public License for more details.
::
:: You should have received a copy of the GNU Lesser General Public License
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
:: ---------------------------------------------------------------------
::
:: Runs tests via the Maya Python Interpreter.
::
:: NOTE: This file is intended as a short-cut rather than having to
:: find and type the full path to 'mayapy.exe' on Windows. On Linux,
:: `mayapy` should be set for your environment (assuming you have an
:: environment managed).


:: The root of this project.
SET PROJECT_ROOT=%CD%
ECHO Project Root: %PROJECT_ROOT%

:: Path to Maya Python interpreter.
SET MAYA_EXE="%PROGRAMFILES%\Autodesk\Maya2020\bin\mayapy.exe"

:: Run tests.
%MAYA_EXE% %PROJECT_ROOT%\tests\runTests.py %*
if errorlevel 1 goto tests_failed

:: Successful return.
exit /b 0

:tests_failed
echo mmSolver tests failed!
exit /b 1
46 changes: 46 additions & 0 deletions scripts/test_mmSolver_windows64_maya2022.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
SETLOCAL
::
:: Copyright (C) 2024 David Cattermole.
::
:: This file is part of mmSolver.
::
:: mmSolver is free software: you can redistribute it and/or modify it
:: under the terms of the GNU Lesser General Public License as
:: published by the Free Software Foundation, either version 3 of the
:: License, or (at your option) any later version.
::
:: mmSolver is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU Lesser General Public License for more details.
::
:: You should have received a copy of the GNU Lesser General Public License
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
:: ---------------------------------------------------------------------
::
:: Runs tests via the Maya Python Interpreter.
::
:: NOTE: This file is intended as a short-cut rather than having to
:: find and type the full path to 'mayapy.exe' on Windows. On Linux,
:: `mayapy` should be set for your environment (assuming you have an
:: environment managed).


:: The root of this project.
SET PROJECT_ROOT=%CD%
ECHO Project Root: %PROJECT_ROOT%

:: Path to Maya Python interpreter.
SET MAYA_EXE="%PROGRAMFILES%\Autodesk\Maya2022\bin\mayapy.exe"

:: Run tests.
%MAYA_EXE% %PROJECT_ROOT%\tests\runTests.py %*
if errorlevel 1 goto tests_failed

:: Successful return.
exit /b 0

:tests_failed
echo mmSolver tests failed!
exit /b 1
46 changes: 46 additions & 0 deletions scripts/test_mmSolver_windows64_maya2023.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
SETLOCAL
::
:: Copyright (C) 2024 David Cattermole.
::
:: This file is part of mmSolver.
::
:: mmSolver is free software: you can redistribute it and/or modify it
:: under the terms of the GNU Lesser General Public License as
:: published by the Free Software Foundation, either version 3 of the
:: License, or (at your option) any later version.
::
:: mmSolver is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU Lesser General Public License for more details.
::
:: You should have received a copy of the GNU Lesser General Public License
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
:: ---------------------------------------------------------------------
::
:: Runs tests via the Maya Python Interpreter.
::
:: NOTE: This file is intended as a short-cut rather than having to
:: find and type the full path to 'mayapy.exe' on Windows. On Linux,
:: `mayapy` should be set for your environment (assuming you have an
:: environment managed).


:: The root of this project.
SET PROJECT_ROOT=%CD%
ECHO Project Root: %PROJECT_ROOT%

:: Path to Maya Python interpreter.
SET MAYA_EXE="%PROGRAMFILES%\Autodesk\Maya2023\bin\mayapy.exe"

:: Run tests.
%MAYA_EXE% %PROJECT_ROOT%\tests\runTests.py %*
if errorlevel 1 goto tests_failed

:: Successful return.
exit /b 0

:tests_failed
echo mmSolver tests failed!
exit /b 1
46 changes: 46 additions & 0 deletions scripts/test_mmSolver_windows64_maya2024.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
SETLOCAL
::
:: Copyright (C) 2024 David Cattermole.
::
:: This file is part of mmSolver.
::
:: mmSolver is free software: you can redistribute it and/or modify it
:: under the terms of the GNU Lesser General Public License as
:: published by the Free Software Foundation, either version 3 of the
:: License, or (at your option) any later version.
::
:: mmSolver is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU Lesser General Public License for more details.
::
:: You should have received a copy of the GNU Lesser General Public License
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
:: ---------------------------------------------------------------------
::
:: Runs tests via the Maya Python Interpreter.
::
:: NOTE: This file is intended as a short-cut rather than having to
:: find and type the full path to 'mayapy.exe' on Windows. On Linux,
:: `mayapy` should be set for your environment (assuming you have an
:: environment managed).


:: The root of this project.
SET PROJECT_ROOT=%CD%
ECHO Project Root: %PROJECT_ROOT%

:: Path to Maya Python interpreter.
SET MAYA_EXE="%PROGRAMFILES%\Autodesk\Maya2024\bin\mayapy.exe"

:: Run tests.
%MAYA_EXE% %PROJECT_ROOT%\tests\runTests.py %*
if errorlevel 1 goto tests_failed

:: Successful return.
exit /b 0

:tests_failed
echo mmSolver tests failed!
exit /b 1
46 changes: 46 additions & 0 deletions scripts/test_mmSolver_windows64_maya2025.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
SETLOCAL
::
:: Copyright (C) 2024 David Cattermole.
::
:: This file is part of mmSolver.
::
:: mmSolver is free software: you can redistribute it and/or modify it
:: under the terms of the GNU Lesser General Public License as
:: published by the Free Software Foundation, either version 3 of the
:: License, or (at your option) any later version.
::
:: mmSolver is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU Lesser General Public License for more details.
::
:: You should have received a copy of the GNU Lesser General Public License
:: along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
:: ---------------------------------------------------------------------
::
:: Runs tests via the Maya Python Interpreter.
::
:: NOTE: This file is intended as a short-cut rather than having to
:: find and type the full path to 'mayapy.exe' on Windows. On Linux,
:: `mayapy` should be set for your environment (assuming you have an
:: environment managed).


:: The root of this project.
SET PROJECT_ROOT=%CD%
ECHO Project Root: %PROJECT_ROOT%

:: Path to Maya Python interpreter.
SET MAYA_EXE="%PROGRAMFILES%\Autodesk\Maya2025\bin\mayapy.exe"

:: Run tests.
%MAYA_EXE% %PROJECT_ROOT%\tests\runTests.py %*
if errorlevel 1 goto tests_failed

:: Successful return.
exit /b 0

:tests_failed
echo mmSolver tests failed!
exit /b 1
32 changes: 32 additions & 0 deletions tests/test/test_api/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ def test_init(self):
self.assertEqual(y.get_attr(), 'translateY')
self.assertEqual(y.get_name(), '|transform1.translateY')

def test_init_with_attr_alias(self):
node = maya.cmds.createNode('transform')
node = node_utils.get_long_name(node)
maya.cmds.aliasAttr('tilt', node + '.rotateX')
maya.cmds.aliasAttr('pan', node + '.rotateY')
maya.cmds.aliasAttr('roll', node + '.rotateZ')

tx = attribute.Attribute(node=node, attr='translateX')
tilt = attribute.Attribute(node=node, attr='rotateX')
pan = attribute.Attribute(node=node, attr='pan')
roll = attribute.Attribute(node=node, attr='roll')

self.assertEqual(tx.get_node(), node)
self.assertEqual(tilt.get_node(), node)
self.assertEqual(pan.get_node(), node)
self.assertEqual(roll.get_node(), node)

self.assertEqual(tx.get_attr(), 'translateX')
self.assertEqual(tilt.get_attr(), 'rotateX')
self.assertEqual(pan.get_attr(), 'rotateY')
self.assertEqual(roll.get_attr(), 'rotateZ')

self.assertEqual(tx.get_attr_alias_name(), None)
self.assertEqual(tilt.get_attr_alias_name(), 'tilt')
self.assertEqual(pan.get_attr_alias_name(), 'pan')
self.assertEqual(roll.get_attr_alias_name(), 'roll')

self.assertEqual(tx.get_name(), '|transform1.translateX')
self.assertEqual(tilt.get_name(), '|transform1.rotateX')
self.assertEqual(pan.get_name(), '|transform1.rotateY')
self.assertEqual(roll.get_name(), '|transform1.rotateZ')

def test_get_state(self):
node = maya.cmds.createNode('transform')
node = node_utils.get_long_name(node)
Expand Down

0 comments on commit 8c91e41

Please sign in to comment.