def initializePlugin(mobject): mplugin = OpenMayaMPx.MFnPlugin(mobject, "Jeremy Ernst\nEpic Games, Inc.", "1.0") status = mplugin.registerUI(makeMyCustomUI, removeMyCustomUI) # check for tools path epicTools() cmds.help(popupMode=True) return status
def __gethelp__(self): """ the function will get the help string via the command of mc.help, then re-format the string into a list and add some valuable data to the attribute flags and flag_type. """ _dict = [] for ln in mc.help(self.__cmd__.__name__).split("\n"): if str(ln).strip().startswith("-"): ent = [] for i in ln.strip().split(" "): if i: ent.append(i) flags = [f[1:] for f in ent[:2]] sn, ln = flags self.flags += flags typ = None if len(ent) > 2: typ = ent[2:] typ = [str(t) for t in typ] entry = [flags, typ] self.flag_typ[str(sn)] = typ self.flag_typ[str(ln)] = typ _dict.append(entry) return _dict
def print_flags(control): print 'in flags', control control_type = get_control_type(control) help = mc.help(control_type) print help print '=' * 20 arg_help = '' print help.strip().split('\n') print '-' * 20 for a in help.strip().split('\n')[4:-3]: # print 'checking',a flag = a.split() # if not flag: # continue print ' checking', flag if flag[1] not in ('-defineTemplate', '-parent', '-docTag', '-exists'): # flag_name = ' '*5+ flag[1] flag_name = ' ' * 5 + flag[1].ljust(25, '.') flag_query = eval('mc.%s("%s",%s=1,q=1)' % (control_type, control, flag[1][1:])) if flag[1] in ('-popupMenuArray', '-childArray'): # flag_query = eval('mc.%s("%s",q=1)' % (control_type, flag[1])) if flag_query: arg_help += flag_name + ' '.join(flag_query[:6]) + '\n' elif flag[1] == '-backgroundColor': # flag_query = eval('mc.%s("%s",q=1)' % (control_type, flag[1])) if flag_query: arg_help += flag_name + str(flag_query) + '\n' else: # print 'yeah','mc.%s("%s",%s=1,q=1)' % (control_type,control, flag[1][1:]) # flag_query = eval('mc.%s("%s",%s=1,q=1)' % (control_type,control, flag[1][1:])) print 'checking', flag[1][1:], '--->', flag_query # if flag_query is None or len(flag_query): arg_help += flag_name + str(flag_query) + '\n' print arg_help
def Event_Act(self): text = self.window.Text_Results.textCursor().selectedText().strip() if text == '': return if self.window.Radio_Attributes.isChecked(): print( '%s = %s' % (text, maya_cmds.getAttr(self.window.Line_Attributes.text().strip() + '.' + text))) elif self.window.Radio_CommandsMel.isChecked( ) or self.window.Radio_CommandsPython.isChecked(): try: print(maya_cmds.help(text)) except RuntimeError: print(mel_eval('whatIs ' + text)) elif self.window.Radio_VariablesMel.isChecked(): print('%s = %s' % (text, mel_eval('$tmp=' + text)))
import maya.cmds as cmds #Create a polysphere cmds.polySphere() #Create a polysphere setting the radius to 10 cmds.polySphere(radius=10) #Print polysphere help docs cmds.help("polySphere") #Query polysphere radius cmds.polySphere(query=True, radius=True) #Edit polysphere radius cmds.polySphere(edit=True, radius=2) #List specified items -> cameras cmds.ls(cameras=True) #List ls related cmds cmds.help("ls") #List items in selection cmds.ls(selection=True) cmds.select("pSphere4") #Add item to selection cmds.select("pPlane1", add=True)
def helpNonVerbose(thing, title='Python Library Documentation: %s', forceload=0): """ Utility method to return python help in the form of a string thing - str or unicode name to get help on title - format string for help result forceload - argument to pydoc.resolve, force object's module to be reloaded from file returns formated help string """ result = "" try: thingStr = thing.encode(cmds.about(codeset=True)) except: thingStr = str(thing) try: # Possible two-stage object resolution! # Sometimes we get docs for strings, other times for objects # try: object, name = pydoc.resolve(thingStr, forceload) except: # Get an object from a string thingObj=eval(thingStr,sys.modules['__main__'].__dict__) object, name = pydoc.resolve(thingObj, forceload) desc = pydoc.describe(object) module = inspect.getmodule(object) if name and '.' in name: desc += ' in ' + name[:name.rfind('.')] elif module and module is not object: desc += ' in module ' + module.__name__ doc = None text = pydoc.TextDoc() if not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isgetsetdescriptor(object) or inspect.ismemberdescriptor(object) or isinstance(object, property)): # If the passed object is a piece of data or an instance, # document its available methods instead of its value. object = type(object) desc += ' object' # if the object is a maya command without a proper docstring, # then tack on the help for it elif module is cmds and inspect.isroutine(object): try: if len(object.__doc__) == 0: doc = cmds.help(object.__name__) except: pass if not doc: doc = text.document(object, name) result = pydoc.plain(title % desc + '\n\n' + doc) # Remove multiple empty lines result = "\n".join([ line for line in result.splitlines() if line.strip()]) except: pass return result
def getCmdInfoBasic( command ): typemap = { 'string' : unicode, 'length' : float, 'float' : float, 'angle' : float, 'int' : int, 'unsignedint' : int, 'on|off' : bool, 'script' : callable, 'name' : 'PyNode' } flags = {} shortFlags = {} removedFlags = {} try: lines = cmds.help( command ).split('\n') except RuntimeError: pass else: synopsis = lines.pop(0) # certain commands on certain platforms have an empty first line if not synopsis: synopsis = lines.pop(0) #_logger.debug(synopsis) if lines: lines.pop(0) # 'Flags' #_logger.debug(lines) for line in lines: line = line.replace( '(Query Arg Mandatory)', '' ) line = line.replace( '(Query Arg Optional)', '' ) tokens = line.split() try: tokens.remove('(multi-use)') multiuse = True except ValueError: multiuse = False #_logger.debug(tokens) if len(tokens) > 1 and tokens[0].startswith('-'): args = [ typemap.get(x.lower(), util.uncapitalize(x) ) for x in tokens[2:] ] numArgs = len(args) # lags with no args in mel require a boolean val in python if numArgs == 0: args = bool # numArgs will stay at 0, which is the number of mel arguments. # this flag should be renamed to numMelArgs #numArgs = 1 elif numArgs == 1: args = args[0] longname = str(tokens[1][1:]) shortname = str(tokens[0][1:]) if longname in keyword.kwlist: removedFlags[ longname ] = shortname longname = shortname elif shortname in keyword.kwlist: removedFlags[ shortname ] = longname shortname = longname #sometimes the longname is empty, so we'll use the shortname for both elif longname == '': longname = shortname flags[longname] = { 'longname' : longname, 'shortname' : shortname, 'args' : args, 'numArgs' : numArgs, 'docstring' : '' } if multiuse: flags[longname].setdefault('modes', []).append('multiuse') shortFlags[shortname] = longname #except: # pass #_logger.debug("could not retrieve command info for", command) res = { 'flags': flags, 'shortFlags': shortFlags, 'description' : '', 'example': '', 'type' : 'other' } if removedFlags: res['removedFlags'] = removedFlags return res
# E:\Courses\Projects_Folder\Python Projects\Maya import maya.cmds as cmds # craeting polySphere with cmds.polySphere() # flags >> radius = 5 cmds.polySphere(radius=5) # flags >> help cmds.help('polySphere') # Modes >> create, Query, Edit # Query sphere radius # prints radius value cmds.polySphere('polySphere1', query=True, radius=True) # Must select or type name # edit radius sphere cmds.polySphere("polySphere1", edit=True, radius=3) # ls, select cmds.ls() cmds.ls(selection=True) cmds.select("pSphere1") cmds.select("pSphere1", add=True) cmds.select("pCube1", replace=True)
import maya.cmds as cmds # Create Polygon Sphere cmds.polySphere() # Create Polygon Sphere with name Sam_Test_GEO cmds.polySphere(n ="Sam_Test_GEO") # Create Polygon Sphere with radius of 10 cmds.polySphere(radius = 10) # Help Command for polySphere command. Will return 3 columns of info. 1. Flag Shorthand 2. Flag Fully Written Out 3. Data Type flag takes print cmds.help("polySphere") # There are 3 types of commands Create, Edit, Query. If a flag is not specified it defaults to Create, to specify a different type of command you have to set that flag to equal True # Query Command for radius of polySphere1 print cmds.polySphere("polySphere1", query=True, radius=True) # If else Query command that changes result based on whether radius equals a certain value if( cmds.polySphere("polySphere1", query=True, radius=True) == 1.0): print("Heyo") else: print("Whop") # Edit command to change polySphere1's radius to equal 5 cmds.polySphere("polySphere1", edit = True, radius = 5)
''' More Loops ''' # enumerate # Showing all the files in a directory. ''' Help and Web Pages ''' # string # maya help & showHelp commands cmds.help( 'textScrollList', language='python', doc=True ) cmds.showHelp( 'http://www.autodesk.com/', absolute=True ) # google search # http://www.google.com/search?sourceid=chrome&ie=UTF-8&q= def googleSearch( item ): google = r'http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=' cmds.showHelp( google + item, absolute=True ) googleSearch( "python" ) ''' Standard Library '''