def snapBake(source, target): """ Snap and bake the position of the source to the target. Delete all keys first @param source: Source transform @param target: Target transform """ # Contraint mel.eval( 'cutKey -t ":" -f ":" -at "tx" -at "ty" -at "tz" -at "rx" -at "ry" -at "rz" %s;' % target) # Contraint con = pm.parentConstraint(source, target) # Bake Animation bakeAnimation(target) # Delete the contraint pm.delete(con) # Get the scale value scale = target.getScale() # Transfer mel.eval('cutKey -t ":" -f ":" -at "sx" -at "sy" -at "sz" %s;' % target) # Scale try: target.setScale(scale) except: logger.warning("Unable to set the target scale")
def transfer_shape(source, target, snap_to_target=True, fix_name=False): """ Reparent a shape node from one parent to another @param source: The source dag which contains the shape @param target: The source dag which will have the new shape the shape @param snap_to_target: Should be we reparent with world space or object space @param fix_name: Should we match the name of the shape to the new target @return: """ source = force_pynode(source) target = force_pynode(target) if snap_to_target: snap(source, target) pm.makeIdentity(source, apply=1) if source.getShape().type() != "locator": try: pm.cluster(source) pm.delete(source, ch=1) except RuntimeError: logger.warning("Cannot cluster {}".format(source)) oldShape = source.getShape() pm.parent(oldShape, target, shape=1, relative=1) if fix_name: fix_shape_name(target) return oldShape
def _closeExistingWindow_(self): """Ensures there is only instance of the PySide GUI""" for qt in QtGui.qApp.topLevelWidgets(): # Check that there is only one instance of the APP try: if qt.__class__.__name__ == self.__class__.__name__: qt.close() except: logger.warning('Failed to close an instance of this GUI:%s' % str(self))
def mel2pyStr(text, namespace): """ Convert a mel command to pymel command and print the result @param text: The mel command @param namespace: The module name """ if not text.endswith(";"): logger.warning('Please end the mel code with ";"') else: import pymel.tools.mel2py as py2mel print py2mel.mel2pyStr(text, pymelNamespace=namespace)
def melEval(evalStatment, echo=False): '''evaluate mel statement line for line. Print out error message for failed eval states @param evalStatment (string) the mel command which need to be evaluated. Multiple lines of mel commands can also be evaluated. @param echo (bool) print out the mel statement before evaluating. Useful for debugging ''' for statement in evalStatment.split(";"): try: if echo: print statement mel.eval("%s;" % statement) except: logger.warning("## ## ## FAILED MEL STATEMENT: %s## ## ## " % ("%s;" % statement))
def setWindowIcon(self, iconPath): """Set the icon for via QIcon""" # Make sure the icon exists if not libFile.exists(iconPath): logger.warning("No Icon exists for path:%s" % iconPath) else: # Set the icon icon = QtGui.QIcon(QtGui.QPixmap(iconPath)) try: super(QMainWindow, self).setWindowIcon(icon) except Exception as e: print e logger.warning("Failed to set Icon")
def snapBake(source, target): """ Snap and bake the position of the source to the target. Delete all keys first @param source: Source transform @param target: Target transform """ # Contraint mel.eval('cutKey -t ":" -f ":" -at "tx" -at "ty" -at "tz" -at "rx" -at "ry" -at "rz" %s;' % target) # Contraint con = pm.parentConstraint(source, target) # Bake Animation bakeAnimation(target) # Delete the contraint pm.delete(con) # Get the scale value scale = target.getScale() # Transfer mel.eval('cutKey -t ":" -f ":" -at "sx" -at "sy" -at "sz" %s;' % target) # Scale try: target.setScale(scale) except: logger.warning("Unable to set the target scale")