def pythonToMel(arg): """ convert a python object to a string representing an equivalent value in mel iterables are flattened. mapping types like dictionaries have their key value pairs flattened: { key1 : val1, key2 : val2 } -- > ( key1, val1, key2, val2 ) """ if util.isNumeric(arg): return str(arg) if isinstance(arg, datatypes.Vector): return '<<%f,%f,%f>>' % ( arg[0], arg[1], arg[2] ) if util.isIterable(arg): if util.isMapping(arg): arg = list(_flatten(arg.iteritems())) else: arg = list(_flatten(arg)) forceString = False for each in arg: if not util.isNumeric(each): forceString = True break if forceString: newargs = [ '"%s"' % x for x in arg ] else: newargs = [ str(x) for x in arg ] return '{%s}' % ','.join( newargs ) # in order for PyNodes to get wrapped in quotes we have to treat special cases first, # we cannot simply test if arg is an instance of basestring because PyNodes are not return '"%s"' % cmds.encodeString(str(arg))
def pythonToMel(arg): """ convert a python object to a string representing an equivalent value in mel iterables are flattened. mapping types like dictionaries have their key value pairs flattened: { key1 : val1, key2 : val2 } -- > ( key1, val1, key2, val2 ) """ if arg is None: return '' if arg is True or arg is False: return str(arg).lower() if util.isNumeric(arg): return str(arg) if isinstance(arg, datatypes.Vector): return '<<%f,%f,%f>>' % (arg[0], arg[1], arg[2]) if util.isIterable(arg): if util.isMapping(arg): arg = list(_flatten(arg.iteritems())) else: arg = list(_flatten(arg)) forceString = False for each in arg: if not util.isNumeric(each): forceString = True break if forceString: newargs = ['"%s"' % x for x in arg] else: newargs = [str(x) for x in arg] return '{%s}' % ','.join(newargs) # in order for PyNodes to get wrapped in quotes we have to treat special # cases first, we cannot simply test if arg is an instance of basestring # because PyNodes are not return '"%s"' % cmds.encodeString(str(arg))