def parse_arguments(): '''This code was copied from moopy and then slightly modified. ''' # First we parse the arguments with shlex. raw_arguments = shlex.split(lx.arg()) # Now take the parsed args, and loop through each item and split them # into two lists. arguments and keyword_arguments. # We also convert every arg, key, and value into the basic proper python # objects. arguments = [] keyword_arguments = {} def convert_string(string_to_convert): '''We use this function to quickly convert a string into an int, float, or bool. If it is found to not be a bool, int, or float, the string is returned unedited. ''' try: if '.' in string_to_convert: return float(string_to_convert) else: return int(string_to_convert) except ValueError: if string_to_convert.lower() == 'true': return True if string_to_convert.lower() == 'false': return False else: return string_to_convert for raw_argument in raw_arguments: if '=' in raw_argument: # If there is a = character, its a kw_arg split_raw_argument = raw_argument.split('=', 1) # Both the key and the value, we use # convert_string() to make sure the objects are their intended # type. key = convert_string(split_raw_argument[0]) value = convert_string(split_raw_argument[1]) # Now we add this keyword arg to the keyword_arguments object. keyword_arguments[key] = value else: arguments.append(convert_string(raw_argument)) if not arguments: # For clean python, if arguments is empty make it None arguments = None if not keyword_arguments: # Same as above. keyword_arguments = None return (arguments, keyword_arguments,)
def main(): # lx.arg() contains a string of all the args sent through in this case the user.value we want to update arg = lx.arg() # set up our fileOpen Dialog lx.eval('dialog.setup fileOpen') # open the dialog lx.eval('dialog.open') # dialog.result ? holds the name of the file dialog file_to_open = lx.eval('dialog.result ?') # set the user value to the file_to_open lx.eval("user.value %s { %s }" % (arg , file_to_open ) )
def __init__(self, argument_string=None): '''The initilization process creates some default value initilization along with parsing the script arguments. @param argument_string: A possible override to the script arguments given to the script from modo. If given, no call to lx.arg() ever takes place and this is solely used as this script's arguments. @type argument_string: A string like object. ''' # The arguments given to the script, where the keys are the # keywords and indexes of each option. self.arguments = {} # The options held in ScriptOptions instances, where each element is # a dict with keywords pertaining to data on that # option (choices, etc) self.options = [] # A set of all the keywords provided to this ScriptOptions instance. self.all_option_keywords = set() # The total positional arguments held within this class. self.total_positional_options = 0 # The total unique arguments this script contains. # An example of unique is "f" and "file", 2 arguments, but one unique # since they both result in the same value. self.total_unique_options = 0 if argument_string is not None: # If the class was given a manual argument string. self.argument_string = argument_string else: # Since the argument_string is not supplied, ask modo for the real # string. self.argument_string = lx.arg() if not self.argument_string: # If the argument string is empty, replace the value with None self.argument_string = None # The raw arguments are those that have only been created but not # validated self.raw_positional_arguments, self.raw_keyword_arguments = parse_script_arguments( self.argument_string)
def main(): # todo fix me # END MAIN PROGRAM ----------------------------------------------- if __name__ == '__main__': try: # Argument parsing is available through the # lx.arg and lx.args methods. lx.arg returns # the raw argument string that was passed into # the script. lx.args parses the argument string # and returns an array of arguments for easier # processing. argsAsString = lx.arg() argsAsTuple = lx.args() main() except: lx.out(traceback.format_exc())
newpath = os.path.splitext(scene.filename)[0] + "camera_bake.fbx" print "Exporting to {0}".format(newpath) lx.eval("scene.saveAs {0} fbx true".format(newpath)) # Cleanup scene.removeItems(bake_cam) lx.eval("user.value sceneio.fbx.save.exportType {0}".format(export_value)) modo.dialogs.alert(title="Export Finished", message="The camera has been exported to {0}".format(newpath)) # END MAIN PROGRAM ----------------------------------------------- if __name__ == '__main__': try: # Argument parsing is available through the # lx.arg and lx.args methods. lx.arg returns # the raw argument string that was passed into # the script. lx.args parses the argument string # and returns an array of arguments for easier # processing. argsAsString = lx.arg() argsAsTuple = lx.args() main() except: lx.out(traceback.format_exc())
m.step() output = ["{0} Instances de-instanced.\n\n".format(i)] for instance_type in set(instance_types): out = "{0} {1}s".format(instance_types.count(instance_type), instance_type) output.append(out) message = "\n".join(output) modo.dialogs.alert("De-instance complete", message, dtype='info') # END MAIN PROGRAM ----------------------------------------------- if __name__ == '__main__': # Argument parsing is available through the # lx.arg and lx.args methods. lx.arg returns # the raw argument string that was passed into # the script. lx.args parses the argument string # and returns an array of arguments for easier # processing. argsAsString = lx.arg() argsAsTuple = lx.args() try: main() except: print traceback.format_exc()
#! /usr/bin/python import lx lx.eval('log.toConsole true') lx.eval('log.toConsoleRolling true') args = lx.arg().split() lx.out('Starting GS Modo Init') # attempt to set the muster submit ui # NOT WORKING, I THINK script is run before the sheet is created in modo, # maybe there is a way to runn the commands defferred until after startup completes #lx.out('Adding Render Submit UI') #lx.eval('select.attr {49634997570:sheet} set') #lx.eval('attr.parent {frm_modomodes_render:sheet} 19')
def pymain(): args = lx.arg() arg_split = args.split() if len(arg_split) == 0: try: arg=panel("UVBlockAligner.mode",None,"integer","which mode:", "U Center;V Center;Left;Right;Top;Bottom;Max Width;Min Width;" +"Max Height;Min Height;Horizontal Distribution;Vertical Distribution;" +"Horizontal Space;Vertical Space") except: return elif len(arg_split) > 2: arg = "%s %s" % (arg_split[0], arg_split[1]) else: arg = args spc=0 if "Space" in arg: if len(arg_split) > 2: spc = float(arg_split[2]) else: try: spc=panel("UVBlockAligner.space",None,"float","Space Distance:",None) except: return all=False main=lx.eval("query layerservice layer.index ? main") vmaps=set(lx.evalN("query layerservice vmaps ? selected")) texture=set(lx.evalN("query layerservice vmaps ? texture")) seltexture=list(vmaps.intersection(texture)) if len(seltexture)==0: return texselerror seltexture=int(seltexture[0]) lx.eval("query layerservice vmap.name ? %s" % seltexture) lx.eval("select.type polygon") backup=lx.evalN("query layerservice polys ? selected") if len(backup)!=0: lx.eval("select.connect") selpolys=set(lx.evalN("query layerservice polys ? selected")) else: selpolys=set(lx.evalN("query layerservice polys ? all")) all=True lx.eval("select.drop polygon") block=[] while len(selpolys)!=0: p=list(selpolys)[0] lx.command("select.element",layer=main,type="polygon",mode="set",index=int(p)) lx.eval("select.connect") bps=lx.evalN("query layerservice polys ? selected") range=None for p in bps: verts=lx.evalN("query layerservice poly.vertList ? %s" % p) for v in verts: uv=lx.eval("query layerservice uv.pos ? (%s,%s)" % (p,v)) if range==None: range=[uv[0],uv[1],uv[0],uv[1]] else: if range[0]>uv[0]:range[0]=uv[0] if range[1]>uv[1]:range[1]=uv[1] if range[2]<uv[0]:range[2]=uv[0] if range[3]<uv[1]:range[3]=uv[1] selpolys=selpolys.difference(set(bps)) block.append([range,bps]) if "Horizontal" in arg:block.sort(hcmp) if "Vertical" in arg:block.sort(vcmp) cu=0 cv=0 minu=None n=len(block) for b in block: r=b[0] if minu==None: minu=r[0] maxu=r[2] minv=r[1] maxv=r[3] sumw=r[2]-r[0] sumh=r[3]-r[1] minwu=maxwu=r[2]-r[0] minwv=maxwv=r[3]-r[1] else: if minu>r[0]:minu=r[0] if maxu<r[2]:maxu=r[2] if minv>r[1]:minv=r[1] if maxv<r[3]:maxv=r[3] wu=r[2]-r[0] wv=r[3]-r[1] if minwu>wu:minwu=wu if minwv>wv:minwv=wv if maxwu<wu:maxwu=wu if maxwv<wv:maxwv=wv sumw=sumw+r[2]-r[0] sumh=sumh+r[3]-r[1] cu=cu+(r[0]+r[2])/2 cv=cv+(r[1]+r[3])/2 cu=cu/n cv=cv/n if n>1: spw=((maxu-minu)-sumw)/(n-1) sph=((maxv-minv)-sumh)/(n-1) ptu=(maxu+minu)/2-(spc*(n-1)+sumw)/2 ptv=(maxv+minv)/2-(spc*(n-1)+sumh)/2 for ptr,b in enumerate(block): r=b[0] lx.eval("select.drop polygon") for p in b[1]: lx.command("select.element",layer=main,type="polygon",mode="add",index=int(p)) if arg=="U Center": uvtrans(cu-(r[0]+r[2])/2,0,0) elif arg=="V Center": uvtrans(0,cv-(r[1]+r[3])/2,0) elif arg=="Left": uvtrans(minu-r[0],0,0) elif arg=="Right": uvtrans(maxu-r[2],0,0) elif arg=="Bottom": uvtrans(0,minv-r[1],0) elif arg=="Top": uvtrans(0,maxv-r[3],0) elif arg=="Min Width": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0]+r[2])/2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1]+r[3])/2)) uvtrans(minwu/(r[2]-r[0])*100,100,1) lx.eval("tool.set actr.auto off 0") elif arg=="Max Width": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0]+r[2])/2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1]+r[3])/2)) uvtrans(maxwu/(r[2]-r[0])*100,100,1) lx.eval("tool.set actr.auto off 0") elif arg=="Min Height": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0]+r[2])/2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1]+r[3])/2)) uvtrans(100,minwv/(r[3]-r[1])*100,1) lx.eval("tool.set actr.auto off 0") elif arg=="Max Height": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0]+r[2])/2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1]+r[3])/2)) uvtrans(100,maxwv/(r[3]-r[1])*100,1) lx.eval("tool.set actr.auto off 0") elif arg=="Horizontal Distribution": if ptr==0: pu=r[2] continue elif ptr==n-1:break pu=pu+spw uvtrans(pu-r[0],0,0) pu=pu+(r[2]-r[0]) elif arg=="Vertical Distribution": if ptr==0: pv=r[3] continue elif ptr==n-1:break pv=pv+sph uvtrans(0,pv-r[1],0) pv=pv+(r[3]-r[1]) elif arg=="Horizontal Space": uvtrans(ptu-r[0],0,0) ptu=ptu+spc+r[2]-r[0] elif arg=="Vertical Space": uvtrans(0,ptv-r[1],0) ptv=ptv+spc+r[3]-r[1] lx.eval("select.drop polygon") if not all: for p in backup: lx.command("select.element",layer=main,type="polygon",mode="add",index=int(p))
def pymain(): args = lx.arg() arg_split = args.split() if len(arg_split) == 0: try: arg = panel( "UVBlockAligner.mode", None, "integer", "which mode:", "U Center;V Center;Left;Right;Top;Bottom;Max Width;Min Width;" + "Max Height;Min Height;Horizontal Distribution;Vertical Distribution;" + "Horizontal Space;Vertical Space") except: return elif len(arg_split) > 2: arg = "%s %s" % (arg_split[0], arg_split[1]) else: arg = args spc = 0 if "Space" in arg: if len(arg_split) > 2: spc = float(arg_split[2]) else: try: spc = panel("UVBlockAligner.space", None, "float", "Space Distance:", None) except: return all = False main = lx.eval("query layerservice layer.index ? main") vmaps = set(lx.evalN("query layerservice vmaps ? selected")) texture = set(lx.evalN("query layerservice vmaps ? texture")) seltexture = list(vmaps.intersection(texture)) if len(seltexture) == 0: return texselerror seltexture = int(seltexture[0]) lx.eval("query layerservice vmap.name ? %s" % seltexture) lx.eval("select.type polygon") backup = lx.evalN("query layerservice polys ? selected") if len(backup) != 0: lx.eval("select.connect") selpolys = set(lx.evalN("query layerservice polys ? selected")) else: selpolys = set(lx.evalN("query layerservice polys ? all")) all = True lx.eval("select.drop polygon") block = [] while len(selpolys) != 0: p = list(selpolys)[0] lx.command("select.element", layer=main, type="polygon", mode="set", index=int(p)) lx.eval("select.connect") bps = lx.evalN("query layerservice polys ? selected") range = None for p in bps: verts = lx.evalN("query layerservice poly.vertList ? %s" % p) for v in verts: uv = lx.eval("query layerservice uv.pos ? (%s,%s)" % (p, v)) if range == None: range = [uv[0], uv[1], uv[0], uv[1]] else: if range[0] > uv[0]: range[0] = uv[0] if range[1] > uv[1]: range[1] = uv[1] if range[2] < uv[0]: range[2] = uv[0] if range[3] < uv[1]: range[3] = uv[1] selpolys = selpolys.difference(set(bps)) block.append([range, bps]) if "Horizontal" in arg: block.sort(hcmp) if "Vertical" in arg: block.sort(vcmp) cu = 0 cv = 0 minu = None n = len(block) for b in block: r = b[0] if minu == None: minu = r[0] maxu = r[2] minv = r[1] maxv = r[3] sumw = r[2] - r[0] sumh = r[3] - r[1] minwu = maxwu = r[2] - r[0] minwv = maxwv = r[3] - r[1] else: if minu > r[0]: minu = r[0] if maxu < r[2]: maxu = r[2] if minv > r[1]: minv = r[1] if maxv < r[3]: maxv = r[3] wu = r[2] - r[0] wv = r[3] - r[1] if minwu > wu: minwu = wu if minwv > wv: minwv = wv if maxwu < wu: maxwu = wu if maxwv < wv: maxwv = wv sumw = sumw + r[2] - r[0] sumh = sumh + r[3] - r[1] cu = cu + (r[0] + r[2]) / 2 cv = cv + (r[1] + r[3]) / 2 cu = cu / n cv = cv / n if n > 1: spw = ((maxu - minu) - sumw) / (n - 1) sph = ((maxv - minv) - sumh) / (n - 1) ptu = (maxu + minu) / 2 - (spc * (n - 1) + sumw) / 2 ptv = (maxv + minv) / 2 - (spc * (n - 1) + sumh) / 2 for ptr, b in enumerate(block): r = b[0] lx.eval("select.drop polygon") for p in b[1]: lx.command("select.element", layer=main, type="polygon", mode="add", index=int(p)) if arg == "U Center": uvtrans(cu - (r[0] + r[2]) / 2, 0, 0) elif arg == "V Center": uvtrans(0, cv - (r[1] + r[3]) / 2, 0) elif arg == "Left": uvtrans(minu - r[0], 0, 0) elif arg == "Right": uvtrans(maxu - r[2], 0, 0) elif arg == "Bottom": uvtrans(0, minv - r[1], 0) elif arg == "Top": uvtrans(0, maxv - r[3], 0) elif arg == "Min Width": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0] + r[2]) / 2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1] + r[3]) / 2)) uvtrans(minwu / (r[2] - r[0]) * 100, 100, 1) lx.eval("tool.set actr.auto off 0") elif arg == "Max Width": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0] + r[2]) / 2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1] + r[3]) / 2)) uvtrans(maxwu / (r[2] - r[0]) * 100, 100, 1) lx.eval("tool.set actr.auto off 0") elif arg == "Min Height": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0] + r[2]) / 2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1] + r[3]) / 2)) uvtrans(100, minwv / (r[3] - r[1]) * 100, 1) lx.eval("tool.set actr.auto off 0") elif arg == "Max Height": lx.eval("tool.set actr.auto on 0") lx.eval("tool.setAttr center.auto cenU %s" % ((r[0] + r[2]) / 2)) lx.eval("tool.setAttr center.auto cenV %s" % ((r[1] + r[3]) / 2)) uvtrans(100, maxwv / (r[3] - r[1]) * 100, 1) lx.eval("tool.set actr.auto off 0") elif arg == "Horizontal Distribution": if ptr == 0: pu = r[2] continue elif ptr == n - 1: break pu = pu + spw uvtrans(pu - r[0], 0, 0) pu = pu + (r[2] - r[0]) elif arg == "Vertical Distribution": if ptr == 0: pv = r[3] continue elif ptr == n - 1: break pv = pv + sph uvtrans(0, pv - r[1], 0) pv = pv + (r[3] - r[1]) elif arg == "Horizontal Space": uvtrans(ptu - r[0], 0, 0) ptu = ptu + spc + r[2] - r[0] elif arg == "Vertical Space": uvtrans(0, ptv - r[1], 0) ptv = ptv + spc + r[3] - r[1] lx.eval("select.drop polygon") if not all: for p in backup: lx.command("select.element", layer=main, type="polygon", mode="add", index=int(p))