def lcObj_exportObjs(*args, **kwargs): ''' Export .obj files from selected geometry, either as one combined file or as individual files per object. Will recognize and convert poly smooth preview to geometry for export ''' global prefix path = pm.textField(prefix+'_textField_export_path', query=True, text=True) objPrefix = pm.textField(prefix+'_textField_prefix', query=True, text=True) if objPrefix: objPrefix+='_' if path: sel = pm.ls(sl=True) if sel: sel = geometry.filterForGeometry(sel) print sel #undo is the easiest way to work on geometry temporarily pm.undoInfo(openChunk=True) if pm.checkBox(prefix+'_checkBox_use_smooth', query=True, v=True): for obj in sel: pm.select(obj) #find the objects currently displayed as smooth and create converted poly copies if pm.displaySmoothness(q=True, polygonObject=True)[0] == 3: pm.mel.performSmoothMeshPreviewToPolygon() if pm.checkBox(prefix+'_checkBox_export_indi', query=True, v=True): #export objects individually for obj in sel: pm.select(obj) name = str(obj) exportString = path+'/'+objPrefix+name+'.obj' pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True) else: #export as one object pm.select(sel) name = '' while name == '': dialog = pm.promptDialog(title='OBJ Name', message='Enter Name:', button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel') if dialog == 'OK': name = pm.promptDialog(query=True, text=True) if name: exportString = path+'/'+objPrefix+name+'.obj' pm.exportSelected(exportString, force=True, options='groups=1;ptgroups=1;materials=0;smoothing=1;normals=1', type='OBJexport', pr=True, es=True) else: pm.warning("You didn't type a name for your obj") if dialog == 'Cancel': break pm.undoInfo(closeChunk=True) pm.undo() pm.select(clear=True) else: pm.warning('Did you specify a path?')
def createCharacter(self): """ Clicked event for self.charSettings.createCharBtn Creates a new character """ pm.undoInfo(openChunk=True) inputName = self.charName.edit.text() charSuffix = self.charNameSuffix.edit.text() rootName = self.charSettings.rootName.edit.text() leftString = self.charSettings.leftString.edit.text() rightString = self.charSettings.rightString.edit.text() if len(inputName) and len(charSuffix): charName = inputName + charSuffix self.character = char.Char(charName, rootName=rootName, leftString=leftString, rightString=rightString) self.character.create() self.infoDock.infoDisplay.append('Created %s character' % charName) listItem = QtGui.QListWidgetItem() listItem.setText(self.character.chRootName) listItem.setTextAlignment(QtCore.Qt.AlignHCenter) self.bpCharList.addItem(listItem) pm.undoInfo(closeChunk=True)
def wrapper(*args, **kwargs): pm.undoInfo(openChunk=True) try: ret = func(*args, **kwargs) finally: pm.undoInfo(closeChunk=True) return ret
def Connect(src, dst): pm.undoInfo(openChunk=True) alembics = src if not isinstance(src, list): alembics = pm.ls(src, dagObjects=True, type='transform') targets = dst if not isinstance(dst, list): targets = pm.ls(dst, dagObjects=True, type='transform') attrs = ['translate', 'rotate', 'scale', 'visibility'] for node in targets: for abc in alembics: if node.longName().split(':')[-1] == abc.longName().split(':')[-1]: for attr in attrs: pm.connectAttr('%s.%s' % (abc, attr), '%s.%s' % (node, attr), force=True) # securing primary shape is connected pm.connectAttr('%s.worldMesh[0]' % abc.getShape(), '%s.inMesh' % node.getShape(), force=True) pm.undoInfo(closeChunk=True)
def doGuideCallback(self): gfs = self.mainUI.getGuide_chk.isChecked() pm.undoInfo(openChunk=True) try: self.doGuide(getFromScene=gfs) finally: pm.undoInfo(closeChunk=True)
def setLegHeight(self, value): pm.undoInfo(openChunk=True) if value > 10.0: value = value / 100.0 self.legHeight_spinBox.setValue(value) else: self.legHeight_slider.setValue(value*100) self.setJointScale(self.hips, value, self.legHeight) self.setJointScale(self.l_upperLeg, value, self.legHeight) self.setJointScale(self.l_lowerLeg, value, self.legHeight) self.setJointScale(self.l_foot, value, self.legHeight) self.setJointScale(self.l_toes, value, self.legHeight) self.setJointScale(self.l_toeEnd, value, self.legHeight) self.setJointScale(self.r_upperLeg, value, self.legHeight) self.setJointScale(self.r_lowerLeg, value, self.legHeight) self.setJointScale(self.r_foot, value, self.legHeight) self.setJointScale(self.r_toes, value, self.legHeight) self.setJointScale(self.r_toeEnd, value, self.legHeight) self.legHeight = value self.RebuildMesh() pm.undoInfo(closeChunk=True)
def doRigCallback(self): rs = self.mainUI.reapplySkin_chk.isChecked() pm.undoInfo(openChunk=True) try: self.doRig(reapplySkin=rs) finally: pm.undoInfo(closeChunk=True)
def __enter__(self): try: pm.undoInfo(openChunk=1) except TypeError: # Legacy support for before undo chunking existed pm.undoInfo(stateWithoutFlush=0) # turn undo off return self
def overrideAttrRun(self, mode): items = self.weightListWidget.selectedItems() if pm.editRenderLayerGlobals(q=1, crl=1) == 'defaultRenderLayer': return 0 attrList = [] pm.undoInfo(ock=1) for x in items: attrList.append(x.text()) for x in self.objectList: for y in attrList: try: if mode: pm.editRenderLayerAdjustment(x.attr(y)) else: overrideList = pm.editRenderLayerAdjustment(q=1) if x.attr(y).name() in overrideList: pm.editRenderLayerAdjustment(x.attr(y), remove=1) except: print x pm.undoInfo(cck=1)
def _ctrlDBL(self, controls): pmc.undoInfo(openChunk=True) if controls == []: controls = pmc.ls(sl=True) for control in controls: control_roo = pmc.xform(control, q=True, roo=True) control_mtx = pmc.xform(control, q=True, m=True, ws=True) control_parent = pmc.listRelatives(control, p=True) pmc.select(cl=True) locdbl_parent = pmc.spaceLocator(n='locDBL_parent_' + control) locdbl_offset = pmc.spaceLocator(n='locDBL_offset_' + control) pmc.xform(locdbl_parent, ws=True, m=control_mtx) pmc.xform(locdbl_offset, ws=True, m=control_mtx) pmc.parent(locdbl_offset, locdbl_parent) pmc.parent(locdbl_parent, control_parent) pmc.parent(control, locdbl_offset) if control_roo == 'xyz': pmc.xform(locdbl_offset, roo='zyx') if control_roo == 'yzx': pmc.xform(locdbl_offset, roo='xzy') if control_roo == 'zxy': pmc.xform(locdbl_offset, roo='yxz') if control_roo == 'xzy': pmc.xform(locdbl_offset, roo='yzx') if control_roo == 'yxz': pmc.xform(locdbl_offset, roo='zxy') if control_roo == 'zyx': pmc.xform(locdbl_offset, roo='xyz') md_trns = pmc.createNode('multiplyDivide', n='mdTRNS_locDBL_' + control) md_rot = pmc.createNode('multiplyDivide', n='mdROT_locDBL_' + control) md_scl = pmc.createNode('multiplyDivide', n='mdSCL_locDBL_' + control) pmc.setAttr(md_trns + '.input1', [-1, -1, -1]) pmc.setAttr(md_rot.input1, [-1, -1, -1]) pmc.setAttr(md_scl.input1, [1, 1, 1]) pmc.setAttr(md_scl.operation, 2) pmc.connectAttr(control + '.translate', md_trns + '.input2') pmc.connectAttr(control + '.rotate', md_rot + '.input2') pmc.connectAttr(control + '.scale', md_scl + '.input2') pmc.connectAttr(md_trns + '.output', locdbl_offset + '.translate') pmc.connectAttr(md_rot + '.output', locdbl_offset + '.rotate') pmc.connectAttr(md_scl + '.output', locdbl_offset + '.scale') pmc.setAttr(locdbl_parent + 'Shape.visibility', 0) pmc.setAttr(locdbl_offset + 'Shape.visibility', 0) pmc.undoInfo(closeChunk=True)
def meshHook(self): logger.debug(self.meshHookMode) pm.undoInfo(openChunk=True) try: attachTools.hookOnMesh(mode=self.meshHookMode) finally: pm.undoInfo(closeChunk=True)
def addParentSpace(self): sel = pm.ls(sl=True) if not sel: logger.warn('Selecione um objeto para space switch') return # todo se nao existir um grupo pai, pedir pra adicionar if not sel[0].getParent(): flags = QtGui.QMessageBox.StandardButton.Yes flags |= QtGui.QMessageBox.StandardButton.No question = "criar um grupo acima?" response = QtGui.QMessageBox.question(self, "Question", question, flags) if response: groupTools.zeroOut() spacelist = [x.text() for x in self.ui.spaceList_listWidget.selectedItems()] logger.debug(spacelist) # todo ver se ja existe o space a ser adicionado no switcher pm.undoInfo(openChunk=True) try: spaceTools.addSpc(target=sel[0], switcher=sel[0].getParent(), type='parent', spaceList=spacelist) finally: pm.undoInfo(closeChunk=True)
def tagEditDelShader_PB_hit(self): SG_list = self.getSgWithTag() shader_list = [] self.child_all_list = [] for sg in SG_list: shader = pm.listConnections(sg.rman__surface, source=True, scn=True) if len(shader) > 0: shader_list.append(shader[0]) self.allChildNode(shader[0], self.child_all_list) dm_shader = pm.listConnections(sg.rman__displacement, source=True, scn=True) if len(dm_shader) > 0: shader_list.append(dm_shader[0]) self.allChildNode(dm_shader[0], self.child_all_list) self.child_all_list = list(set(self.child_all_list)) self.child_all_list = self.child_all_list + SG_list + shader_list self.child_all_list.remove('global_matteID') num = len(self.child_all_list) print '#####################################################################################################' print 'total of ' + str(num) + ' node(s) will be deleted' for node in self.child_all_list: print str(node) + ' (' + str(node.type())+')' pm.undoInfo(ock=True) pm.delete(self.child_all_list) pm.undoInfo(cck=True)
def _jointRes(self, parentJoint, endJoint, boneTranslateAxis='.tx', add=2.0, name="subJoint_"): pmc.undoInfo(openChunk=True) selJoints = pmc.ls(selection=True) boneLength = mc.getAttr(endJoint + boneTranslateAxis) boneRadius = mc.getAttr(parentJoint + ".radius") mc.select(cl=True) for i in xrange(int(round(add))): newJoint = pmc.joint(name=name + str(i + 1), radius=(boneRadius * 2)) mc.select(cl=True) pmc.parent(newJoint, parentJoint, relative=True) mc.setAttr(newJoint + boneTranslateAxis, (boneLength / (add + 1))) if i > 0: pmc.parent(newJoint, (name + str(i)), relative=True) if i == add - 1: pmc.parent(endJoint, newJoint) pmc.undoInfo(closeChunk=True)
def rtb_shrink_wrap_verts(highresListDropdown, *args, **kwargs): ''' ''' global defaultString high = highresListDropdown.getValue() if not high == defaultString: pm.undoInfo(openChunk=True) live = pm.PyNode(high.replace('_high', '_live')) liveShape = live.getShape() sel = pm.ls(sl=True) if sel: verts = geometry.getVertsFromSelection(sel) if verts and verts[0].nodeType() == 'mesh': try: geometry.shrinkWrap(verts, liveShape, prefix+'_progress_control') except: pm.warning('You Should Not See This Error!') pm.progressBar(prefix+'_progress_control', edit=True, endProgress=True) else: pm.warning('No verts to shrink wrap!') pm.select(sel, r=True) pm.hilite(pm.PyNode(sel[0].split('.')[0]).getParent(), r=True) type = geometry.getMeshSelectionType(sel) geometry.switchSelectType(type) pm.undoInfo(closeChunk=True) else: pm.warning('Select a mesh from the dropdown list')
def zero_out_bend(**kwargs): """ Zero out all the bend joint Here we assume it already has a optimised rotate order - joint_list: (list) List of joint to zero out te bend - axis: (str) Which axis is the joint bending - rotate_order: (str) What is the current rotate order @return the rotate order """ joint_list = libUtilities.pyList(kwargs.get("joint_list") or get_joint_children(pm.selected()[0])) libUtilities.freeze_rotation(joint_list) libUtilities.freeze_scale(joint_list) rotate_order = kwargs.get("rotate_order") or joint_list[0].rotateOrder.get(asString=True) target_axis = kwargs.get("axis", rotate_order[0]) new_rotate_order = None if target_axis != rotate_order[0]: new_rotate_order = "{}{}{}".format(target_axis, rotate_order[0], rotate_order[2]) pm.undoInfo(openChunk=True) for joint in joint_list: for rotate_axis in rotate_order: if rotate_axis != target_axis: joint.attr("jointOrient{}".format(rotate_axis.upper())).set(0) if new_rotate_order: joint.rotateOrder.set(new_rotate_order) pm.undoInfo(closeChunk=True) return new_rotate_order
def setDelAction(self): pm.undoInfo(openChunk=True) for item in self.selectedItems(): layer_name = item.text() layer_name = unicode(layer_name) pm.delete(layer_name) self.takeItem(self.row(item)) pm.undoInfo(closeChunk=True)
def undoable(name): try: pm.undoInfo(ock=True, cn=name) yield name except Exception, e: import traceback pm.warning('[XGen Hub] : Error while running undoable <%s> : %s' % (name, e)) traceback.print_exc()
def substitutePath(self): u'''點擊轉換按鈕觸發''' pm.undoInfo(ock=True) for i in self.substituteNode: path = mc.getAttr(i + '.filename') pathChanged = self.replace(path) mc.setAttr(i + '.filename', str(pathChanged), type='string') pm.undoInfo(cck=True)
def wrapper(*args, **kwargs): pymel.undoInfo(openChunk=True) try: func(*args, **kwargs) except Exception as ex: log.warning(ex) finally: pymel.undoInfo(closeChunk=True)
def inner(*args, **kwargs): pmc.undoInfo(openChunk=True) try: return func(*args, **kwargs) except RuntimeError as ex: print(ex) finally: pmc.undoInfo(closeChunk=True)
def _ctrlDBL(self, controls): pmc.undoInfo(openChunk=True) if controls == []: controls = pmc.ls(sl=True) for control in controls: control_roo = pmc.xform(control, q=True, roo=True) control_mtx = pmc.xform(control, q=True, m=True, ws=True) control_parent = pmc.listRelatives(control, p=True) pmc.select(cl=True) locdbl_parent = pmc.spaceLocator(n='locDBL_parent_' + control) locdbl_offset = pmc.spaceLocator(n='locDBL_offset_' + control) pmc.xform(locdbl_parent, ws=True, m=control_mtx) pmc.xform(locdbl_offset, ws=True, m=control_mtx) pmc.parent(locdbl_offset, locdbl_parent) pmc.parent(locdbl_parent, control_parent) pmc.parent(control, locdbl_offset) if control_roo == 'xyz': pmc.xform(locdbl_offset, roo='zyx') if control_roo == 'yzx': pmc.xform(locdbl_offset, roo='xzy') if control_roo == 'zxy': pmc.xform(locdbl_offset, roo='yxz') if control_roo == 'xzy': pmc.xform(locdbl_offset, roo='yzx') if control_roo == 'yxz': pmc.xform(locdbl_offset, roo='zxy') if control_roo == 'zyx': pmc.xform(locdbl_offset, roo='xyz') md_trns = pmc.createNode('multiplyDivide', n='mdTRNS_locDBL_' + control) md_rot = pmc.createNode('multiplyDivide', n='mdROT_locDBL_' + control) md_scl = pmc.createNode('multiplyDivide', n='mdSCL_locDBL_' + control) pmc.setAttr(md_trns + '.input1', [-1,-1,-1]) pmc.setAttr(md_rot.input1, [-1,-1,-1]) pmc.setAttr(md_scl.input1, [ 1, 1, 1]) pmc.setAttr(md_scl.operation, 2) pmc.connectAttr(control + '.translate', md_trns + '.input2') pmc.connectAttr(control + '.rotate', md_rot + '.input2') pmc.connectAttr(control + '.scale', md_scl + '.input2') pmc.connectAttr(md_trns + '.output', locdbl_offset + '.translate') pmc.connectAttr(md_rot + '.output', locdbl_offset + '.rotate') pmc.connectAttr(md_scl + '.output', locdbl_offset + '.scale') pmc.setAttr(locdbl_parent + 'Shape.visibility', 0) pmc.setAttr(locdbl_offset + 'Shape.visibility', 0) pmc.undoInfo(closeChunk=True)
def wrapper(*args, **kwargs): pmc.undoInfo(openChunk=True) try: result = func(*args, **kwargs) except: vp.vPrint('Error', 1) finally: pmc.undoInfo(closeChunk=True) return result
def undo(): """ Run a block of code in an undo block. """ pm.undoInfo(openChunk=True) try: yield finally: pm.undoInfo(closeChunk=True)
def onAfterPressed(self, method): pm.undoInfo(closeChunk=True) # repeat last command module = method.__module__ full_method = module + '.' + method.__name__ pm.repeatLast(ac='python("import {}; {}()")'.format( module, full_method), acl=full_method)
def wrapper(*args, **kwargs): pm.undoInfo(openChunk=True) try: return func(*args, **kwargs) except Exception as e: print(traceback.format_exc()) error(str(e)) finally: pm.undoInfo(closeChunk=True)
def restore(self): pm.undoInfo(closeChunk=True) self._closed = True try: pm.undo() except StandardError: pass
def uvmp_reset_slider(*args, **kwargs): ''' resets the rotation slider to 0 position after its let go ''' global undoChunk if undoChunk == True: # close the undo chunck on slider release pm.undoInfo(closeChunk=True, chunkName='undo_rotate_interactive') undoChunk = False pm.floatSlider(prefix + '_rotate_free', e=True, v=0)
def clear_all_rsl(): """Clear all renderSetupLayers """ try: pm.undoInfo(openChunk=True) rs = renderSetup.instance() rs.clearAll() mel.eval('MLdeleteUnused;') finally: pm.undoInfo(closeChunk=True)
def setDelAction(self): # self.dropAction = Qt.CopyAction print 111 pm.undoInfo(openChunk=True) # self.dropAction = Qt.MoveAction for item in self.selectedItems(): layer_name = item.text() layer_name = unicode(layer_name) pm.delete(layer_name) pm.undoInfo(closeChunk=True)
def __exit__(self, exc_type, exc_val, exc_tb): pmc.undoInfo(closeChunk=True) if exc_val is not None: try: pmc.undo() except RuntimeError: pass if exc_type == AssertionError: logging.warning(exc_val) return True
def set(self, cc=False): if not cc and not self.undoState: self.undoState = True pm.undoInfo(openChunk=True) for i in self.obj(): getattr(i, self.name.lower()).set(self.attr_.getValue()) if cc and self.undoState: pm.undoInfo(closeChunk=True) self.undoState = False
def doNgSkinRelax(self, *args): numSteps = self.ui.ng_iteractions_spin.value() stepSize = self.ui.ng_stepSize_spin.value() nativeSoft = self.ui.ng_mayaNativeSelection_chk.isChecked() pm.undoInfo(openChunk=True) try: pm.ngSkinRelax(numSteps=numSteps, stepSize=stepSize, nss=nativeSoft) finally: pm.undoInfo(closeChunk=True)
def onPivotPressed(self, item): """ Called when dynamic pivot item is clicked. Will set dynamic pivot transforms to 0. Args: item (QtWidgets.QListWidgetItem): Dynamic pivot to reset when clicked. """ pm.undoInfo(openChunk=True) space.resetDynamicPivot(pm.PyNode(item.text()), key=self.keyframe_box.isChecked()) pm.undoInfo(closeChunk=True)
def _iterator_smooth(self, iterations, pass_value): """Function to create an undo chunk and iteratively smooth the graph keys. The undo chunk is used to return back to the original state in one undo command. """ # Creating an undo chunk start point _pm.undoInfo(openChunk=True) # Iteratively calling the smooth keys functionality for iterator in xrange(iterations): self.smooth_keys(pass_value) # Creating an undo chunk end point _pm.undoInfo(closeChunk=True)
def headSquash_doGuide(self): getDictFromScene = self.ui.squash_getGuide_chk.isChecked() self.headSquash = squash.Squash(name='headSquash') pm.undoInfo(openChunk=True) try: if getDictFromScene: self.headSquash.getDict() self.headSquash.doGuide() finally: pm.undoInfo(closeChunk=True)
def exportAnimation(path=None): """ Bakes and exports animation on a rig in the scene. Args: path(str): An destination fbx path to export. """ if path is None: path = pmc.sceneName() path = path.replace('.ma', '.fbx') # Get the root joint root = None namespace = None for namespace in pmc.listNamespaces(): root = getRootJoint(namespace) if root is not None: namespace = namespace break if root is None: raise RootJointException('Could not find a root in the scene with a namespace.') try: pmc.undoInfo(openChunk=True) # Create a duplicate root joint dupRoot = pmc.duplicate(root)[0] pmc.rename(dupRoot, root.nodeName().split(':')[-1]) # Copy animation tags copyTagAttribiutes(root, dupRoot) # Bind skeleton constraints = [] exportJoints = [dupRoot] + getBindSkeleton() for joint in [dupRoot] + getBindSkeleton(): source = pmc.PyNode('%s:%s' % (namespace, joint.nodeName())) constraints.append(pmc.parentConstraint(source, joint)) # Bake animation and remove constraints bakeAnimation(exportJoints) pmc.delete(constraints) # Export animation and convert to hkx exportFbx([dupRoot] + getBindSkeleton(), path=path, animation=True) ckcmd.importanimation( getSceneSkeletonHkx(legacy=True), path, getSceneAnimationDirectory(), cache_txt=getSceneCacheFile(), behavior_directory=getSceneBehaviorDirectory() ) # TODO copy cache file to correct directory finally: pmc.undoInfo(closeChunk=True)
def switch(space, timeRange=False, start=0, end=0): #undo enable pm.undoInfo(openChunk=True) sel = pm.ls(selection=True) for node in sel: cnt = getConnectedNodes(node, 'control')[0] controls = [] for obj in getConnectedNodes(cnt, 'message'): #IK switch if space == 'IK': if obj.space.get() == space: if timeRange: for count in xrange(start, end): pm.currentTime(count) switch = getConnectedNodes(obj, 'switch')[0] Snap(obj, switch) cnt.blend.set(1) else: switch = getConnectedNodes(obj, 'switch')[0] Snap(obj, switch) cnt.blend.set(1) #FK control finding if space == 'FK': if obj.space.get() == space: controls.append(obj) #FK switch controls.sort(key=lambda x: x.chain.get()) if timeRange: for count in xrange(start, end): pm.currentTime(count) for obj in controls: switch = getConnectedNodes(obj, 'switch')[0] Snap(obj, switch) cnt.blend.set(0) else: for obj in controls: switch = getConnectedNodes(obj, 'switch')[0] Snap(obj, switch) cnt.blend.set(0) pm.undoInfo(closeChunk=True)
def create_ui(self): pmc.undoInfo(openChunk=True) self.setWindowTitle('VFK Rig Creator') self.setWindowFlags(qc.Qt.Tool) self.setMinimumSize(300, 400) self.setMaximumWidth(300) self.create_controls() self.create_layout() self.create_connections() pmc.undoInfo(closeChunk=True)
def set(self, cc=False): if not cc and not self.undoState: self.undoState = True pm.undoInfo(openChunk=True) try: getattr(self.ceObj.wire[0], self.name).set(self.attr.getValue()) except: AttributeError('{0} node does no longer exist'.format(self.ceObj.wire[0])) if cc and self.undoState: pm.undoInfo(closeChunk=True) self.undoState = False
def RebuildMesh(self): pm.undoInfo(openChunk=True) mc.select(self.hipsMesh, self.spineMesh, self.chestMesh, self.headMesh, self.l_upperArmMesh, self.l_lowerArmMesh, self.l_thumbMesh_a, self.l_thumbMesh_b, self.l_thumbMesh_c, self.l_indexMesh_a, self.l_indexMesh_b, self.l_indexMesh_c, self.l_middleMesh_a, self.l_middleMesh_b, self.l_middleMesh_c, self.l_ringMesh_a, self.l_ringMesh_b, self.l_ringMesh_c, self.l_pinkieMesh_a, self.l_pinkieMesh_b, self.l_pinkieMesh_c, self.r_upperArmMesh, self.r_lowerArmMesh, self.r_thumbMesh_a, self.r_thumbMesh_b, self.r_thumbMesh_c, self.r_indexMesh_a, self.r_indexMesh_b, self.r_indexMesh_c, self.r_middleMesh_a, self.r_middleMesh_b, self.r_middleMesh_c, self.r_ringMesh_a, self.r_ringMesh_b, self.r_ringMesh_c, self.r_pinkieMesh_a, self.r_pinkieMesh_b, self.r_pinkieMesh_c, self.l_upperLegMesh, self.l_lowerLegMesh, self.l_footMesh, self.l_toesMesh, self.r_upperLegMesh, self.r_lowerLegMesh, self.r_footMesh, self.r_toesMesh) mc.delete() self.BuildMesh() pm.undoInfo(closeChunk=True)
def setTorsoSize(self, value): pm.undoInfo(openChunk=True) if value > 10.0: value = value / 100.0 self.torsoSize_spinBox.setValue(value) else: self.torsoSize_slider.setValue(value*100) self.setJointScale(self.spine, value, self.torsoSize) self.setJointScale(self.chest, value, self.torsoSize) self.setJointScale(self.neck, value, self.torsoSize) self.torsoSize = value self.RebuildMesh() pm.undoInfo(closeChunk=True)
def InitRig(self): pm.undoInfo(openChunk=True) self.legHeight_slider.blockSignals(True) self.legHeight_spinBox.blockSignals(True) self.legHeight = 1 self.legHeight_slider.setValue(100) self.legHeight_spinBox.setValue(1.0) self.legHeight_slider.blockSignals(False) self.legHeight_spinBox.blockSignals(False) self.headSize_slider.blockSignals(True) self.headSize_spinBox.blockSignals(True) self.headSize = 1 self.headSize_slider.setValue(100) self.headSize_spinBox.setValue(1.0) self.headSize_slider.blockSignals(False) self.headSize_spinBox.blockSignals(False) self.torsoSize_slider.blockSignals(True) self.torsoSize_spinBox.blockSignals(True) self.torsoSize = 1 self.torsoSize_slider.setValue(100) self.torsoSize_spinBox.setValue(1.0) self.torsoSize_slider.blockSignals(False) self.torsoSize_spinBox.blockSignals(False) self.l_armLength_slider.blockSignals(True) self.l_armLength_spinBox.blockSignals(True) self.l_armLength = 1 self.l_armLength_slider.setValue(100) self.l_armLength_spinBox.setValue(1.0) self.l_armLength_slider.blockSignals(False) self.l_armLength_spinBox.blockSignals(False) self.r_armLength_slider.blockSignals(True) self.r_armLength_spinBox.blockSignals(True) self.r_armLength = 1 self.r_armLength_slider.setValue(100) self.r_armLength_spinBox.setValue(1.0) self.r_armLength_slider.blockSignals(False) self.r_armLength_spinBox.blockSignals(False) self.enableRigEdit(True) self.InitializeRig(); pm.undoInfo(closeChunk=True)
def Connect(alembicRoot, targetRoot, connectShapes=True): pm.undoInfo(openChunk=True) alembics = pm.ls(alembicRoot, dagObjects=True, long=True) targets = pm.ls(targetRoot, dagObjects=True, long=True) for node in targets: for abc in alembics: if node.split(':')[-1] == abc.split(':')[-1]: #get connection attributes data = getConnectedAttr(abc, connectShapes) #connects any animated node if data: for attr in data: try: pm.connectAttr(data[attr], '%s.%s' % (node, attr), force=True) CopyTransform(abc, node) except: pass #connects any static node else: try: #copy transform and blendshape to ensure placement CopyTransform(abc, node) Blendshape(abc, node) except: pass #adding user defined attrs to all shapes if node.nodeType() == 'mesh': shapes = node.getParent().getShapes() for shp in shapes: for attr in node.listAttr(userDefined=True): attrType = pm.getAttr(attr, type=True) try: shp.addAttr(attr.split('.')[-1], attributeType=attrType, defaultValue=attr.get()) except: pass pm.undoInfo(closeChunk=True)
def setHeadSize(self, value): pm.undoInfo(openChunk=True) self.progressBar.setValue(100) if value > 10.0: value = value / 100.0 self.headSize_spinBox.setValue(value) else: self.headSize_slider.setValue(value*100) mc.select(self.headMesh) mc.delete() self.setJointScale(self.headTop, value, self.headSize) self.headMesh = createSphere("char_headMesh", self.head, self.headTop) self.headSize = value self.progressBar.setValue(0) pm.undoInfo(closeChunk=True)
def inner(*args, **kwargs): err = None pmc.undoInfo(openChunk=True) try: res = func(*args, **kwargs) except Exception as err: raise finally: pmc.undoInfo(closeChunk=True) # Close undo! if err: # Did we error out? pmc.undo() e_type, e_name, e_trace = sys.exc_info() # Last error pmc.confirmDialog( t="Uh oh... %s" % e_type.__name__, m=str(e_name) ) return res
def amcveProfile(cvSrc, trim): """ """ cvSrc = pm.ls(cvSrc)[0] tiLen = [] if trim: tiLen.append(pm.playbackOptions(q= 1, min= 1)) tiLen.append(pm.playbackOptions(q= 1, max= 1)) pm.undoInfo(ock= 1) pm.setKeyframe(cvSrc, insert= 1, t= tiLen, f= tiLen) pm.undoInfo(cck= 1) cvBaseMod = { 'cvTyp' : pm.objectType(cvSrc), 'prInf' : cvSrc.getPreInfinityType().key, 'poInf' : cvSrc.getPostInfinityType().key, 'weedT' : pm.keyTangent(cvSrc, q= 1, weightedTangents= 1), 'breaD' : pm.keyframe(cvSrc, q= 1, breakdown= 1) } cvPortray = { 'Frame' : pm.keyframe(cvSrc, q= 1, timeChange= 1), 'Float' : pm.keyframe(cvSrc, q= 1, floatChange= 1), 'Value' : pm.keyframe(cvSrc, q= 1, valueChange= 1) } cvFeature = { 'TLock' : pm.keyTangent(cvSrc, q= 1, lock= 1), 'WLock' : pm.keyTangent(cvSrc, q= 1, weightLock= 1), 'InTyp' : pm.keyTangent(cvSrc, q= 1, inTangentType= 1), 'OuTyp' : pm.keyTangent(cvSrc, q= 1, outTangentType= 1), 'InWet' : pm.keyTangent(cvSrc, q= 1, inWeight= 1), 'OuWet' : pm.keyTangent(cvSrc, q= 1, outWeight= 1), 'InAng' : pm.keyTangent(cvSrc, q= 1, inAngle= 1), 'OuAng' : pm.keyTangent(cvSrc, q= 1, outAngle= 1) } cvSrcProfile = { 'cvTrimmed' : tiLen, 'cvBaseMod' : cvBaseMod, 'cvPortray' : cvPortray, 'cvFeature' : cvFeature } if trim: pm.undo() return cvSrcProfile
def run(self): items = self.weightListWidget.selectedItems() attrList = [] pm.undoInfo(ock=1) for x in items: attrList.append(x.text()) value = float(self.setValueLine.text()) for x in self.objectList: for y in attrList: x.attr(y).set(value) pm.undoInfo(cck=1)
def localRemap(dis, remapType, tirm, sel_src, sel_dis, scale= None, mirror= None): """ ### preselect dis, than select src dis = 'TVbuddy_rigging_master3:TVbuddyV1' mr.localRemap(dis, 'order', True, False, False) """ # src ctrl keys ctrlList_src = md.lsController(sel_src) src = md.keyController(ctrlList_src) # dis ctrl list dis = md.lsController(sel_dis, dis) # gen map keyMap = md.drawKeyMap(remapType, src, dis) # link up pm.undoInfo(ock= 1) for ctrl in keyMap: if not ctrl == keyMap[ctrl]: cvp = md.packup(src[ctrl], tirm) md.wireup(cvp, keyMap[ctrl], scale, mirror) pm.undoInfo(cck= 1)
def bindRig(self): pm.undoInfo(openChunk=True) self.progressBar.setValue(50) mc.polyUnite(self.hipsMesh, self.spineMesh, self.chestMesh, self.headMesh, self.l_upperArmMesh, self.l_lowerArmMesh, self.l_thumbMesh_a, self.l_thumbMesh_b, self.l_thumbMesh_c, self.l_indexMesh_a, self.l_indexMesh_b, self.l_indexMesh_c, self.l_middleMesh_a, self.l_middleMesh_b, self.l_middleMesh_c, self.l_ringMesh_a, self.l_ringMesh_b, self.l_ringMesh_c, self.l_pinkieMesh_a, self.l_pinkieMesh_b, self.l_pinkieMesh_c, self.r_upperArmMesh, self.r_lowerArmMesh, self.r_thumbMesh_a, self.r_thumbMesh_b, self.r_thumbMesh_c, self.r_indexMesh_a, self.r_indexMesh_b, self.r_indexMesh_c, self.r_middleMesh_a, self.r_middleMesh_b, self.r_middleMesh_c, self.r_ringMesh_a, self.r_ringMesh_b, self.r_ringMesh_c, self.r_pinkieMesh_a, self.r_pinkieMesh_b, self.r_pinkieMesh_c, self.l_upperLegMesh, self.l_lowerLegMesh, self.l_footMesh, self.l_toesMesh, self.r_upperLegMesh, self.r_lowerLegMesh, self.r_footMesh, self.r_toesMesh, n = "char_body") self.progressBar.setValue(100) mc.select(self.hips, tgl=True, hi=True) mc.SmoothBindSkin() self.enableRigEdit(False) self.progressBar.setValue(0) pm.undoInfo(closeChunk=True)
def _jointRes(self, parentJoint, endJoint, boneTranslateAxis = '.tx', add=2.0, name="subJoint_"): pmc.undoInfo(openChunk=True) selJoints = pmc.ls(selection=True) boneLength = mc.getAttr(endJoint + boneTranslateAxis) boneRadius = mc.getAttr(parentJoint + ".radius") mc.select(cl=True) for i in xrange(int(round(add))): newJoint = pmc.joint(name=name + str(i+1), radius = (boneRadius*2)) mc.select(cl=True) pmc.parent(newJoint, parentJoint, relative=True) mc.setAttr(newJoint + boneTranslateAxis, (boneLength/(add + 1))) if i > 0: pmc.parent(newJoint, (name + str(i)), relative = True) if i == add - 1: pmc.parent(endJoint, newJoint) pmc.undoInfo(closeChunk=True)
def manage_default_options(**kwargs): """ Sets Various Default options for Maya viewmManip : Default Hide the manipulator Cube gradient: Default Hide the Background gradient autosave: Default Enable Autosave mentalray: Default Enable mr as Default Render Engine interactiveCreation: Enables Disables Interactive Creation Mode for Primitive Objects hardware2: Optional Enable Hardware Renderer 2.0 as Default Render Engine """ # Disable View Cube pm.viewManip(visible=kwargs.get("viewManip", False)) # Disable Background Gradient pm.displayPref(displayGradient=kwargs.get("gradient", False)) # Infinite Undo pm.undoInfo(state=True, infinity=kwargs.get("infiniteUndo", True)) # Enable Autosave, max Versions 10, interval 15min pm.autoSave(enable=kwargs.get("autosave", True), maxBackups=kwargs.get( "maxBackups", 10), interval=kwargs.get("interval", 900)) # Activate Mental Ray if kwargs.get("mentalray", True): enable_mr_plugin() # Sets Hardwarerenderer 2.0 as Default if kwargs.get("hardware2", False): pm.PyNode("defaultRenderGlobals").currentRenderer.set("mayaHardware2") # Expose Mental Ray Production Nodes pm.optionVar["MIP_SHD_EXPOSE"] = 1 # Disable Interactive Creation set_interactive_creation(kwargs.get("interactiveCreation", False))
def __exit__(self, type, value, tb): try: pm.undoInfo(closeChunk=1) except TypeError: # Legacy support for before undo chunking existed # Turn undo back on pm.undoInfo(stateWithoutFlush=1) # This is needed for things to work for some reason pm.undoInfo(query=1, undoName=0)
def undo_chunk(auto_undo=False, exc_callback=None): ''' Undo chunk context manager... ''' try: pm.undoInfo(openChunk=True) yield except Exception as e: pm.undoInfo(closeChunk=True) if auto_undo: pm.undo() if exc_callback: exc_callback(e) raise else: pm.undoInfo(closeChunk=True)
def setRightArmLength(self, value): pm.undoInfo(openChunk=True) self.progressBar.setValue(50) if value > 10.0: value = value / 100.0 self.r_armLength_spinBox.setValue(value) else: self.r_armLength_slider.setValue(value*100) mc.select(self.r_upperArmMesh, self.r_lowerArmMesh, self.r_thumbMesh_a, self.r_thumbMesh_b, self.r_thumbMesh_c, self.r_indexMesh_a, self.r_indexMesh_b, self.r_indexMesh_c, self.r_middleMesh_a, self.r_middleMesh_b, self.r_middleMesh_c, self.r_ringMesh_a, self.r_ringMesh_b, self.r_ringMesh_c, self.r_pinkieMesh_a, self.r_pinkieMesh_b, self.r_pinkieMesh_c) mc.delete() self.setJointScale(self.r_shoulder, value, self.r_armLength) self.setJointScale(self.r_upperArm, value, self.r_armLength) self.setJointScale(self.r_lowerArm, value, self.r_armLength) self.setJointScale(self.r_wrist, value, self.r_armLength) self.setJointScale(self.r_thumb_a, value, self.r_armLength) self.setJointScale(self.r_thumb_b, value, self.r_armLength) self.setJointScale(self.r_thumb_c, value, self.r_armLength) self.setJointScale(self.r_thumb_d, value, self.r_armLength) self.setJointScale(self.r_index_a, value, self.r_armLength) self.setJointScale(self.r_index_b, value, self.r_armLength) self.setJointScale(self.r_index_c, value, self.r_armLength) self.setJointScale(self.r_index_d, value, self.r_armLength) self.setJointScale(self.r_middle_a, value, self.r_armLength) self.setJointScale(self.r_middle_b, value, self.r_armLength) self.setJointScale(self.r_middle_c, value, self.r_armLength) self.setJointScale(self.r_middle_d, value, self.r_armLength) self.setJointScale(self.r_ring_a, value, self.r_armLength) self.setJointScale(self.r_ring_b, value, self.r_armLength) self.setJointScale(self.r_ring_c, value, self.r_armLength) self.setJointScale(self.r_ring_d, value, self.r_armLength) self.setJointScale(self.r_pinkie_a, value, self.r_armLength) self.setJointScale(self.r_pinkie_b, value, self.r_armLength) self.setJointScale(self.r_pinkie_c, value, self.r_armLength) self.setJointScale(self.r_pinkie_d, value, self.r_armLength) self.r_upperArmMesh = CreateRightCube("char_r_upperArmMesh", self.r_lowerArm, self.r_upperArm, [2,1,2], [5,1,5]) self.r_lowerArmMesh = CreateRightCube("char_r_lowerArmMesh", self.r_wrist, self.r_lowerArm, [2,1,2], [3,1,3]) self.r_thumbMesh_a = CreateRightCube("char_r_thumbMesh_a", self.r_thumb_b, self.r_thumb_a, [1,1,1], [1,1,1]) self.r_thumbMesh_b = CreateRightCube("char_r_thumbMesh_b", self.r_thumb_c, self.r_thumb_b, [1,1,1], [1,1,1]) self.r_thumbMesh_c = CreateRightCube("char_r_thumbMesh_c", self.r_thumb_d, self.r_thumb_c, [1,1,1], [1,1,1]) self.r_indexMesh_a = CreateRightCube("char_r_indexMesh_a", self.r_index_b, self.r_index_a, [1,1,1], [1,1,1]) self.r_indexMesh_b = CreateRightCube("char_r_indexMesh_b", self.r_index_c, self.r_index_b, [1,1,1], [1,1,1]) self.r_indexMesh_c = CreateRightCube("char_r_indexMesh_c", self.r_index_d, self.r_index_c, [1,1,1], [1,1,1]) self.progressBar.setValue(100) self.r_middleMesh_a = CreateRightCube("char_r_middleMesh_a", self.r_middle_b, self.r_middle_a, [1,1,1], [1,1,1]) self.r_middleMesh_b = CreateRightCube("char_r_middleMesh_b", self.r_middle_c, self.r_middle_b, [1,1,1], [1,1,1]) self.r_middleMesh_c = CreateRightCube("char_r_middleMesh_c", self.r_middle_d, self.r_middle_c, [1,1,1], [1,1,1]) self.r_ringMesh_a = CreateRightCube("char_r_ringMesh_a", self.r_ring_b, self.r_ring_a, [1,1,1], [1,1,1]) self.r_ringMesh_b = CreateRightCube("char_r_ringMesh_b", self.r_ring_c, self.r_ring_b, [1,1,1], [1,1,1]) self.r_ringMesh_c = CreateRightCube("char_r_ringMesh_c", self.r_ring_d, self.r_ring_c, [1,1,1], [1,1,1]) self.r_pinkieMesh_a = CreateRightCube("char_r_pinkieMesh_a", self.r_pinkie_b, self.r_pinkie_a, [1,1,1], [1,1,1]) self.r_pinkieMesh_b = CreateRightCube("char_r_pinkieMesh_b", self.r_pinkie_c, self.r_pinkie_b, [1,1,1], [1,1,1]) self.r_pinkieMesh_c = CreateRightCube("char_r_pinkieMesh_c", self.r_pinkie_d, self.r_pinkie_c, [1,1,1], [1,1,1]) self.r_armLength = value self.progressBar.setValue(0) pm.undoInfo(closeChunk=True)
def _endSliderUndo(self): pm.undoInfo(closeChunk=True) self.slider_down = False