def get_polygons(type): if type == 'selected': nodes = core.ls(sl=True) all_polygons = core.listTransforms(type='mesh') polygons = [] for node in nodes: if node not in all_polygons: continue polygons.append(node) elif type == 'all': polygons = core.listTransforms(type='mesh') polygons = [polygon.fullPath() for polygon in polygons] return polygons
def uvmp_auto_layout(*args, **kwargs): ''' automaticaly unfold 3d ''' # if int(pm.about(version=True))<=2014: # lcUtility.Utility.lc_print('This command requires Maya 2015 or higher', mode='error') if not pm.pluginInfo('Unfold3D', query=True, loaded=True): lcUtility.Utility.lc_print('This command requires the Unfold3D plugin', mode='error') else: sel = pm.ls(sl=True) if sel: try: sel = sel[0] if pm.nodeType(sel) != 'transform': sel = pm.listTransforms(sel)[0] allFaces = pm.polyListComponentConversion(sel, tf=True) pm.polyProjection(allFaces, type='Planar', md='y') pm.delete(sel, ch=True) uvs = pm.polyListComponentConversion(sel, toUV=True) pm.Unfold3D(uvs, u=True, ite=6, p=1, bi=1, tf=1, ms=512, rs=8) pm.delete(sel, ch=True) except: lcUtility.Utility.lc_print_exception( 'something went wrong unfolding: {}'.format(sel)) finally: pm.select(sel, replace=True)
def find_from_scene(data, mode=False, polygons=None): studio_maya = studioMaya.Connect() if not polygons: polygons = core.listTransforms(type='mesh') scene_polygons = {} for index, contents in data.items(): for polygon in polygons: if isinstance(polygon, str) or isinstance(polygon, unicode): polygon = core.PyNode(polygon) if mode: if contents['short_name'] != polygon.fullPath().split('|')[-1]: continue num_polygons_data = contents['num_polygons'] polygon_vertices_data = contents['polygon_vertices'] studio_maya.node = polygon.name() mfn_mesh = studio_maya.getMfnMesh() num_polygons, polygon_vertices = studio_maya.getFacesVertices( mfn_mesh) if num_polygons_data != num_polygons: continue if polygon_vertices_data != polygon_vertices: continue scene_contents = copy.deepcopy(contents) scene_contents['shape_node'] = polygon.name() scene_contents['long_name'] = polygon.fullPath() scene_contents['short_name'] = polygon.fullPath().split('|')[-1] scene_polygons.setdefault(index, []).append(scene_contents) return scene_polygons
def select_all_ctrls(): pymel.select(None) selection_list = [] for obj in pymel.listTransforms(): if obj.hasAttr('Type') and obj.Type.get() == 'CTRL': selection_list.append(obj) pymel.select(selection_list)
def render_layer(): layers = core.ls(type='renderLayer') for layer in layers: attribute = layer.attr('renderable') attribute.set(False) geometrys = core.listTransforms(geometry=True) layer = 'scene_preview' if core.objExists(layer): core.editRenderLayerGlobals(crl='defaultRenderLayer') core.delete(layer) render_layer = core.createRenderLayer(geometrys, n=layer, num=1, nr=1) render_layer.setCurrent()
def del_node(node_name): if pm.objExists(node_name): try: tran = pm.listTransforms(node_name) for a in tran: pm.delete(a) print "the %s is del " % (a) except: print "the %s dont del " % (node_name) pass
def get_data(): contents = core.ls() transforms = core.listTransforms() defaults = get_defaults() node_data = {} nodes = [] nodes_shapes = [] for transform in transforms: if transform.type() != 'transform': continue shape = transform.getShape() if shape: shapes = [each.name() for each in transform.getShapes()] t_data = {transform.name(): shapes} node_data.setdefault(shape.type(), {}) node_data[shape.type()].setdefault(transform.name(), {'shapes': shapes}) nodes.extend(shapes) else: node_data.setdefault(transform.type(), []).append(transform.name()) nodes.append(transform.name()) if shape: nodes_shapes.append(shape.type()) for content in contents: if content.name() in defaults: continue if content.name() in nodes: continue if content.type() in nodes_shapes: continue node_data.setdefault(content.type(), []).append(content.name()) for nodetype, node_contents in node_data.items(): print '\nType : ', nodetype if isinstance(node_contents, dict): for each, shape_nodes in node_contents.items(): print 'Name : ', each for shape_node in shape_nodes['shapes']: print 'shape : ', shape_node print '\n' else: for each in node_contents: print 'Name : ', each return node_data
def creatSoftModCtrl(vtx): for i in vtx: a = str(type(i)) if a == "<class 'pymel.core.general.MeshVertex'>": name = (str(i)) ModifiedName = re.sub(r'[^\w]', '_', name) print (ModifiedName) else: print('Wrong Selection, Only select verticies') break pos = pm.pointPosition(i) name = (str(i)) ModifiedName = re.sub(r'[^\w]', '_', name) ctl = pm.curve(n = ModifiedName +'_SoftMod_Handle_Ctrl' ,d=1, p=[(1, 1, 1),(1, 1, -1),(-1, 1, -1),(-1, 1, 1),(1, 1, 1),(1, -1, 1),(1, -1, -1),(1, 1, -1),(-1, 1, -1),(-1, -1, -1),(1, -1, -1),(-1, -1, -1),(-1, -1, 1),(-1, 1, 1),(-1, -1, 1),(1, -1, 1)], k=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) pm.addAttr(ctl , ln = 'fallOff', at = 'double', dv = 20) pm.setAttr(ctl.fallOff, k=1) pm.addAttr(ctl , ln = 'fallOffMode', at = 'enum', en = 'volume:surface') pm.setAttr(ctl.fallOffMode, k=1) pm.addAttr(ctl , ln = 'globalScale', at = 'double', dv = 1) pm.setAttr(ctl.globalScale, k=1) grp = pm.createNode('transform',n = ModifiedName + '_ctrl_grp' ) loc = pm.spaceLocator(n = ModifiedName+'_SoftMod_Ctrl') pm.select(cl=1) pm.parent(loc,grp) pm.parent(ctl,loc) grp.translate.set(pos) mesh = pm.listTransforms(i.split('.')[0])[0] pm.select(mesh) sfMod = cmds.softMod(wn = (str(mesh),str(mesh))) pm.select(cl=1) cmds.softMod(sfMod[0],e=1,wn = (str(ctl),str(ctl))) pm.setAttr(sfMod[0]+'.falloffAroundSelection',0) pm.connectAttr(loc.worldPosition[0],sfMod[0]+'.falloffCenter') mdl = pm.createNode('multDoubleLinear',n = ModifiedName+'_MDL') pm.connectAttr(ctl.fallOffMode,sfMod[0]+'.falloffMode') ctl.fallOff>>mdl.input1 ctl.globalScale>>mdl.input2 pm.connectAttr(mdl.output,sfMod[0]+'.falloffRadius') pm.connectAttr(loc.worldInverseMatrix[0],str(sfMod[0])+'.bindPreMatrix')
def export_cameras_to_fbx(): '''export allBake Camera to FBX files''' FBXSettings = [ "FBXExportBakeComplexAnimation -v true;" "FBXExportCameras -v true;" "FBXProperty Export|AdvOptGrp|UI|ShowWarningsManager -v false;" "FBXProperty Export|AdvOptGrp|UI|GenerateLogData -v false;" ] for s in FBXSettings: mm.eval(s) excludedList = ['frontShape', 'sideShape', 'perspShape', 'topShape'] cams = [(cam, pm.listTransforms(cam)[0]) for cam in pm.ls(type='camera') if str(cam.name()) not in excludedList] scenePath = [str(i) for i in pm.sceneName().split("/")] stripScenePath = scenePath[:-1] sceneName = scenePath[-1] print sceneName filename = "_".join([sceneName[:-3], 'ConvertCam.fbx']) stripScenePath.append(filename) filePath = "/".join(stripScenePath) for c in cams: pm.select(c[1]) oldcam = c[1] newcam = pm.duplicate(oldcam, rr=True)[0] startFrame = int(pm.playbackOptions(q=True, minTime=True)) endFrame = int(pm.playbackOptions(q=True, maxTime=True)) pm.parent(newcam, w=True) for la in pm.listAttr(newcam, l=True): attrName = '.'.join([newcam.name(), str(la)]) pm.setAttr(attrName, l=False) camconstraint = pm.parentConstraint(oldcam, newcam) pm.bakeResults(newcam, at=('translate', 'rotate'), t=(startFrame, endFrame), sm=True) pm.delete(camconstraint) pm.select(newcam, r=True) cc = 'FBXExport -f "%s" -s' % filePath mm.eval(cc)
def selectMayaObjectFromView(self): self.dashboard.moveHand(0) if self.selectionModelInTreeView.hasSelection(): index = self.selectionModelInTreeView.selectedRows()[0] text = self.modelInPolycountTreeView.itemFromIndex(index).text() index = self.selectionModelInTreeView.selectedRows(1)[0] count = int( self.modelInPolycountTreeView.itemFromIndex(index).text()) self.dashboard.moveHand(count) if self.scene == text: # Select all polygon geometries. transforms = pm.listTransforms(type='mesh') pm.select(transforms, r=True) else: # Select individual asset. node = pm.ls(text)[0] not isinstance(node, pm.nt.DagContainer) or pm.select(node, r=True) not isinstance(node, pm.nt.Container ) or self._selectTransformsFromContainer(node)
options, args = parser.parse_args() if len(args) != 2: parser.error("invalid arguments") if not "{lod}" in args[1]: parser.error("OUTPUT must contain {lod}") sys.stderr.write("inputs are " + str(options) + " " + str(args)) import pymel.core as pm pm.openFile(args[0], loadReferenceDepth="none", force=True) details = [] for transform in pm.listTransforms(): try: lod = transform.resolution_export.get() if len(lod): path = args[1].format(lod=lod) pm.showHidden(transform) pm.select(transform) # unparent, otherwise the top node is also exported pm.parent(transform, world=True) pm.exportSelected(path, preserveReferences=True, force=True) details.append({"element": {"path": path}, "context": {"LOD": lod}}) except AttributeError: pass # pass outputs back
def reset_rig(): for obj in pymel.listTransforms(): reset_ctrl(obj)