def arguments(cls, arglist, selection=True): """ Rturn the contents of arglist as a list of strings. If <selection> is True, the arglist will be populated with Maya selection """ syntax = MSyntax() syntax.setObjectType(MSyntax.kStringObjects) syntax.useSelectionAsDefault(selection) adb = MArgDatabase(syntax, arglist) return adb.getObjectStrings()
def generic_syntax(cls): """ Creates a generic syntax object. Automatically added to any class using PluginMeta as a metaclass. If the class defines it's own syntax() class method, that will be used instead. """ m = MSyntax() m.setObjectType(MSyntax.kSelectionList) m.useSelectionAsDefault(True) return m
def objects(cls, arglist, selection=True): """ Returns the contents of arglist as an MSelectionList. If <selection> is True, uses the maya selection as the default. Note this does no error handling, if the argList has a bad object name a RuntimeError will be raised """ syntax = MSyntax() syntax.setObjectType(MSyntax.kSelectionList) syntax.useSelectionAsDefault(selection) try: adb = MArgDatabase(syntax, arglist) return adb.getObjectList() except RuntimeError as e: raise RuntimeError("could not parse argument list", cls.arguments(arglist))
class Flags(object): """ A context manager that allows a shorthand method of creating flags. Entries are added in the form name = type where name is python name and type is a type (bool, float, etc or MAngle, MDistance, or MTime). A type of `object` is interpreted as a selectionItem. The complete list of mappings is in the TYPE_MAPPINGS dictionary. Example usage: with Flags() as f: boolValue = bool uintValue = int doubleValue = float syntax = f.syntax() would create an MSyntax object with these flags: -b -bool kBoolean -u -uintValue kUnsigned -d -doubleValue kDouble You can customize the short name of the flag using this form: with Flags() as f: longName = 'ln', str which would create an MSyntax like -ln -longName kString To create a multi-use flag, enclose the type in square brackets with Flags() as f: multiInt = [int] If the flags 'edit' or 'query' are provided, the final MSyntax will have its edit or query flags enabled by default. """ def __init__(self): self.flags = [] self._syntax = MSyntax() def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): if exc_type: return False for k, v in inspect.currentframe().f_back.f_locals.items(): if k in ('self', 'cls') or v is self: continue flag = k value = v if isinstance(v, tuple) else (flag[0], v) short, typespec = value multi = isinstance(typespec, list) if multi: typespec = typespec[0] self.flags.append( SyntaxItem(flag, short, dataType=typespec, multi=multi)) # HACK ALERT ------------------------------------------------------ # there seems to be a bug in 2015 SP5 which # ignores the first flag added. This fixes that # by adding a dummy flag if self.flags and _MAYA_VERSION in ('2015', ): self._syntax.addFlag('-adk', '-adsk_2015_fix', MSyntax.kNoArg) # ----------------------------------------------------------------- # another symptom of the same problem is garbled flag names for f in self.flags: f.insert(self._syntax) return True def syntax(self): return self._syntax
def __init__(self): self.flags = [] self._syntax = MSyntax()
class Flags(object): """ A context manager that allows a shorthand method of creating flags. Entries are added in the form name = type where name is python name and type is a type (bool, float, etc or MAngle, MDistance, or MTime). A type of `object` is interpreted as a selectionItem. The complete list of mappings is in the TYPE_MAPPINGS dictionary. Example usage: with Flags() as f: boolValue = bool uintValue = int doubleValue = float syntax = f.syntax() would create an MSyntax object with these flags: -b -bool kBoolean -u -uintValue kUnsigned -d -doubleValue kDouble You can customize the short name of the flag using this form: with Flags() as f: longName = 'ln', str which would create an MSyntax like -ln -longName kString To create a multi-use flag, enclose the type in square brackets with Flags() as f: multiInt = [int] If the flags 'edit' or 'query' are provided, the final MSyntax will have its edit or query flags enabled by default. """ def __init__(self): self.flags = [] self._syntax = MSyntax() def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): if exc_type: return False for k, v in inspect.currentframe().f_back.f_locals.items(): if k in ('self', 'cls') or v is self: continue flag = k value = v if isinstance(v, tuple) else (flag[0], v) short, typespec = value multi = isinstance(typespec, list) if multi: typespec = typespec[0] self.flags.append(SyntaxItem(flag, short, dataType=typespec, multi=multi)) # HACK ALERT ------------------------------------------------------ # there seems to be a bug in 2015 SP5 which # ignores the first flag added. This fixes that # by adding a dummy flag if self.flags and _MAYA_VERSION in ('2015',): self._syntax.addFlag('-adk', '-adsk_2015_fix', MSyntax.kNoArg) # ----------------------------------------------------------------- # another symptom of the same problem is garbled flag names for f in self.flags: f.insert(self._syntax) return True def syntax(self): return self._syntax