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 press_cmd(self, *args) : ctx = self.ctx print "paramProgress_befor", self.paramProgress_befor pressPosition = cmds.draggerContext( ctx, query=True, anchorPoint=True) self.drag_star_point = pressPosition print ("Press: " + str(pressPosition)) #self.paramProgress = 0.0 pos = curvetool.getCurvePoint( self.cur, [self.paramProgress], "normal" )[0] # 第二引数でターゲットの初期位置を指定 self.moving_sph = pm.sphere(n = "moving_sph", r=0.1)[0] pm.move( self.moving_sph , [pos[0],pos[1],pos[2]] ) pm.refresh(f = 1) # ハイライト pm.hilite(self.cur) list = pm.ls(type = u'transform') for i in list : if "temp" in i.name() : pm.hilite(i)
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 import_component(file_path, selected_object): """ This function opens the selected file and reads the information from the file :param file_path: :param selected_object: :return: """ try: f = open(file_path, 'r') except: pm.confirmDialog( t='Error', b=['OK'], m='Unable to read file: %s' % file_path ) raise component = cPickle.load(f) f.close() # this list is for storing the unmatched component ID's err_comps = [] # selected objects name if selected_object is None: selected_object = get_selected_object() else: None # this list is for storing the component ID's with the name of the object selection = [] # clearing any selection on the mesh pm.select(clear=True) # this for loop is for merging and the storing the component ID's with the object ID unmatched ID's is gonna be # stored in errComps list. for compValue in component: try: selection.append(selected_object+"."+compValue) except: try: err_comps.append(compValue[0]) except: err_comps.append(compValue) # changing the select mode into component mode pm.selectMode(component=True) # changing the hilite visibility to true pm.hilite(selected_object, r=True) # this is for checking the component types and changing the selection type to the chosen component if component[0].startswith("vtx["): pm.selectType(pv=True) elif component[0].startswith("vtxFace["): pm.selectType(pvf=True) elif component[0].startswith("e["): pm.selectType(pe=True) elif component[0].startswith("f["): pm.selectType(pf=True) else: None # applying the selection by using the list pm.select(selection, r=True) # checks the component errors if any if len(err_comps) > 0: import_error_window(err_comps) sys.stderr.write('Not all components could be loaded.') return selected_object
def __init__( self, cur , # nt.Transform("name") base, # str myface, pinIndexList = [], paramList = [], prePos = 0, blender = 0, alpha = 0 ): self.pinIndexList = pinIndexList self.paramList = paramList self.cur = cur self.base_name = base self.base_transform = pm.PyNode(self.base_name) self.ctx = "paramSetCtx" self.paramProgress = 0.0 self.paramProgress_befor = 0.0 self.myface = myface self.prePos = prePos self.blender = blender self.alpha = alpha self.constParamList = paramList self.constPinIndexList = pinIndexList #self.constPinIt = 0 # 現在何番目のピンを操作しているのか self.no_of_editing_pin = 0 self.no_of_editing_pin_max = len(pinIndexList) #self.initialization() self.make_param_set_cmd() pm.setToolTo(self.ctx) self.make_ui() self.update_field(pinIndexList,paramList) # 現在の口のラインを作成 self.sph_befor_move = [0] self.meke_mouth_line() """ pm.select(self.base_name) pm.mel.doMenuComponentSelectionExt("base", "vertex", 1) pm.setToolTo("selectSuperContext") """ pm.hilite(self.cur)
def getOverInfluencedVerts(): """Find vertices that have more weights than set maximumInfluences.""" selected = pm.ls(sl=1)[0] if isinstance(selected, pm.nt.Mesh): mesh = selected elif isinstance(selected, pm.Component): mesh = selected.node() elif isinstance(selected, pm.nt.Transform): mesh = selected.getShape() skin_cluster = mesh.listHistory(type='skinCluster')[0] mfn_skin_cluster = api.MFnSkinCluster( skin_cluster.__apiobject__() ) max_influences = skin_cluster.getMaximumInfluences() vertIter = api.MItMeshVertex ( mesh.__apiobject__() ) vert_list = set() while not vertIter.isDone(): vert_influences = 0 for i in range( skin_cluster.numInfluenceObjects() ): weights = api.MFloatArray() mfn_skin_cluster.getWeights( mesh.__apimdagpath__(), vertIter.currentItem(), i, weights ) if weights[0] > 0.0: vert_influences += 1 if vert_influences > max_influences: vert_list.add( vertIter.index() ) vertIter.next() vert_list = list(vert_list) pm.select(cl=1) if vert_list: pm.hilite(mesh, r=1) print '# ', list(vert_list), 'have too many weights.' for v in vert_list: pm.select(mesh.vtx[v], add=1) else: pm.select(selected, replace=1) print '# Ok.'
def add_to_selection_btn_cmd(self, *args): """This function gets the new selection of the components from the mesh and adds the selected file's stored components into the same selection :return: None """ selected_list = pm.ls(sl=True, fl=True) pm.select(cl=True) if pm.selectMode(q=True, object=True): None else: pm.selectMode(object=True) obj = get_selected_object() import_component(self.checkList, self.selectedObject) pm.select(selected_list, add=True) pm.selectMode(component=True) pm.hilite(obj, r=True) populate_characters(self.dirName, self.selectedCharacter, self.characterList, self.selectedFile)
def generateAlignedControl(self, _handedness, _joint, _name, _offsetXYZ=[0, 90, 0], _scaleMultiplier=3): # TODO: lock and hide all attrs on the LocAlign_ locators after # generation is done _scaleMultiplier = _scaleMultiplier**self.rigHeight jPos = pm.PyNode(_joint).getTranslation(space='world') loc = pm.spaceLocator(n='LocAlign_' + _handedness + '_' + _name + '_ctrl', p=jPos) loc.localScale.set([0, 0, 0]) pm.xform(loc, cp=1) oc = pm.orientConstraint(_joint, loc, mo=0) pm.delete(oc) ctrl = pm.circle(n=_handedness + '_' + _name + '_ctrl', c=pm.PyNode(_joint).getTranslation(space='world')) ctrlShape = pm.listRelatives(ctrl) ctrlTrans = pm.listRelatives(ctrlShape, p=1) locShape = pm.listRelatives(loc) locTrans = pm.listRelatives(locShape, p=1) pm.hilite(ctrl) pm.parent(ctrlTrans, locTrans, r=0) pm.xform(ctrl, cp=1) locTrans[0].t.set([0, 0, 0]) pm.select(ctrl[0] + '.cv[0:' + str(len(ctrl[0] + '.cv')) + ']') ctrl[0].rotate.set([0, 0, 0]) rad = pm.PyNode(_joint).getRadius() pm.xform(ro=(_offsetXYZ), s=(int(rad) * _scaleMultiplier, int(rad) * _scaleMultiplier, int(rad) * _scaleMultiplier)) pm.makeIdentity(ctrl, a=1, t=1) ctrlShape[0].overrideEnabled.set(True) if 'r_' in str(ctrl[0]): ctrlShape[0].overrideColor.set(13) if 'l_' in str(ctrl[0]): ctrlShape[0].overrideColor.set(6) if 'main_' in str(ctrl[0]): ctrlShape[0].overrideColor.set(17) return ctrl
def switchSelectionModeToEdge(item): ''' :Reference: doMenuComponentSelection in C:/Program Files/Autodesk/Maya2017/scripts/others/dagMenuProc.mel ''' pm.mel.eval('HideManipulators') if pm.selectMode(q=True, object=True): pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, edge=True) pm.selectType(edge=True) pm.hilite(item) else: pm.selectType(alc=False) pm.selectType(edge=True) not pm.selectMode(q=True, preset=True) or pm.hilite(item) try: not pm.mel.eval('exists dR_selTypeChanged') or pm.mel.eval( 'dR_selTypeChanged("edge")') except pm.MelError: pass
# # Leif Peterson 2016 # # This code deletes random interior edges and cleans up winged vertices, while maintaing corners import pymel.core as pm import random # create a list of all selected objects SelectedObjects = pm.ls( selection=True, o=True ) # for each object delete its interior edges randomly for Object in range(len(SelectedObjects)): # select only border edges pm.selectType( pe=True ) pm.hilite( SelectedObjects[Object] ) pm.polySelectConstraint( mode=3, type=0x8000, where=1 ) pm.select() borderEdges = pm.ls( selection=True, fl=True ) # select all edges pm.polySelectConstraint( where=0 ) pm.select() allEdges = pm.ls( selection=True, fl=True ) # initilize the inside edges list insideEdges = [] # remove border edges for edge in range(len(borderEdges)): allEdges.remove( borderEdges[edge] )