Best Python code snippet using ATX
animTransform_test.py
Source:animTransform_test.py
1##-*****************************************************************************2##3## Copyright (c) 2009-2011,4## Sony Pictures Imageworks, Inc. and5## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.6##7## All rights reserved.8##9## Redistribution and use in source and binary forms, with or without10## modification, are permitted provided that the following conditions are11## met:12## * Redistributions of source code must retain the above copyright13## notice, this list of conditions and the following disclaimer.14## * Redistributions in binary form must reproduce the above15## copyright notice, this list of conditions and the following disclaimer16## in the documentation and/or other materials provided with the17## distribution.18## * Neither the name of Sony Pictures Imageworks, nor19## Industrial Light & Magic nor the names of their contributors may be used20## to endorse or promote products derived from this software without specific21## prior written permission.22##23## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS24## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT25## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR26## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT27## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT29## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,30## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY31## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT32## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE33## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34##35##-*****************************************************************************36import maya.cmds as MayaCmds37import os38import subprocess39import unittest40import util41class AnimTransformTest(unittest.TestCase):42 def setUp(self):43 MayaCmds.file(new=True, force=True)44 self.__abcStitcher = [os.environ['AbcStitcher']]45 self.__files = []46 def tearDown(self):47 for f in self.__files:48 os.remove(f)49 def testAnimTransformReadWrite(self):50 nodeName = MayaCmds.createNode('transform', n='test')51 # shear52 MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXY', t=[1, 24])53 MayaCmds.setKeyframe(nodeName, value=0, attribute='shearYZ', t=[1, 24])54 MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXZ', t=[1, 24])55 MayaCmds.setKeyframe(nodeName, value=1.5, attribute='shearXY', t=12)56 MayaCmds.setKeyframe(nodeName, value=5, attribute='shearYZ', t=12)57 MayaCmds.setKeyframe(nodeName, value=2.5, attribute='shearXZ', t=12)58 # translate59 MayaCmds.setKeyframe('test', value=0, attribute='translateX',60 t=[1, 24])61 MayaCmds.setKeyframe('test', value=0, attribute='translateY',62 t=[1, 24])63 MayaCmds.setKeyframe('test', value=0, attribute='translateZ',64 t=[1, 24])65 MayaCmds.setKeyframe('test', value=1.5, attribute='translateX', t=12)66 MayaCmds.setKeyframe('test', value=5, attribute='translateY', t=12)67 MayaCmds.setKeyframe('test', value=2.5, attribute='translateZ', t=12)68 # rotate69 MayaCmds.setKeyframe('test', value=0, attribute='rotateX', t=[1, 24])70 MayaCmds.setKeyframe('test', value=0, attribute='rotateY', t=[1, 24])71 MayaCmds.setKeyframe('test', value=0, attribute='rotateZ', t=[1, 24])72 MayaCmds.setKeyframe('test', value=24, attribute='rotateX', t=12)73 MayaCmds.setKeyframe('test', value=53, attribute='rotateY', t=12)74 MayaCmds.setKeyframe('test', value=90, attribute='rotateZ', t=12)75 # scale76 MayaCmds.setKeyframe('test', value=1, attribute='scaleX', t=[1, 24])77 MayaCmds.setKeyframe('test', value=1, attribute='scaleY', t=[1, 24])78 MayaCmds.setKeyframe('test', value=1, attribute='scaleZ', t=[1, 24])79 MayaCmds.setKeyframe('test', value=1.2, attribute='scaleX', t=12)80 MayaCmds.setKeyframe('test', value=1.5, attribute='scaleY', t=12)81 MayaCmds.setKeyframe('test', value=1.5, attribute='scaleZ', t=12)82 # rotate pivot83 MayaCmds.setKeyframe('test', value=0.5, attribute='rotatePivotX',84 t=[1, 24])85 MayaCmds.setKeyframe('test', value=-0.1, attribute='rotatePivotY',86 t=[1, 24])87 MayaCmds.setKeyframe('test', value=1, attribute='rotatePivotZ',88 t=[1, 24])89 MayaCmds.setKeyframe('test', value=0.8, attribute='rotatePivotX', t=12)90 MayaCmds.setKeyframe('test', value=1.5, attribute='rotatePivotY', t=12)91 MayaCmds.setKeyframe('test', value=-1, attribute='rotatePivotZ', t=12)92 # scale pivot93 MayaCmds.setKeyframe('test', value=1.2, attribute='scalePivotX',94 t=[1, 24])95 MayaCmds.setKeyframe('test', value=1.0, attribute='scalePivotY',96 t=[1, 24])97 MayaCmds.setKeyframe('test', value=1.2, attribute='scalePivotZ',98 t=[1, 24])99 MayaCmds.setKeyframe('test', value=1.4, attribute='scalePivotX', t=12)100 MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotY', t=12)101 MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotZ', t=12)102 self.__files.append(util.expandFileName('testAnimTransformReadWrite.abc'))103 self.__files.append(util.expandFileName('testAnimTransformReadWrite01_14.abc'))104 self.__files.append(util.expandFileName('testAnimTransformReadWrite15_24.abc'))105 MayaCmds.AbcExport(j='-fr 1 14 -root test -file ' + self.__files[-2])106 MayaCmds.AbcExport(j='-fr 15 24 -root test -file ' + self.__files[-1])107 subprocess.call(self.__abcStitcher + self.__files[-3:])108 MayaCmds.AbcImport(self.__files[-3], mode='open')109 # frame 1110 MayaCmds.currentTime(1, update=True)111 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))112 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))113 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))114 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))115 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))116 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))117 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))118 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))119 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))120 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))121 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))122 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))123 self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))124 self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))125 self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))126 self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))127 self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))128 self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))129 # frame 12130 MayaCmds.currentTime(12, update=True);131 abcNodeName = MayaCmds.ls(exactType='AlembicNode')132 MayaCmds.dgeval(abcNodeName, verbose=True)133 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.shearXY'))134 self.failUnlessEqual(5, MayaCmds.getAttr('test.shearYZ'))135 self.failUnlessEqual(2.5, MayaCmds.getAttr('test.shearXZ'))136 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.translateX'))137 self.failUnlessEqual(5, MayaCmds.getAttr('test.translateY'))138 self.failUnlessEqual(2.5, MayaCmds.getAttr('test.translateZ'))139 self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr('test.rotateX'), 4)140 self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr('test.rotateY'), 4)141 self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr('test.rotateZ'), 4)142 self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scaleX'))143 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleY'))144 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleZ'))145 self.failUnlessEqual(0.8, MayaCmds.getAttr('test.rotatePivotX'))146 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.rotatePivotY'))147 self.failUnlessEqual(-1, MayaCmds.getAttr('test.rotatePivotZ'))148 self.failUnlessEqual(1.4, MayaCmds.getAttr('test.scalePivotX'))149 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotY'))150 self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotZ'))151 # frame 24152 MayaCmds.currentTime(24, update=True);153 abcNodeName = MayaCmds.ls(exactType='AlembicNode')154 MayaCmds.dgeval(abcNodeName, verbose=True)155 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))156 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))157 self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))158 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))159 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))160 self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))161 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))162 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))163 self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))164 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))165 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))166 self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))167 self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))168 self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))169 self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))170 self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))171 self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))172 self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))173 def testSampledConnectionDetectionRW(self):174 # connect to plugs at parent level and see if when loaded back175 # the sampled channels are recognized correctly176 driver = MayaCmds.createNode('transform', n='driverTrans')177 # shear178 MayaCmds.setKeyframe(driver, value=0, attribute='shearXY', t=[1, 24])179 MayaCmds.setKeyframe(driver, value=0, attribute='shearYZ', t=[1, 24])180 MayaCmds.setKeyframe(driver, value=0, attribute='shearXZ', t=[1, 24])181 MayaCmds.setKeyframe(driver, value=1.5, attribute='shearXY', t=12)182 MayaCmds.setKeyframe(driver, value=5, attribute='shearYZ', t=12)183 MayaCmds.setKeyframe(driver, value=2.5, attribute='shearXZ', t=12)184 # translate185 MayaCmds.setKeyframe(driver, value=0, attribute='translateX',186 t=[1, 24])187 MayaCmds.setKeyframe(driver, value=0, attribute='translateY',188 t=[1, 24])189 MayaCmds.setKeyframe(driver, value=0, attribute='translateZ',190 t=[1, 24])191 MayaCmds.setKeyframe(driver, value=1.5, attribute='translateX', t=12)192 MayaCmds.setKeyframe(driver, value=5, attribute='translateY', t=12)193 MayaCmds.setKeyframe(driver, value=2.5, attribute='translateZ', t=12)194 # rotate195 MayaCmds.setKeyframe(driver, value=0, attribute='rotateX', t=[1, 24])196 MayaCmds.setKeyframe(driver, value=0, attribute='rotateY', t=[1, 24])197 MayaCmds.setKeyframe(driver, value=0, attribute='rotateZ', t=[1, 24])198 MayaCmds.setKeyframe(driver, value=24, attribute='rotateX', t=12)199 MayaCmds.setKeyframe(driver, value=53, attribute='rotateY', t=12)200 MayaCmds.setKeyframe(driver, value=90, attribute='rotateZ', t=12)201 # scale202 MayaCmds.setKeyframe(driver, value=1, attribute='scaleX', t=[1, 24])203 MayaCmds.setKeyframe(driver, value=1, attribute='scaleY', t=[1, 24])204 MayaCmds.setKeyframe(driver, value=1, attribute='scaleZ', t=[1, 24])205 MayaCmds.setKeyframe(driver, value=1.2, attribute='scaleX', t=12)206 MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleY', t=12)207 MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleZ', t=12)208 # rotate pivot209 MayaCmds.setKeyframe(driver, value=0.5, attribute='rotatePivotX',210 t=[1, 24])211 MayaCmds.setKeyframe(driver, value=-0.1, attribute='rotatePivotY',212 t=[1, 24])213 MayaCmds.setKeyframe(driver, value=1, attribute='rotatePivotZ',214 t=[1, 24])215 MayaCmds.setKeyframe(driver, value=0.8, attribute='rotatePivotX', t=12)216 MayaCmds.setKeyframe(driver, value=1.5, attribute='rotatePivotY', t=12)217 MayaCmds.setKeyframe(driver, value=-1, attribute='rotatePivotZ', t=12)218 # scale pivot219 MayaCmds.setKeyframe(driver, value=1.2, attribute='scalePivotX',220 t=[1, 24])221 MayaCmds.setKeyframe(driver, value=1.0, attribute='scalePivotY',222 t=[1, 24])223 MayaCmds.setKeyframe(driver, value=1.2, attribute='scalePivotZ',224 t=[1, 24])225 MayaCmds.setKeyframe(driver, value=1.4, attribute='scalePivotX', t=12)226 MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotY', t=12)227 MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotZ', t=12)228 # create the transform node that's been driven by the connections229 driven = MayaCmds.createNode('transform', n = 'drivenTrans')230 MayaCmds.connectAttr(driver+'.translate', driven+'.translate')231 MayaCmds.connectAttr(driver+'.scale', driven+'.scale')232 MayaCmds.connectAttr(driver+'.rotate', driven+'.rotate')233 MayaCmds.connectAttr(driver+'.shear', driven+'.shear')234 MayaCmds.connectAttr(driver+'.rotatePivot', driven+'.rotatePivot')235 MayaCmds.connectAttr(driver+'.scalePivot', driven+'.scalePivot')236 self.__files.append(util.expandFileName('testSampledTransformDetection.abc'))237 MayaCmds.AbcExport(j='-fr 1 24 -root drivenTrans -file ' + self.__files[-1])238 # reading test239 MayaCmds.AbcImport(self.__files[-1], mode='open')240 # frame 1241 MayaCmds.currentTime(1, update=True)242 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXY'))243 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearYZ'))244 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXZ'))245 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateX'))246 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateY'))247 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateZ'))248 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateX'))249 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateY'))250 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateZ'))251 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleX'))252 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleY'))253 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleZ'))254 self.failUnlessEqual(0.5, MayaCmds.getAttr(driven+'.rotatePivotX'))255 self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven+'.rotatePivotY'))256 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.rotatePivotZ'))257 self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotX'))258 self.failUnlessEqual(1.0, MayaCmds.getAttr(driven+'.scalePivotY'))259 self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotZ'))260 # frame 12261 MayaCmds.currentTime(12, update=True);262 abcNodeName = MayaCmds.ls(exactType='AlembicNode')263 MayaCmds.dgeval(abcNodeName, verbose=True)264 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.shearXY'))265 self.failUnlessEqual(5, MayaCmds.getAttr(driven+'.shearYZ'))266 self.failUnlessEqual(2.5, MayaCmds.getAttr(driven+'.shearXZ'))267 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.translateX'))268 self.failUnlessEqual(5, MayaCmds.getAttr(driven+'.translateY'))269 self.failUnlessEqual(2.5, MayaCmds.getAttr(driven+'.translateZ'))270 self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr(driven+'.rotateX'),271 4)272 self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr(driven+'.rotateY'),273 4)274 self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr(driven+'.rotateZ'), 4)275 self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scaleX'))276 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scaleY'))277 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scaleZ'))278 self.failUnlessEqual(0.8, MayaCmds.getAttr(driven+'.rotatePivotX'))279 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.rotatePivotY'))280 self.failUnlessEqual(-1, MayaCmds.getAttr(driven+'.rotatePivotZ'))281 self.failUnlessEqual(1.4, MayaCmds.getAttr(driven+'.scalePivotX'))282 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scalePivotY'))283 self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scalePivotZ'))284 # frame 24285 MayaCmds.currentTime(24, update=True);286 abcNodeName = MayaCmds.ls(exactType='AlembicNode')287 MayaCmds.dgeval(abcNodeName, verbose=True)288 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXY'))289 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearYZ'))290 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXZ'))291 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateX'))292 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateY'))293 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateZ'))294 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateX'))295 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateY'))296 self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateZ'))297 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleX'))298 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleY'))299 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleZ'))300 self.failUnlessEqual(0.5, MayaCmds.getAttr(driven+'.rotatePivotX'))301 self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven+'.rotatePivotY'))302 self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.rotatePivotZ'))303 self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotX'))304 self.failUnlessEqual(1.0, MayaCmds.getAttr(driven+'.scalePivotY'))...
eulerFilter_test.py
Source:eulerFilter_test.py
1##-*****************************************************************************2##3## Copyright (c) 2009-2011,4## Sony Pictures Imageworks, Inc. and5## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.6##7## All rights reserved.8##9## Redistribution and use in source and binary forms, with or without10## modification, are permitted provided that the following conditions are11## met:12## * Redistributions of source code must retain the above copyright13## notice, this list of conditions and the following disclaimer.14## * Redistributions in binary form must reproduce the above15## copyright notice, this list of conditions and the following disclaimer16## in the documentation and/or other materials provided with the17## distribution.18## * Neither the name of Sony Pictures Imageworks, nor19## Industrial Light & Magic nor the names of their contributors may be used20## to endorse or promote products derived from this software without specific21## prior written permission.22##23## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS24## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT25## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR26## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT27## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT29## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,30## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY31## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT32## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE33## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34##35##-*****************************************************************************36import maya.cmds as MayaCmds37import os38import unittest39import util40#41# Test AbcExport [-eulerFilter]42# Note that the Euler Filter is applied to the sampled curve instead of43# the original anim curve.44# The result would be different than applying Euler Filter in Graph Editor.45#46class EulerFilterTest(unittest.TestCase):47 def setUp(self):48 MayaCmds.file(new=True, force=True)49 self.__files = []50 def tearDown(self):51 MayaCmds.file(new=True, force=True)52 for f in self.__files:53 os.remove(f)54 def testEulerFilter_RotateY(self):55 nodeName = MayaCmds.createNode('transform', n = 'test')56 # rotate Y57 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = 10, t = 1)58 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = 20, t = 2)59 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -330, t = 3)60 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -320, t = 4)61 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = 50, t = 5)62 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -300, t = 6)63 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -290, t = 7)64 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -280, t = 8)65 self.__files.append(util.expandFileName('testEulerFilter_RotY.abc'))66 self.__files.append(util.expandFileName('testEulerFilter_RotY_EulerFiltered.abc'))67 MayaCmds.AbcExport(j = '-fr 1 8 -root test -file ' + self.__files[-2])68 MayaCmds.AbcExport(j = '-fr 1 8 -root test -eulerFilter -file ' + self.__files[-1])69 # Check file without euler filter70 MayaCmds.AbcImport(self.__files[-2], mode='open')71 MayaCmds.currentTime(1, update = True)72 self.failUnlessAlmostEqual(10, MayaCmds.getAttr('test.rotateY'))73 MayaCmds.currentTime(2, update = True)74 self.failUnlessAlmostEqual(20, MayaCmds.getAttr('test.rotateY'))75 MayaCmds.currentTime(3, update = True)76 self.failUnlessAlmostEqual(-330, MayaCmds.getAttr('test.rotateY'))77 MayaCmds.currentTime(4, update = True)78 self.failUnlessAlmostEqual(-320, MayaCmds.getAttr('test.rotateY'))79 MayaCmds.currentTime(5, update = True)80 self.failUnlessAlmostEqual(50, MayaCmds.getAttr('test.rotateY'))81 MayaCmds.currentTime(6, update = True)82 self.failUnlessAlmostEqual(-300, MayaCmds.getAttr('test.rotateY'))83 MayaCmds.currentTime(7, update = True)84 self.failUnlessAlmostEqual(-290, MayaCmds.getAttr('test.rotateY'))85 MayaCmds.currentTime(8, update = True)86 self.failUnlessAlmostEqual(-280, MayaCmds.getAttr('test.rotateY'))87 # Check file with euler filter88 MayaCmds.AbcImport(self.__files[-1], mode='open')89 MayaCmds.currentTime(1, update = True)90 self.failUnlessAlmostEqual(10, MayaCmds.getAttr('test.rotateY'))91 MayaCmds.currentTime(2, update = True)92 self.failUnlessAlmostEqual(20, MayaCmds.getAttr('test.rotateY'))93 MayaCmds.currentTime(3, update = True)94 self.failUnlessAlmostEqual(30, MayaCmds.getAttr('test.rotateY'))95 MayaCmds.currentTime(4, update = True)96 self.failUnlessAlmostEqual(40, MayaCmds.getAttr('test.rotateY'))97 MayaCmds.currentTime(5, update = True)98 self.failUnlessAlmostEqual(50, MayaCmds.getAttr('test.rotateY'))99 MayaCmds.currentTime(6, update = True)100 self.failUnlessAlmostEqual(60, MayaCmds.getAttr('test.rotateY'))101 MayaCmds.currentTime(7, update = True)102 self.failUnlessAlmostEqual(70, MayaCmds.getAttr('test.rotateY'))103 MayaCmds.currentTime(8, update = True)104 self.failUnlessAlmostEqual(80, MayaCmds.getAttr('test.rotateY'))105 def testEulerFilter_Rotate(self):106 nodeName = MayaCmds.createNode('transform', n = 'test')107 # Rotate108 MayaCmds.setKeyframe('test', attribute = 'rotateX', value = 90, t = 1)109 MayaCmds.setKeyframe('test', attribute = 'rotateX', value = 460, t = 2)110 MayaCmds.setKeyframe('test', attribute = 'rotateX', value = 110, t = 3)111 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -10, t = 1)112 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = -40, t = 2)113 MayaCmds.setKeyframe('test', attribute = 'rotateY', value = 290, t = 3)114 MayaCmds.setKeyframe('test', attribute = 'rotateZ', value = 270, t = 1)115 MayaCmds.setKeyframe('test', attribute = 'rotateZ', value = 0, t = 2)116 MayaCmds.setKeyframe('test', attribute = 'rotateZ', value = 810, t = 3)117 # Rotate Order118 MayaCmds.setAttr('test.rotateOrder', 1)119 # Rotate Axis120 MayaCmds.setKeyframe('test', attribute = 'rotateAxisX', value = 90, t = 1)121 MayaCmds.setKeyframe('test', attribute = 'rotateAxisX', value = 460, t = 2)122 MayaCmds.setKeyframe('test', attribute = 'rotateAxisX', value = 110, t = 3)123 MayaCmds.setKeyframe('test', attribute = 'rotateAxisY', value = -10, t = 1)124 MayaCmds.setKeyframe('test', attribute = 'rotateAxisY', value = -40, t = 2)125 MayaCmds.setKeyframe('test', attribute = 'rotateAxisY', value = 290, t = 3)126 MayaCmds.setKeyframe('test', attribute = 'rotateAxisZ', value = 270, t = 1)127 MayaCmds.setKeyframe('test', attribute = 'rotateAxisZ', value = 0, t = 2)128 MayaCmds.setKeyframe('test', attribute = 'rotateAxisZ', value = 810, t = 3)129 self.__files.append(util.expandFileName('testEulerFilter_Rotate.abc'))130 self.__files.append(util.expandFileName('testEulerFilter_Rotate_EulerFiltered.abc'))131 MayaCmds.AbcExport(j = '-fr 1 3 -root test -file ' + self.__files[-2])132 MayaCmds.AbcExport(j = '-fr 1 3 -root test -eulerFilter -file ' + self.__files[-1])133 # Check file without euler filter134 # Maya uses quaternion to represent Rotate Axis and Joint Orient internally.135 # The number from rotateAxis and jointOrient attribute might not be the same136 # as the values from their anim curves.137 MayaCmds.AbcImport(self.__files[-2], mode='open')138 MayaCmds.currentTime(3, update = True) # refresh139 MayaCmds.currentTime(1, update = True)140 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))141 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateX'))142 self.failUnlessAlmostEqual(-10, MayaCmds.getAttr('test.rotateY'))143 self.failUnlessAlmostEqual(270, MayaCmds.getAttr('test.rotateZ'))144 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateAxisX'))145 self.failUnlessAlmostEqual(-10, MayaCmds.getAttr('test.rotateAxisY'))146 self.failUnlessAlmostEqual(-90, MayaCmds.getAttr('test.rotateAxisZ'))147 MayaCmds.currentTime(2, update = True)148 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))149 self.failUnlessAlmostEqual(460, MayaCmds.getAttr('test.rotateX'))150 self.failUnlessAlmostEqual(-40, MayaCmds.getAttr('test.rotateY'))151 self.failUnlessAlmostEqual(0, MayaCmds.getAttr('test.rotateZ'))152 self.failUnlessAlmostEqual(100, MayaCmds.getAttr('test.rotateAxisX'))153 self.failUnlessAlmostEqual(-40, MayaCmds.getAttr('test.rotateAxisY'))154 self.failUnlessAlmostEqual(0, MayaCmds.getAttr('test.rotateAxisZ'))155 MayaCmds.currentTime(3, update = True)156 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))157 self.failUnlessAlmostEqual(110, MayaCmds.getAttr('test.rotateX'))158 self.failUnlessAlmostEqual(290, MayaCmds.getAttr('test.rotateY'))159 self.failUnlessAlmostEqual(810, MayaCmds.getAttr('test.rotateZ'))160 self.failUnlessAlmostEqual(110, MayaCmds.getAttr('test.rotateAxisX'))161 self.failUnlessAlmostEqual(-70, MayaCmds.getAttr('test.rotateAxisY'))162 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateAxisZ'))163 # Check file with euler filter164 MayaCmds.AbcImport(self.__files[-1], mode='open')165 MayaCmds.currentTime(3, update = True) # refresh166 MayaCmds.currentTime(1, update = True)167 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))168 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateX'))169 self.failUnlessAlmostEqual(-10, MayaCmds.getAttr('test.rotateY'))170 self.failUnlessAlmostEqual(270, MayaCmds.getAttr('test.rotateZ'))171 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateAxisX'))172 self.failUnlessAlmostEqual(-10, MayaCmds.getAttr('test.rotateAxisY'))173 self.failUnlessAlmostEqual(-90, MayaCmds.getAttr('test.rotateAxisZ'))174 MayaCmds.currentTime(2, update = True)175 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))176 self.failUnlessAlmostEqual(100, MayaCmds.getAttr('test.rotateX'))177 self.failUnlessAlmostEqual(-40, MayaCmds.getAttr('test.rotateY'))178 self.failUnlessAlmostEqual(360, MayaCmds.getAttr('test.rotateZ'))179 self.failUnlessAlmostEqual(100, MayaCmds.getAttr('test.rotateAxisX'))180 self.failUnlessAlmostEqual(-40, MayaCmds.getAttr('test.rotateAxisY'))181 self.failUnlessAlmostEqual(0, MayaCmds.getAttr('test.rotateAxisZ'))182 MayaCmds.currentTime(3, update = True)183 self.assertEqual(1, MayaCmds.getAttr('test.rotateOrder'))184 self.failUnlessAlmostEqual(110, MayaCmds.getAttr('test.rotateX'))185 self.failUnlessAlmostEqual(-70, MayaCmds.getAttr('test.rotateY'))186 self.failUnlessAlmostEqual(450, MayaCmds.getAttr('test.rotateZ'))187 self.failUnlessAlmostEqual(110, MayaCmds.getAttr('test.rotateAxisX'))188 self.failUnlessAlmostEqual(-70, MayaCmds.getAttr('test.rotateAxisY'))189 self.failUnlessAlmostEqual(90, MayaCmds.getAttr('test.rotateAxisZ'))...
scatter.py
Source:scatter.py
...165 self.zmax_rotate = 360166 def create_polygon(self):167 if poly_surface_cmb.currentText() = 0168 return cmds.polySphere169 def rotate(self):170 """Makes instances rotate randomly."""171 result = cmds.poly172 transformName = result[0]173 for i in range(0, 50):174 instanceResult = cmds.instance(transformName, name=transformName +175 '_instance#')176 xRot = random.uniform(min(a), max(b))177 yRot = random.uniform(min(c), max(d))178 zRot = random.uniform(min(e), max(f))179 cmds.rotate(xRot, yRot, zRot, instanceResult)180 return181 #polygons = ['Sphere', 'Cube', 'Cylinder', 'Cone', 'Torus', 'Plane', 'Disc']182 #cmds.ls(shapes=True)...
staticTransform_test.py
Source:staticTransform_test.py
1##-*****************************************************************************2##3## Copyright (c) 2009-2011,4## Sony Pictures Imageworks, Inc. and5## Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.6##7## All rights reserved.8##9## Redistribution and use in source and binary forms, with or without10## modification, are permitted provided that the following conditions are11## met:12## * Redistributions of source code must retain the above copyright13## notice, this list of conditions and the following disclaimer.14## * Redistributions in binary form must reproduce the above15## copyright notice, this list of conditions and the following disclaimer16## in the documentation and/or other materials provided with the17## distribution.18## * Neither the name of Sony Pictures Imageworks, nor19## Industrial Light & Magic nor the names of their contributors may be used20## to endorse or promote products derived from this software without specific21## prior written permission.22##23## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS24## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT25## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR26## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT27## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT29## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,30## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY31## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT32## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE33## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34##35##-*****************************************************************************36from maya import cmds as MayaCmds37import os38import unittest39import util40class TransformTest(unittest.TestCase):41 def setUp(self):42 MayaCmds.file(new=True, force=True)43 self.__files = []44 def tearDown(self):45 for f in self.__files :46 os.remove(f)47 def testStaticTransformReadWrite(self):48 nodeName = MayaCmds.polyCube(n='cube')49 MayaCmds.setAttr('cube.translate', 2.456, -3.95443, 0, type="double3")50 MayaCmds.setAttr('cube.rotate', 45, 15, -90, type="double3")51 MayaCmds.setAttr('cube.rotateOrder', 4)52 MayaCmds.setAttr('cube.scale', 1.5, 5, 1, type="double3")53 MayaCmds.setAttr('cube.shearXY',1)54 MayaCmds.setAttr('cube.rotatePivot', 13.52, 0.0, 20.25, type="double3")55 MayaCmds.setAttr('cube.rotatePivotTranslate', 0.5, 0.0, 0.25,56 type="double3")57 MayaCmds.setAttr('cube.scalePivot', 10.7, 2.612, 0.2, type="double3")58 MayaCmds.setAttr('cube.scalePivotTranslate', 0.0, 0.0, 0.25,59 type="double3")60 MayaCmds.setAttr('cube.inheritsTransform', 0)61 self.__files.append(util.expandFileName('testStaticTransformReadWrite.abc'))62 MayaCmds.AbcExport(j='-root %s -file %s' % (nodeName[0], self.__files[-1]))63 # reading test64 MayaCmds.AbcImport(self.__files[-1], mode='open')65 self.failUnlessAlmostEqual(2.456,66 MayaCmds.getAttr('cube.translateX'), 4)67 self.failUnlessAlmostEqual(-3.95443,68 MayaCmds.getAttr('cube.translateY'), 4)69 self.failUnlessAlmostEqual(0.0, MayaCmds.getAttr('cube.translateZ'), 4)70 self.failUnlessAlmostEqual(45, MayaCmds.getAttr('cube.rotateX'), 4)71 self.failUnlessAlmostEqual(15, MayaCmds.getAttr('cube.rotateY'), 4)72 self.failUnlessAlmostEqual(-90, MayaCmds.getAttr('cube.rotateZ'), 4)73 self.failUnlessEqual(4, MayaCmds.getAttr('cube.rotateOrder'))74 self.failUnlessAlmostEqual(1.5, MayaCmds.getAttr('cube.scaleX'), 4)75 self.failUnlessAlmostEqual(5, MayaCmds.getAttr('cube.scaleY'), 4)76 self.failUnlessAlmostEqual(1, MayaCmds.getAttr('cube.scaleZ'), 4)77 self.failUnlessAlmostEqual(1, MayaCmds.getAttr('cube.shearXY'), 4)78 self.failUnlessAlmostEqual(13.52,79 MayaCmds.getAttr('cube.rotatePivotX'), 4)80 self.failUnlessAlmostEqual(0.0,81 MayaCmds.getAttr('cube.rotatePivotY'), 4)82 self.failUnlessAlmostEqual(20.25,83 MayaCmds.getAttr('cube.rotatePivotZ'), 4)84 self.failUnlessAlmostEqual(0.5,85 MayaCmds.getAttr('cube.rotatePivotTranslateX'), 4)86 self.failUnlessAlmostEqual(0.0,87 MayaCmds.getAttr('cube.rotatePivotTranslateY'), 4)88 self.failUnlessAlmostEqual(0.25,89 MayaCmds.getAttr('cube.rotatePivotTranslateZ'), 4)90 self.failUnlessAlmostEqual(10.7,91 MayaCmds.getAttr('cube.scalePivotX'), 4)92 self.failUnlessAlmostEqual(2.612,93 MayaCmds.getAttr('cube.scalePivotY'), 4)94 self.failUnlessAlmostEqual(0.2,95 MayaCmds.getAttr('cube.scalePivotZ'), 4)96 self.failUnlessAlmostEqual(0.0,97 MayaCmds.getAttr('cube.scalePivotTranslateX'), 4)98 self.failUnlessAlmostEqual(0.0,99 MayaCmds.getAttr('cube.scalePivotTranslateY'), 4)100 self.failUnlessAlmostEqual(0.25,101 MayaCmds.getAttr('cube.scalePivotTranslateZ'), 4)102 self.failUnlessEqual(0, MayaCmds.getAttr('cube.inheritsTransform'))103 def testStaticTransformRotateOrder(self):104 nodeName = MayaCmds.polyCube(n='cube')105 MayaCmds.setAttr('cube.rotate', 45, 1, -90, type="double3")106 MayaCmds.setAttr('cube.rotateOrder', 5)107 self.__files.append(util.expandFileName('testStaticTransformRotateOrder.abc'))108 MayaCmds.AbcExport(j='-root %s -file %s' % (nodeName[0], self.__files[-1]))109 MayaCmds.AbcImport(self.__files[-1], mode='open')110 self.failUnlessEqual(5, MayaCmds.getAttr('cube.rotateOrder'))111 self.failUnlessAlmostEqual(45, MayaCmds.getAttr('cube.rotateX'), 4)112 self.failUnlessAlmostEqual(1, MayaCmds.getAttr('cube.rotateY'), 4)113 self.failUnlessAlmostEqual(-90, MayaCmds.getAttr('cube.rotateZ'), 4)114 def testStaticTransformRotateOrder2(self):115 nodeName = MayaCmds.polyCube(n='cube')116 MayaCmds.setAttr('cube.rotate', 45, 0, -90, type="double3")117 MayaCmds.setAttr('cube.rotateOrder', 5)118 self.__files.append(util.expandFileName('testStaticTransformRotateOrder2.abc'))119 MayaCmds.AbcExport(j='-root %s -file %s' % (nodeName[0], self.__files[-1]))120 MayaCmds.AbcImport(self.__files[-1], mode='open')121 self.failUnlessEqual(5, MayaCmds.getAttr('cube.rotateOrder'))122 self.failUnlessAlmostEqual(45, MayaCmds.getAttr('cube.rotateX'), 4)123 self.failUnlessAlmostEqual(0, MayaCmds.getAttr('cube.rotateY'), 4)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!