def run(self): """Doc...""" self.saveSelection() count = self.fetch('count', 1000) self._size = self.fetch('size', 0.1) self._padding = self.fetch('padding', 0.0) transforms = cmds.ls(selection=True, type='transform') if not transforms: self._cleanup() self.putErrorResult(u'ERROR: No transforms selected') return shapes = [] totalVolume = 0.0 shapeCount = 0 for transform in transforms: shapeNames = cmds.listRelatives(transforms, shapes=True) if not shapeNames: continue for shape in shapeNames: try: box = TransformUtils.getBoundingBox(shape) cmds.select(shape, replace=True) shapeVolume = nimble.executeMelCommand('computePolysetVolume') totalVolume += shapeVolume shapes.append(dict( transform=transform, name=shape, box=box, weight=float(shapeVolume)) ) shapeCount += 1 except Exception as err: self._cleanup() NimbleEnvironment.logError(u'ERROR: Shape processing', err) self.putErrorResult( u'ERROR: Unable to process selection item %s -> %s' % (transform, shape) ) return if shapeCount == 0: self._cleanup() self.putErrorResult(u'ERROR: No polygon transforms found in selection') return try: for shape in shapes: if not self._createMeshPointNode(shape): self._cleanup() print(u'ERROR: Creation failure') self.putErrorResult(u'ERROR: Unable to create point test node') shape['weight'] /= totalVolume shapeCount = int(round(float(count)*shape['weight'])) for i in range(shapeCount): self._create(shape) self._removeMeshPointNode() except Exception as err: self._cleanup() print(Logger.createErrorMessage(u'ERROR: Creation failure', err)) self.putErrorResult(u'ERROR: Unable to create random box') return self._cleanup()
# test_melCommands.py # (C)2014 # Scott Ernst """ A unit test for the Nimble bridge to test the execution of mel commands. """ from __future__ import print_function, absolute_import, unicode_literals, division import nimble from nimble import cmds from nimble.error.MayaCommandException import MayaCommandException try: cubeNode = cmds.polyCube(width=2, height=2, depth=4) print('CREATED:', cubeNode) except MayaCommandException as err: print(err.echo()) raise cubeShape = cmds.listRelatives(cubeNode[0], shapes=True) print('SHAPE:', cubeShape) cmds.select(cubeShape[0], replace=True) result = nimble.executeMelCommand('computePolysetVolume', nimbleResult=True) print(result.echo(verbose=True, pretty=True))