def buildHierarchy_itemTags(item_name): item_tags = [] temp = lx.evalN('query sceneservice item.tagTypes ? {%s} ' % item_name) for i in temp: item_tags.append(i) item_tagValues = [] temp = [] temp = lx.evalN('query sceneservice item.tags ? {%s} ' % item_name) for i in temp: item_tagValues.append(i) return (item_tags, item_tagValues)
def retrieve_args(self): ''' Retrieves a list of arguments and datatypes from modo's commandservice. See http://sdk.luxology.com/wiki/Commandservice#command.argNames Args: None Returns: None ''' if not self.command: raise Exception("Command string not set.") # Names of the arguments for the current command. argNames = lx.evalN("query commandservice command.argNames ? {%s}" % self.command) # No arguments to add if not argNames: return # Populate the list. for n in range(len(argNames)): self.args.append( MacroCommandArg(parent=self, arg_index=n, controller=self._controller))
def vmunselect(): vmaps=lx.evalN("query layerservice vmaps ? selected") ctd={"weight":"wght","texture":"txuv","subvweight":"subd","morph":"morf","absmorpf":"spot","rgb":"rgb","rgba":"rgba","pick":"pick"} for vm in vmaps: name=lx.eval("query layerservice vmap.name ? %s" % vm) type=ctd[lx.eval("query layerservice vmap.type ? %s" % vm)] lx.eval("select.vertexMap \"%s\" %s remove" % (name,type))
def main(): global osType global unix_path global win_path global save_selection lx.trace(False) osType = platform.system() lx.out("TYPE OS: " + osType) unix_path = "/Volumes/ProjectsRaid/WorkingProjects" win_path = "Z:\AzureSync\CloudComputing\WorkingProjects" save_selection = lx.evalN("query sceneservice selection ? all") renderoutputs = bd_utils.get_ids("renderOutput") if renderoutputs: for x in renderoutputs: update_render_output(x) bd_utils.restoreSelection(save_selection) else: bd_utils.restoreSelection(save_selection)
def checkMaskInRom(maskID): romMaskExists = None romChildrenAll = lx.evalN("query sceneservice mask.children ? {ROM}") romChildren = [] for child in romChildrenAll: if lx.eval("query sceneservice item.type ? {%s}" % child) == "mask": romChildren.append(child) lx.eval("select.item %s set" % maskID) maskItemSel = lx.eval("mask.setMesh ?") if maskItemSel == "(all)": for romChild in romChildren: lx.out("---") lx.eval("select.item %s" % romChild) romChildSel = lx.eval("mask.setMesh ?") if romChildSel == "(all)": romChildName = lx.eval("item.name ?") lx.out(romChildName.split(" ")[0]) lx.eval("select.item %s" % maskID) maskName = lx.eval("item.name ?") lx.out(maskName.split(" ")[0]) if romChildName.split(" ")[0] == maskName.split(" ")[0]: romMaskExists = romChild else: for romChild in romChildren: lx.out("---") lx.eval("select.item %s" % romChild) romChildSel = lx.eval("mask.setMesh ?") if romChildSel == maskItemSel: lx.out(romChildSel) lx.out(maskItemSel) romMaskExists = romChild return romMaskExists
def writeCamera(name, plist): camera_entry = [name] camera_entry.append(lx.eval("query sceneservice item.pos ? " + name)) camera_entry.append([ math.degrees(x) for x in lx.eval("query sceneservice item.rot ? " + name) ]) fov = "35" near_p = "500" far_p = "10000" for i in range(lx.eval("query sceneservice channel.N ?")): channel_name = lx.eval("query sceneservice channel.name ? " + str(i)) channel_value = lx.eval("query sceneservice channel.value ? " + str(i)) spline_name = "" if channel_name == 'spline': spline_name = channel_value elif channel_name == 'FOV': fov = channel_value elif channel_name == 'NearP': near_p = channel_value elif channel_name == 'FarP': far_p = channel_value if spline_name: for i in lx.evalN("query layerservice layers ? all"): if spline_name == lx.eval("query layerservice layer.name ? " + str(i)): spline_entry = [spline_name] for poly in lx.evalN("query layerservice polys ? all"): if lx.eval("query layerservice poly.type ? " + str(poly)) == 'curve': for vert in lx.evalN( "query layerservice poly.vertList ? " + str(poly)): spline_entry.append( lx.eval("query layerservice vert.pos ? " + str(vert))) if spline_entry: plist['Splines'].append(spline_entry) camera_entry.append([fov, near_p, far_p]) camera_entry.append(spline_name) plist['Cameras'].append(camera_entry)
def checkRoInGroup(maskID, roType): roExists = None grpChildrenAll = lx.evalN("query sceneservice mask.children ? %s" % maskID) grpChildren = [] for grpChild in grpChildrenAll: if lx.eval("query sceneservice item.type ? {%s}" % grpChild) == "renderOutput": lx.eval("select.item %s set" % grpChild) roEffect = lx.eval("shader.setEffect ?") if roEffect == roType: roExists = grpChild return roExists
def main(): meshIDs = lx.evalN('query sceneservice selection ? mesh') if (len(meshIDs) == 0): lx.out('At least one mesh must be selected to create links') sys.exit() targetFile = customfile('fileOpen', 'Load Target file', 'fst', 'FST', '*.fst', None) if (targetFile != None): parseTarget(targetFile) else: sys.exit() for meshID in meshIDs: linkMorphs(meshID)
def main(): global outputs outputs = [] allnames = [] selection = lx.evalN('query sceneservice selection ? mask') try: if len(selection) == 0: lx.out('No Groups selected!') else: for id in selection: name = lx.eval('query sceneservice mask.name ? %s' % id) children = lx.evalN('query sceneservice mask.children ? %s' % id) childrenstring = ''.join(children) if "renderOutput" in childrenstring: lx.eval('layout.createOrClose EventLog "Event Log_layout" ' 'title:@macros.layouts@EventLog@ width:600 height:600 ' 'persistent:true ' 'open:true') lx.out('"%s" already has one or more RenderOutputs!' % name) allnames.append(name) else: lx.out('Adding Alpha output to "%s"' % name) addmask(id, name, "shade.alpha") lx.out('Adding Diffuse Color output to "%s"' % name) addmask(id, name, "mat.diffCol") # select new render outputs at the end selectnew() lx.out('Success!') if len(allnames) is not 0: lx.out('Some layers already had one or more RenderOutputs:') lx.out(allnames) except: lx.eval('layout.createOrClose EventLog "Event Log_layout" ' 'title:@macros.layouts@EventLog@ width:600 height:600 persistent:true ' 'open:true') lx.out("ERROR failed with ", sys.exc_info())
def nextedge(v, plist, loopedge): find = False for e in list(loopedge): vid = e.strip("()").split(",") if str(v) in vid: find = True break if not find: return None loopedge.remove(e) p = set(lx.evalN("query layerservice edge.polyList ? %s" % e)) if len(p.intersection(plist)) != 0: return None else: return e
def load_files(): """ Load in files and save complete paths in a list """ try: lx.eval("dialog.setup fileOpenMulti") lx.eval("dialog.title {Import MARI textures}") lx.eval("dialog.result ok") lx.eval("dialog.open") return lx.evalN("dialog.result ?") except RuntimeError: return False
def peeler(edge_list): mainlayer = lx.eval("query layerservice layers ? main") for edges in edge_list: polys = lx.evalN("query layerservice edge.polyList ? " + str(edges[0][0]) + "," + str(edges[0][1])) lx.eval("select.type polygon") lx.eval("select.element " + str(mainlayer) + " polygon set " + str(polys[0])) lx.eval("select.connect") lx.eval("uv.delete") lx.eval("select.drop edge") for edge in edges: lx.eval("select.element " + str(mainlayer) + " edge add " + str(edge[0]) + " " + str(edge[1])) lx.eval("tool.set uv.peeler on") lx.eval("tool.reset") lx.eval("tool.doApply") lx.eval("tool.set uv.peeler off")
def vmunselect(): vmaps = lx.evalN("query layerservice vmaps ? selected") ctd = { "weight": "wght", "texture": "txuv", "subvweight": "subd", "morph": "morf", "absmorpf": "spot", "rgb": "rgb", "rgba": "rgba", "pick": "pick" } for vm in vmaps: name = lx.eval("query layerservice vmap.name ? %s" % vm) type = ctd[lx.eval("query layerservice vmap.type ? %s" % vm)] lx.eval("select.vertexMap \"%s\" %s remove" % (name, type))
def edgelist(edges, verts): edlist = [] for e in edges: length = lx.eval("query layerservice edge.length ? %(e)s" % vars()) vmid = e.strip("()").split(",") polys = lx.evalN("query layerservice edge.polylist ? %(e)s" % vars()) vid1 = "(%s,%s)" % (polys[0], vmid[0]) cvid1 = "(-1,%s)" % vmid[0] vid2 = "(%s,%s)" % (polys[0], vmid[1]) cvid2 = "(-1,%s)" % vmid[1] pos1 = None if (vid1 in verts or cvid1 in verts) and (vid2 in verts or cvid2 in verts): pos1 = lx.eval("query layerservice uv.pos ? %(vid1)s" % vars()) pos2 = lx.eval("query layerservice uv.pos ? %(vid2)s" % vars()) if len(polys) == 2: vid3 = "(%s,%s)" % (polys[1], vmid[0]) cvid3 = "(-1,%s)" % vmid[0] vid4 = "(%s,%s)" % (polys[1], vmid[1]) cvid4 = "(-1,%s)" % vmid[1] if (vid3 in verts or cvid3 in verts) and (vid4 in verts or cvid4 in verts): pos3 = lx.eval("query layerservice uv.pos ? %(vid3)s" % vars()) pos4 = lx.eval("query layerservice uv.pos ? %(vid4)s" % vars()) if pos1 == None: edlist.append([[[vid3], [vid4]], [pos3, pos4], length, uvlength(pos3, pos4)]) else: if issame(pos1, pos3) and issame(pos2, pos4): edlist.append([[[vid1, vid3], [vid2, vid4]], [pos1, pos2], length, uvlength(pos1, pos2)]) else: edlist.append([[[vid1], [vid2]], [pos1, pos2], length, uvlength(pos1, pos2)]) edlist.append([[[vid3], [vid4]], [pos3, pos4], length, uvlength(pos3, pos4)]) else: if pos1 != None: edlist.append([[[vid1], [vid2]], [pos1, pos2], length, uvlength(pos1, pos2)]) else: if pos1 != None: edlist.append([[[vid1], [vid2]], [pos1, pos2], length, uvlength(pos1, pos2)]) return edlist
def main(): save_selection = lx.evalN("query sceneservice selection ? all") filename = lx.eval("item.channel renderOutput$filename ?") path = filename.rsplit(os.sep, 1) lx.out("Opening path: " + path[0]) try: subprocess.Popen(['open', path[0]]) except: lx.eval('layout.createOrClose EventLog "Event Log_layout" ' 'title:@macros.layouts@EventLog@ width:600 height:600 persistent:true ' 'open:true') lx.out("ERROR Opening Render Output path failed with ", sys.exc_info()) bd_utils.restoreSelection(save_selection)
def main(): save_selection = lx.evalN("query sceneservice selection ? all") groups = pyModo.Group_Name_All() passes = False pyModo.Render_Count_All() for group in groups: if group == "passes": passes = True if passes: lx.out("Setting up proper Output Pattern: '[<pass>]_[<output>][<LR>].<FFFF>'") lx.eval("select.Item Render") lx.eval('item.channel outPat "[<pass>]_[<output>][<LR>].<FFFF>"') else: lx.out("Setting up proper Output Pattern: '[<pass>][<output>][<LR>].<FFFF>'") lx.eval("select.Item Render") lx.eval('item.channel outPat "[<pass>][<output>][<LR>].<FFFF>"') bd_utils.restoreSelection(save_selection)
def main(): save_selection = lx.evalN("query sceneservice selection ? all") filepath = bd_utils.filePath() filename = os.path.splitext(bd_utils.fileName()) fileextension = filename[1] filename = filename[0] filename = filename.rsplit("_", 1) version = filename[1] filename = filename[0] lx.out('Current file "' + filename + '" is at Version ' + version + '.') version = version.lstrip("_v") created = False while created is False: version = str(int(version) + 1).zfill(2) newfile = filepath + os.sep + filename + "_v" + version + fileextension if os.path.isfile(newfile): lx.out("Version " + version + " already exists. Increasing version count.") pass else: lx.out("Saving as Version " + version) try: lx.eval('scene.saveAs {%s}' % newfile) except: lx.eval('layout.createOrClose EventLog "Event Log_layout" ' 'title:@macros.layouts@EventLog@ width:600 height:600 persistent:true ' 'open:true') lx.out("ERROR Scene save failed with ", sys.exc_info()) created = True bd_utils.restoreSelection(save_selection)
def edgelist(edges,verts) : edlist = [] for e in edges : length = lx.eval("query layerservice edge.length ? %(e)s" % vars()) vmid=e.strip("()").split(",") polys = lx.evalN("query layerservice edge.polylist ? %(e)s" % vars()) vid1 = "(%s,%s)" %(polys[0],vmid[0]) cvid1 = "(-1,%s)" % vmid[0] vid2 = "(%s,%s)" %(polys[0],vmid[1]) cvid2 = "(-1,%s)" % vmid[1] pos1 = None if (vid1 in verts or cvid1 in verts) and (vid2 in verts or cvid2 in verts): pos1 = lx.eval("query layerservice uv.pos ? %(vid1)s" % vars()) pos2 = lx.eval("query layerservice uv.pos ? %(vid2)s" % vars()) if len(polys)==2 : vid3 = "(%s,%s)" %(polys[1],vmid[0]) cvid3 = "(-1,%s)" % vmid[0] vid4 = "(%s,%s)" %(polys[1],vmid[1]) cvid4 = "(-1,%s)" % vmid[1] if (vid3 in verts or cvid3 in verts) and (vid4 in verts or cvid4 in verts): pos3 = lx.eval("query layerservice uv.pos ? %(vid3)s" % vars()) pos4 = lx.eval("query layerservice uv.pos ? %(vid4)s" % vars()) if pos1 == None : edlist.append([[[vid3],[vid4]],[pos3,pos4],length,uvlength(pos3,pos4)]) else : if issame(pos1,pos3) and issame(pos2,pos4) : edlist.append([[[vid1,vid3],[vid2,vid4]],[pos1,pos2],length,uvlength(pos1,pos2)]) else: edlist.append([[[vid1],[vid2]],[pos1,pos2],length,uvlength(pos1,pos2)]) edlist.append([[[vid3],[vid4]],[pos3,pos4],length,uvlength(pos3,pos4)]) else: if pos1 != None : edlist.append([[[vid1],[vid2]],[pos1,pos2],length,uvlength(pos1,pos2)]) else : if pos1 != None : edlist.append([[[vid1],[vid2]],[pos1,pos2],length,uvlength(pos1,pos2)]) return edlist
def panel(var,val,type,mes,lst): if lx.eval("query scriptsysservice userValue.isDefined ? %(var)s" % vars()) == 0 : lx.eval("user.defNew %(var)s %(type)s temporary" % vars()) if val!=None : lx.eval("user.value %(var)s %(val)s" % vars()) if mes != None : lx.eval("user.def %(var)s username \"%(mes)s\"" % vars()) if lst!=None : lx.eval("user.def %(var)s list %(lst)s" % vars()) if mes != None : lx.eval("user.value %(var)s" % vars()) return lx.eval("user.value %(var)s ?" % vars()) mon=lx.Monitor() main=lx.eval("query layerservice layers ? main") vmaps = lx.evalN("query layerservice vmaps ? weight") wmapnameset=set() for w in vmaps : wname = lx.eval("query layerservice vmap.name ? %(w)s" % vars()) wmapnameset.add(wname) lx.eval("select.type vertex") selverts=lx.evalN("query layerservice verts ? selected") nonselection=False if len(selverts)==0: nonselection=True selverts=lx.evalN("query layerservice verts ? all") mon.init(len(selverts)) weightmap=panel("uv2weight.weight",None,"string","WeightMap",None) useuv=panel("uv2weight.use",None,"integer","use","U;V") shift=panel("uv2weight.shift",None,"float","Shift Value",None) scale=panel("uv2weight.scale",None,"percent","Scale Value",None)
vars()) == 0: lx.eval("user.defNew %(var)s %(type)s temporary" % vars()) if val != None: lx.eval("user.value %(var)s %(val)s" % vars()) if mes != None: lx.eval("user.def %(var)s username \"%(mes)s\"" % vars()) if lst != None: lx.eval("user.def %(var)s list %(lst)s" % vars()) if mes != None: lx.eval("user.value %(var)s" % vars()) return lx.eval("user.value %(var)s ?" % vars()) mon = lx.Monitor() main = lx.eval("query layerservice layers ? main") vmaps = lx.evalN("query layerservice vmaps ? weight") wmapnameset = set() for w in vmaps: wname = lx.eval("query layerservice vmap.name ? %(w)s" % vars()) wmapnameset.add(wname) lx.eval("select.type vertex") selverts = lx.evalN("query layerservice verts ? selected") nonselection = False if len(selverts) == 0: nonselection = True selverts = lx.evalN("query layerservice verts ? all") mon.init(len(selverts)) weightmap = panel("uv2weight.weight", None, "string", "WeightMap", None) useuv = panel("uv2weight.use", None, "integer", "use", "U;V") shift = panel("uv2weight.shift", None, "float", "Shift Value", None) scale = panel("uv2weight.scale", None, "percent", "Scale Value", None)
def retreive_arg_meta(self): ''' Retrieve a list of arguments and datatypes from modo's commandservice. See http://sdk.luxology.com/wiki/Commandservice#command.argNames Args: None Returns: None Example: [ { 'argName': 'argname', 'argUsername': '******', 'argType': 0, # 0 for generic objects, 1 for integers, 2 for floats an 3 for strings 'argTypeName': 'boolean', 'argDesc': 'What the argument does.', 'argExample': 'Example if available.' 'argValue': 'Value of the argument.' } ] ''' base_command = self.parent.command arg_index = self._arg_index if not base_command: raise Exception("Invalid parent command.") return # Names of the arguments for the current command. if not lx.evalN( "query commandservice command.argNames ? {%s}" % base_command): raise Exception( "Parent command has no args. Why do I exist? (Big Questions In Life)" ) return # Unlike other metadata, we store these two directly inside the value objects for the columns. values_list = lx.evalN("query commandservice command.argNames ? {%s}" % base_command) self.argName = values_list[arg_index] values_list = lx.evalN( "query commandservice command.argUsernames ? {%s}" % base_command) self.argUsername = "******" % (values_list[arg_index], self.argName) # These are the ones I care about for now. If there are others later, we can add them. query_terms = ['argTypes', 'argTypeNames', 'argDescs', 'argExamples'] # The list of query_terms is arbitrary. I'm just grabbing everything I think is important. for term in query_terms: # Remove the last character from the term to make it singular (argNames becomes argName) property_name = term[:-1] # Get the full list of values (for all args) # Note the use of `lx.evalN` as opposed to the normal `lx.eval`. We need to be certain # that we always receive a list in response, even if the list length is 1. values_list = lx.evalN('query commandservice command.%s ? {%s}' % (term, base_command)) # Run the query. setattr(self, property_name, values_list[arg_index])
cnt = cnt + 1 return vchain def vmunselect(): vmaps=lx.evalN("query layerservice vmaps ? selected") ctd={"weight":"wght","texture":"txuv","subvweight":"subd","morph":"morf","absmorpf":"spot","rgb":"rgb","rgba":"rgba","pick":"pick"} for vm in vmaps: name=lx.eval("query layerservice vmap.name ? %s" % vm) type=ctd[lx.eval("query layerservice vmap.type ? %s" % vm)] lx.eval("select.vertexMap \"%s\" %s remove" % (name,type)) mode = whichmode() edges = verts = None main = lx.eval("query layerservice layers ? main") if mode == "edge" : edges = lx.evalN("query layerservice edges ? selected") lx.eval("select.convert vertex") verts = lx.evalN("query layerservice uvs ? selected") elif mode == "vertex" : verts = lx.evalN("query layerservice uvs ? selected") lx.eval("select.convert edge") edges = lx.evalN("query layerservice edges ? selected") if edges != None : if lx.eval("query scriptsysservice userValue.isDefined ? uvaligner.divide") == 0 : lx.eval("user.defNew uvaligner.divide integer temporary") lx.eval("user.def uvaligner.divide username \"divide method\"") lx.eval("user.def uvaligner.divide list Uniform;Proportional;UVProportional") lx.eval("user.value uvaligner.divide") divide = lx.eval("user.value uvaligner.divide ?") selverts = optimize(verts) elist = edgelist(edges,selverts)
def getRenderOuptut(): """ Get a list of item IDs of type 'type' Returns a list of item IDs or None if there are no items of the specified tyep or if there's an error. Error printed is to Event log. type - the type of item to be returned (mesh, camera etc) """ global updateOnly global groupSelected global updateExistingOnly updateOnly = False try: """ #Si on fait seulement la mise a jour on recuoere tous les render existant ou ceux que lon a selectionner if (updateExistingOnly): RenderOutputsSelected = lx.evalN('query sceneservice selection ? renderOutput') RenderOutputs = [] if RenderOutputsSelected: for layer in RenderOutputsSelected: lx.out("UPDADE ONLY ",layer) RenderOutputs.append(lx.eval('query sceneservice item.ID ? %s' % layer)) return RenderOutputs # si on a rien selectionner on met a jour tous les éléments else: itemlist = [] numitems = lx.eval('!!query sceneservice renderOutput.N ?') if numitems == 0: return None else: for x in xrange(numitems): #typeLayer = lx.eval( "query sceneservice item.type ? %s" %(x) ) #if( typeLayer == "renderOutput" ) : idRender = lx.eval('query sceneservice renderOutput.ID ? %s' % (x)) itemlist.append(idRender) return itemlist """ #Est ce qu'on a selectionner des render Ouput RenderOutputsSelected = lx.evalN( 'query sceneservice selection ? renderOutput') RenderOutputs = [] if RenderOutputsSelected: for layer in RenderOutputsSelected: lx.out(layer) lx.out("le parent:" + lx.eval('query sceneservice item.parent ? %s' % layer)) RenderOutputs.append( lx.eval('query sceneservice item.ID ? %s' % layer)) updateOnly = True return RenderOutputs #Est ce qu'une selection de group exist ? selectionMask = lx.evalN('query sceneservice selection ? mask') masks = [] if selectionMask: layer = selectionMask[0] lx.out(layer) groupSelected = layer #lx.eval('query sceneservice item.name ? %s' % layer) nameGroup = lx.eval( 'query sceneservice item.name ? %s' % layer) + "_" nameGroup = nameGroup.replace(" (Material)", "") nameGroup = nameGroup.replace(" (Item)", "") lx.eval('user.value rom_prefixName %s' % (nameGroup)) #Has child output childRender = lx.evalN('query sceneservice item.children ? %s' % layer) lx.out(childRender) return childRender #Est ce qu'une selection de Render principal ? selectionMask = lx.evalN('query sceneservice selection ? polyRender') masks = [] if selectionMask: layer = selectionMask[0] lx.out(layer) groupSelected = layer #lx.eval('query sceneservice item.name ? %s' % layer) #Has child output childRender = lx.evalN('query sceneservice item.children ? %s' % layer) lx.out(childRender) return childRender # On peut cree seulement en selectionnant le poly render, un render output ou un mask itemlist = [] numitems = lx.eval('!!query sceneservice renderOutput.N ?') if numitems == 0: return None else: for x in xrange(numitems): #typeLayer = lx.eval( "query sceneservice item.type ? %s" %(x) ) #if( typeLayer == "renderOutput" ) : itemlist.append( lx.eval('query sceneservice renderOutput.ID ? %s' % (x))) return itemlist except: #exc_log() lx.out("ERROR getRenderOuptut") return None
edge_bounds = getBoundingBox((vec1,vec2),threshold) sample_points = [vec1] + lineSamples (vec1, vec2, SECTORS) + [vec2] for point in sample_points: edge_sectors.append(tuple(int(math.ceil(x/y)-1) for x,y in izip(vecSub(layer_bounds[1],point), sector_range))) edge_sectors = set(edge_sectors) for sectors in edge_sectors: sector_vertices.extend(sector_space[sectors[0]][sectors[1]][sectors[2]]) for vertex in sector_vertices: vec3 = lx.eval("query layerservice vert.pos ? " + str(vertex)) #Check the vertex against the bounds of the edge if (vec3 != vec1 and vec3 != vec2) and \ (vec3[0] > edge_bounds[0][0] and vec3[0] < edge_bounds[1][0]) and \ (vec3[1] > edge_bounds[0][1] and vec3[1] < edge_bounds[1][1]) and \ (vec3[2] > edge_bounds[0][2] and vec3[2] < edge_bounds[1][2]): vert_polys = set(lx.evalN("query layerservice vert.polyList ? " + str(vertex))) if not vert_polys: vert_polys = set([lx.eval1("query layerservice vert.polyList ? " + str(vertex))]) edge_polys = set(lx.evalN("query layerservice edge.polyList ? " + str(edge))) if not edge_polys: edge_polys = set([lx.eval1("query layerservice edge.polyList ? " + str(edge))]) if not edge_polys.intersection(vert_polys): timer2 = time.clock() distance = vecDistanceAxis((vec1,vec2),vec3) try: angle1 = vecAngle(vec1,vec2,vec1,vec3) except: angle1 = 0 try: angle2 = vecAngle(vec2,vec1,vec2,vec3)
if lx.eval("query scriptsysservice userValue.isDefined ? %(var)s" % vars()) == 0: lx.eval("user.defNew %(var)s %(type)s temporary" % vars()) if val != None: lx.eval("user.value %(var)s %(val)s" % vars()) if mes != None: lx.eval("user.def %(var)s username \"%(mes)s\"" % vars()) if lst != None: lx.eval("user.def %(var)s list %(lst)s" % vars()) if mes != None: lx.eval("user.value %(var)s" % vars()) return lx.eval("user.value %(var)s ?" % vars()) main = lx.eval("query layerservice layers ? main") verts = lx.evalN("query layerservice verts ? selected") if len(verts) >= 2: pos1 = lx.eval("query layerservice vert.pos ? " + verts[0]) pos2 = lx.eval("query layerservice vert.pos ? " + verts[1]) n = panel("makepointbydivide.n", None, "integer", "How many", None) if n > 0: dx = (pos2[0] - pos1[0]) / (n + 1) dy = (pos2[1] - pos1[1]) / (n + 1) dz = (pos2[2] - pos1[2]) / (n + 1) sx = pos1[0] + dx sy = pos1[1] + dy sz = pos1[2] + dz for i in range(n): lx.command("vert.new", x=sx, y=sy, z=sz) sx = sx + dx
def main(batchsize=None): lx.out("Headless Rendering Triggered") headless_path = lx.eval("query platformservice path.path ? headless") + "_cl" lx.eval("select.Item Render") first_frame = str(lx.eval("item.channel first ?")) last_frame = str(lx.eval("item.channel last ?")) frame_step = str(lx.eval("item.channel step ?")) save_selection = lx.evalN("query sceneservice selection ? all") filepath = bd_utils.filePath() filename = bd_utils.fileName().split(".") filename = filename[0] fullpath = lx.eval('query sceneservice scene.file ? current') groups = pyModo.Group_Name_All() passes = False pyModo.Render_Count_All() try: # set up the dialog lx.eval('dialog.setup yesNo') lx.eval('dialog.title {Confirm Operation}') lx.eval('dialog.msg {Try to query newer PathAliases?}') lx.eval('dialog.result ok') # Open the dialog and see which button was pressed lx.eval('dialog.open') lx.eval("dialog.result ?") pathaliases = bd_utils.pathAliases(ask=False) except: pathaliases = "" bd_utils.renderRegionCheck() for group in groups: if group == "passes": passes = True if passes: rendercmd = "render.animation {*} group:passes" else: rendercmd = "render.animation {*}" if filepath is False: lx.eval('layout.createOrClose EventLog "Event Log_layout" ' 'title:@macros.layouts@EventLog@ width:600 height:600 persistent:true ' 'open:true') lx.out("ERROR Please save scene first.") else: wd_regex = re.compile("/Volumes/ProjectsRaid/WorkingProjects/[^/]*/[^/]*/") workingdirectory = wd_regex.match(filepath).group() batchdir = workingdirectory + "work/modo/05_render/_batch/" bd_utils.makes_path(batchdir) shellfile = batchdir + filename + "_batchrender.sh" s = open(shellfile, 'w') s.write("""#!/usr/bin/env bash source """ + mail_config_path + """ SUBJECT="modo render completed" MACHINE=$(hostname -s) START=$(date +%s) STARTDATE=$(date -j -f "%s" "`date +%s`" "+%A, %d.%m.%Y %T") FRAMES=$((""" + last_frame + """-""" + first_frame + """+1)) """) filesdir = workingdirectory + "work/modo/05_render/_batch/" + filename + "/" bd_utils.makes_path(filesdir) if batchsize: framelist = range(int(first_frame), int(last_frame) + 1, int(frame_step)) framelist = chunker(framelist, batchsize) for framegroup in framelist: first_frame = str(min(int(minframe) for minframe in framegroup)) last_frame = str(max(int(maxframe) for maxframe in framegroup)) batchfile = filesdir + filename + \ "_batchrender_frames_" + first_frame + "-" + last_frame \ + ".txt" lx.out("Saving renderbatch at: " + batchfile) template = """log.toConsole true log.toConsoleRolling true""" for alias, path in pathaliases.iteritems(): template = template + """ pathalias.create """ + alias + " \"" + path + "\"" template = template + """ scene.open """ + fullpath + """ pref.value render.threads auto select.Item Render item.channel step """ + frame_step + """ item.channel first """ + first_frame + """ item.channel last """ + last_frame + """ """ + rendercmd + """ scene.close app.quit """ f = open(batchfile, 'w') f.write(template) f.close() s.write(headless_path + " < " + batchfile + "\n") else: batchfile = filesdir + filename + \ "_batchrender_frames_" + first_frame + "-" + last_frame \ + ".txt" lx.out("Saving renderbatch at: " + batchfile) template = """log.toConsole true log.toConsoleRolling true""" if pathaliases is not "": for alias, path in pathaliases.iteritems(): template = template + """ pathalias.create """ + alias + " \"" + path + "\"" template = template + """ scene.open """ + fullpath + """ pref.value render.threads auto select.Item Render item.channel step """ + frame_step + """ item.channel first """ + first_frame + """ item.channel last """ + last_frame + """ """ + rendercmd + """ scene.close app.quit """ f = open(batchfile, 'w') f.write(template) f.close() s.write(headless_path + " < " + batchfile + "\n") s.write(""" END=$(date +%s) ENDDATE=$(date -j -f "%s" "`date +%s`" "+%A, %d.%m.%Y %T") secs=$((END-START)) perframe=$(($secs/$FRAMES)) DURATION=$(printf '%dh:%02dm:%02ds' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60))) DURATIONPERFRAME=$(printf '%dh:%02dm:%02ds' $(($perframe/3600)) $(($perframe%3600/60)) $(($perframe%60))) BODY="${MACHINE} just finished rendering """ + filename + """. It started at ${STARTDATE}""" + """ and ended at ${ENDDATE} taking ${DURATION} overall for ${FRAMES} frames. That's ${DURATIONPERFRAME} per frame on average." echo " ##### " echo $BODY echo " ##### " sendemail -f ${FROM_ADDRESS} -t ${TO_ADDRESS} -m ${BODY} -u ${SUBJECT} -s ${SERVER} -xu ${USER} -xp ${PASS}""") s.close() os.chmod(shellfile, 0755) pyperclip.copy(shellfile) subprocess.Popen(['open', '-a', '/Applications/Utilities/Terminal.app', '-n']) bd_utils.restoreSelection(save_selection)
break if not find: return None loopedge.remove(e) p = set(lx.evalN("query layerservice edge.polyList ? %s" % e)) if len(p.intersection(plist)) != 0: return None else: return e mode = whichmode() if mode == "edge": result = [] main = lx.eval("query layerservice layers ? main") edges = [(v.strip("()").split(",")) for v in lx.evalN("query layerservice selection ? edge")] seledge = [] for e in edges: if int(e[1]) < int(e[2]): seledge.append("(%s,%s)" % (e[1], e[2])) else: seledge.append("(%s,%s)" % (e[2], e[1])) if len(seledge) != 0: seededge = seledge[-1] plist = set( lx.evalN("query layerservice edge.polyList ? %s" % seededge)) lx.eval("select.drop edge") vid = seededge.strip("()").split(",") lx.command("select.element", layer=main, type="edge",
#python import lx import sys def SetValue(args): if "value" not in args: args["value"] = "" lx.eval("channel.value " + args["value"] + " channel:{" + item + ":" + args["name"] +"}") args = lx.args() args = dict(map(str.strip, arg.split(':', 1)) for arg in args) items = lx.evalN("query sceneservice selection ? " + args["itemtype"]) if items == None: sys.exit("LXe_SUCCESS") for item in items: lx.eval("query sceneservice item.name ? " + item) # check if the channel already exists for i in range(lx.eval("query sceneservice channel.N ?")): if lx.eval("query sceneservice channel.name ? " + str(i)) == args["name"]: if "action" in args and args["action"] == "delete": lx.eval("channel.delete") else: SetValue(args) sys.exit("LXe_SUCCESS")
def process_items(self): self.begining_log() if not self.exportFile_sw: # Transform Selected if self.userSelectionCount == 0: # No file Selected self.init_message('error', 'No item selected', 'Select at least one item') sys.exit() self.transform_loop() self.scn.select(self.userSelection) elif not self.scanFiles_sw: # export selected mesh if self.userSelectionCount == 0: # No file Selected self.init_message('error', 'No item selected', 'Select at least one item') sys.exit() if self.exportEach_sw: self.init_dialog("output") else: self.init_dialog("file_save") try: # output folder dialog lx.eval('dialog.open') except: self.init_dialog('cancel') else: output_dir = lx.eval1('dialog.result ?') self.batch_export(output_dir) else: # browse file to process self.init_dialog("input") try: # mesh to process dialog lx.eval('dialog.open') except: self.init_dialog('cancel') else: files = lx.evalN('dialog.result ?') self.init_dialog("output") try: # output folder dialog lx.eval('dialog.open') except: self.init_dialog('cancel') else: output_dir = lx.eval1('dialog.result ?') for f in files: self.processing_log('..................................... ' + os.path.basename(f) + ' .....................................') lx.eval('!scene.open "%s" normal' % f) # if ext == 'fbx' lx.eval('select.itemType mesh') scnIndex = lx.eval('query sceneservice scene.index ? current') self.userSelection = self.scn.selected self.userSelectionCount = len(self.userSelection) self.print_log('..................................... ' + str(self.userSelectionCount) + ' mesh item founded .....................................') self.batch_export(output_dir) lx.eval('!scene.close') self.init_message('info', 'Done', 'Operation completed successfully !') if self.exportFile_sw: if self.openDestFolder_sw: if self.scanFiles_sw: self.open_folder(output_dir) if self.exportEach_sw: self.open_folder(output_dir) else: self.open_folder(os.path.split(output_dir)[0]) self.ending_log()
"absmorpf": "spot", "rgb": "rgb", "rgba": "rgba", "pick": "pick" } for vm in vmaps: name = lx.eval("query layerservice vmap.name ? %s" % vm) type = ctd[lx.eval("query layerservice vmap.type ? %s" % vm)] lx.eval("select.vertexMap \"%s\" %s remove" % (name, type)) mode = whichmode() edges = verts = None main = lx.eval("query layerservice layers ? main") if mode == "edge": edges = lx.evalN("query layerservice edges ? selected") lx.eval("select.convert vertex") verts = lx.evalN("query layerservice uvs ? selected") elif mode == "vertex": verts = lx.evalN("query layerservice uvs ? selected") lx.eval("select.convert edge") edges = lx.evalN("query layerservice edges ? selected") if edges != None: if lx.eval("query scriptsysservice userValue.isDefined ? uvaligner.divide" ) == 0: lx.eval("user.defNew uvaligner.divide integer temporary") lx.eval("user.def uvaligner.divide username \"divide method\"") lx.eval( "user.def uvaligner.divide list Uniform;Proportional;UVProportional") lx.eval("user.value uvaligner.divide") divide = lx.eval("user.value uvaligner.divide ?")
lx.eval("dialog.setup error") lx.eval("dialog.title \"%s\"" % titleString) lx.eval("dialog.msg \"%s\"" % errorString) lx.eval("dialog.open") selmode = lx.eval("query layerservice selmode ?") mainlayer = lx.eval("query layerservice layers ? main") if selmode != "edge": lx.eval("poly.spinQuads") sys.exit("LXe_SUCCESS") else: polys = [] selected_polys = lx.evalN("query layerservice polys ? selected") edges = lx.evalN("query layerservice edges ? selected") for edge in edges: if lx.eval("query layerservice edge.numPolys ? " + str(edge)) == 2: polys.append( lx.evalN("query layerservice edge.polyList ? " + str(edge))) if not polys: sys.exit("LXe_SUCCESS") for poly in polys: lx.eval("select.drop polygon") lx.eval("select.element " + str(mainlayer) + " polygon add " + str(poly[0])) lx.eval("select.element " + str(mainlayer) + " polygon add " + str(poly[1])) lx.eval("poly.spinQuads") lx.eval("select.drop polygon")
def partTwoMain(mesh, camera): lx.eval('view3d.projection psp') lx.eval('select.item %s add' % mesh) lx.eval('center.bbox center') lx.eval('select.less') lx.eval('item.parent %s %s inPlace:1' % (mesh, camera)) lx.eval('select.item %s add' % camera) lx.eval('transform.channel rot.X 0.0') lx.eval('transform.channel rot.Y 0.0') lx.eval('transform.channel rot.Z 0.0') lx.eval('select.item %s add' % mesh) lx.eval('transform.channel pos.X 0.0') lx.eval('transform.channel pos.Y 0.0') lx.eval('transform.channel pos.Z 0.0') lx.eval('select.convert vertex') lx.eval('select.vertex add 0 0') vert_index = lx.evalN('query layerservice verts ? selected') vert_posX = [] vert_posY = [] vert_posZ = [] for element in vert_index: vert_pos_single = lx.eval('query layerservice vert.wpos ? ' + str(element)) if not vert_pos_single[0] in vert_posX: vert_posX.append(vert_pos_single[0]) if not vert_pos_single[1] in vert_posY: vert_posY.append(vert_pos_single[1]) if not vert_pos_single[2] in vert_posZ: vert_posZ.append(vert_pos_single[2]) vert_posX.sort() vert_posY.sort() vert_posZ.sort() if vert_posX[-1] > abs(vert_posX[0]): vert_posX = vert_posX[-1] else: vert_posX = abs(vert_posX[0]) if vert_posY[-1] > abs(vert_posY[0]): vert_posY = vert_posY[-1] else: vert_posY = abs(vert_posY[0]) if vert_posZ[-1] > abs(vert_posZ[0]): vert_posZ = vert_posZ[-1] else: vert_posZ = abs(vert_posZ[0]) if vert_posX > vert_posY and vert_posX > vert_posZ: axisBig = vert_posX elif vert_posY > vert_posZ: axisBig = vert_posY else: axisBig = vert_posZ print axisBig lx.eval('select.typeFrom item;pivot;center;edge;polygon;vertex;ptag true') lx.eval('transform.channel scl.X %s' % (10/axisBig)) lx.eval('transform.channel scl.Y %s' % (10/axisBig)) lx.eval('transform.channel scl.Z %s' % (10/axisBig))
# To give a custom size to all channels in a selected Locators, # no matter the kind of Locators and if there are some channels greyed # # www.etereaestudios.com import lx try: scene_svc = lx.Service("sceneservice") # Define my argument: mysize = float(lx.args()[0]) # get selected layers selected_layers = lx.evalN("query sceneservice selection ? all") # drop selection so that we can work on one item at a time lx.eval("select.drop item") # create empty list to put locators in locators = [] for item in selected_layers: # select layer scene_svc.select("item", str(item)) lx.eval('select.item {%s} set' % item) # get item type itemType = scene_svc.query("item.type")
group_locator_dict = construct_item_dict(group_locator) mesh_item_dict = construct_item_dict(mesh_item) path = r'C:\Users\lboucher\Documents\3dsMax\export\NewBodyPose' if len(group_locator): # at least one group locator or mesh item item selected init_dialog("input", path, 'fbx') try: # mesh to process dialog lx.eval('dialog.open') except: # if cancel button pressed init_dialog('cancel', path) else: # process selected mesh files = lx.evalN('dialog.result ?') for f in files: filename = os.path.splitext(os.path.basename(f))[0] if filename in group_locator_name: # the filename have a groupLocator selected with the same name lx.eval('!!scene.open "{}" import'.format(f)) print_log('Importing {}'.format(filename)) imported_scene_root = modo.Item(filename + '_2') imported_items = get_child_of_type(imported_scene_root, 'mesh') source_items = get_child_of_type(group_locator_dict[filename], 'mesh') for imported_item in imported_items: matching_source_item = get_matching_item(source_items, imported_item, skipped_item_dict) if matching_source_item is not None:
loopedge.remove(e) break if not term: which.append(seqv) if len(which) == 2: if len(which[0]) < len(which[1]): return which[0] else: return which[1] else: return which[0] mon = lx.Monitor() main = lx.eval("query layerservice layers ? main") pseledges = lx.evalN("query layerservice edges ? selected") lx.eval("select.convert vertex") everts = list(lx.evalN("query layerservice verts ? selected")) selverts = set(everts * 1) lx.eval("select.drop edge") lx.eval("select.drop vertex") vs = lx.evalN("query layerservice vert.vertList ? %s" % everts[0]) for v in vs: if str(v) in selverts: lx.eval("select.type edge") lx.command("select.element", layer=main, type="edge", mode="set", index=int(everts[0]), index2=int(v))
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))
#python import lx def selectConectedUV(): lx.eval('!!select.3DElementUnderMouse set') lx.eval('ffr.selectconnecteduv') selType = lx.eval1('query layerservice selmode ?') if selType == 'polygon': p_hover = lx.eval1('query view3dservice element.over ? poly') p_sel = lx.evalN('query layerservice uv ? selected') if isinstance(p_hover, str): selectConectedUV() else: if len(p_sel)>0: lx.eval('ffr.selectconnecteduv') else: lx.eval('select.all') elif selType == 'edge': lx.eval('select.type polygon') e_hover = lx.eval1('query view3dservice element.over ? poly') if isinstance(e_hover, str): selectConectedUV() else: lx.eval('select.all') elif selType == 'vertex': lx.eval('select.type polygon')
def basic_Execute(self, msg, flags): #The command will be enabled if at least 1 vert is selected. vertcount = lx.eval('select.count vertex ?') lx.out('vertcount', vertcount) #If no verts are selected display this dialog and exit command if vertcount <= 0: lx.eval('dialog.setup info') lx.eval('dialog.title {PP Locator Drop:}') lx.eval( 'dialog.msg {You must have at least one vertex selected to run this script.}' ) lx.eval('+dialog.open') return #reads the user values from the arguments locator = self.dyna_String(0) shape = self.dyna_String(1) label = self.dyna_String(2) solid = self.dyna_String(3) align = self.dyna_String(4) axis = self.dyna_String(5) sizeX = self.dyna_Float(6) sizeY = self.dyna_Float(7) sizeZ = self.dyna_Float(8) radius = self.dyna_Float(9) wcolor = self.dyna_String(10) fcolor = self.dyna_String(11) lx.out('locator name', locator) lx.out('shape', shape) lx.out('label', label) lx.out('solid', solid) lx.out('align', align) lx.out('axis', axis) lx.out('x', sizeX) lx.out('y', sizeX) lx.out('z', sizeX) lx.out('radius', radius) lx.out('wireframe color', wcolor) lx.out('fill color', fcolor) try: #All my regular code #pass layer = lx.eval('query layerservice layer.index ? main') verts = lx.evalN( 'query layerservice verts ? selected') # index of verts vertsN = lx.eval( 'query layerservice vert.N ? selected') #vert count lx.out('verts', verts) lx.out('vertsN', vertsN) #Now that the user set the values, we can just query it lx.out('text', locator) lx.out('type', shape) num = 1 #for each vert create a locator and move the locator to the vert position for v in verts: #store vert position vertpos = lx.eval('query layerservice vert.pos ? %s' % v) vertPOS_X, vertPOS_Y, vertPOS_Z = vertpos #create locator and rename it to user input layer = lx.eval('item.create locator') layer = lx.eval('!!item.name %s_%s locator' % (locator, num)) num += +1 #move locator layer = lx.eval('transform.channel pos.Z %f' % vertPOS_Z) layer = lx.eval('transform.channel pos.Y %f' % vertPOS_Y) layer = lx.eval('transform.channel pos.X %f' % vertPOS_X) if shape == "standard": lx.eval('item.channel locator$size %f' % sizeX) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "box": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) lx.eval('item.channel locator$isSize.X %f' % sizeX) lx.eval('item.channel locator$isSize.Y %f' % sizeY) lx.eval('item.channel locator$isSize.Z %f' % sizeZ) #lx.eval('item.channel locator$isRadius %f' %radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "pyramid": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) lx.eval('item.channel locator$isSize.X %f' % sizeX) lx.eval('item.channel locator$isSize.Y %f' % sizeY) lx.eval('item.channel locator$isSize.Z %f' % sizeZ) #lx.eval('item.channel locator$isRadius %f' %radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "rhombus": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) lx.eval('item.channel locator$isSize.X %f' % sizeX) lx.eval('item.channel locator$isSize.Y %f' % sizeY) lx.eval('item.channel locator$isSize.Z %f' % sizeZ) #lx.eval('item.channel locator$isRadius %f' %radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "cylinder": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) if axis == 'x': lx.eval('item.channel locator$isSize.X %f' % sizeX) elif axis == 'y': lx.eval('item.channel locator$isSize.Y %f' % sizeY) else: lx.eval('item.channel locator$isSize.Z %f' % sizeZ) lx.eval('item.channel locator$isRadius %f' % radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "cone": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) if axis == 'x': lx.eval('item.channel locator$isSize.X %f' % sizeX) elif axis == 'y': lx.eval('item.channel locator$isSize.Y %f' % sizeY) else: lx.eval('item.channel locator$isSize.Z %f' % sizeZ) lx.eval('item.channel locator$isRadius %f' % radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "sphere": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) lx.eval('item.channel locator$isRadius %f' % radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "plane": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) if axis == 'x': lx.eval('item.channel locator$isSize.Y %f' % sizeY) lx.eval('item.channel locator$isSize.Z %f' % sizeZ) elif axis == 'y': lx.eval('item.channel locator$isSize.X %f' % sizeX) lx.eval('item.channel locator$isSize.Z %f' % sizeZ) else: lx.eval('item.channel locator$isSize.X %f' % sizeX) lx.eval('item.channel locator$isSize.Y %f' % sizeY) #lx.eval('item.channel locator$isRadius %f' %radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') elif shape == "circle": #customize locator lx.eval('item.channel locator$drawShape custom') lx.eval('item.channel locator$isStyle replace') lx.eval('item.channel locator$isShape %s' % shape) lx.eval('item.help add label "%s"' % label) lx.eval('item.channel locator$isSolid %s' % solid) lx.eval('item.channel locator$isAlign %s' % align) lx.eval('item.channel locator$isAxis %s' % axis) lx.eval('item.channel locator$isRadius %f' % radius) lx.eval('item.draw add locator') lx.eval('item.channel locator$wireOptions user') lx.eval('item.channel locator$wireColor {%s}' % wcolor) lx.eval('item.channel locator$fillOptions user') lx.eval('item.channel locator$fillColor {%s}' % fcolor) #switch back to vert mode for next vert in list lx.eval('select.typeFrom vertex') except: lx.out(traceback.format_exc())
# To give a custom size to all channels in a selected Locators, # no matter the kind of Locators and if there are some channels greyed # # www.etereaestudios.com import lx try: scene_svc = lx.Service("sceneservice") # Define my argument: mysize = float(lx.args()[0]) # get selected layers selected_layers = lx.evalN("query sceneservice selection ? all") # drop selection so that we can work on one item at a time lx.eval("select.drop item") # create empty list to put locators in locators = [] for item in selected_layers: # select layer scene_svc.select("item",str(item)) lx.eval('select.item {%s} set' % item) # get item type itemType = scene_svc.query("item.type")
# ------------------------------------------------------------------------------- # IF COMPONENTS ARE SELECTED (verts, edges or polys) # ------------------------------------------------------------------------------- if mySelMode in components: # Force to select your Mesh in the Item List, for when components are selected # although some other Item is highlighted on ItemList (a very common issue) myMeshID = lx.eval('query layerservice layer.id ? %s' % myCurrentLayerID) lx.eval('select.subItem %s set mesh;locator' % myMeshID) myMeshName = lx.eval('query sceneservice selection ? mesh') # Query Bounding Box of selected components using external script 'calculate_bbox.py' by James O'Hare aka Farfarer # http://community.thefoundry.co.uk/discussion/post.aspx?f=119&t=93824&p=839842 boundBox = lx.evalN( 'ffr.getbbox ? world' ) # Get world space boundBox as (+X, +Y, +Z, -X, -Y, -Z) # Calculate average (arithmetic mean) of resulting coords to get the Center for that Bounding Box # http://stackoverflow.com/questions/7716331/calculating-arithmetic-mean-average-in-python def average(numbers): return float(sum(numbers)) / max(len(numbers), 1) avgX = average([boundBox[0], boundBox[3]]) avgY = average([boundBox[1], boundBox[4]]) avgZ = average([boundBox[2], boundBox[5]]) averagePos = ( avgX, avgY, avgZ ) # This is the average/center position for selected components
lx.out("INIT RENDER OUTPUT MANAGER") if arg == 'loadPreset': lx.out("LOADING PRESET") loadPreset() if arg == 'savePreset': lx.out("SAVING PRESET") savePreset() #recupere la liste des layer actif "renderOutput" if arg == 'getRender': #On sauve la selection active_scene = lx.eval("query sceneservice scene.name ? current") OSF_saveSelection = lx.evalN("query sceneservice selection ? all") #on eteint tous les flag numList = len(listName) i = 0 while (i < numList): nameFlag = "rom_" + listName[i] + "Flag" lx.eval('user.value %s {}' % nameFlag) i = i + 1 #on recupere la liste de tous les layer actif existingRenderOutput = getRenderOuptut() #on regarde chaque layer si il existe on active le boutton correspondant num = len(existingRenderOutput) first = True if (num):
#python import lx def selectConectedUV(): lx.eval('!!select.3DElementUnderMouse set') lx.eval('select.polygonConnect m3d false') selType = lx.eval1('query layerservice selmode ?') if selType == 'polygon': p_hover = lx.eval1('query view3dservice element.over ? poly') p_sel = lx.evalN('query layerservice polys ? selected') if isinstance(p_hover, str): selectConectedUV() else: if len(p_sel) > 0: lx.eval('select.polygonConnect m3d false') else: lx.eval('select.all') elif selType == 'edge': lx.eval('select.type polygon') e_hover = lx.eval1('query view3dservice element.over ? poly') if isinstance(e_hover, str): selectConectedUV() else: lx.eval('select.all')
def main(): lx.eval("user.defNew gl_viewport_size integer momentary") lx.eval('user.def gl_viewport_size username "Open New GL View"') lx.eval('user.def gl_viewport_size dialogname "Which resolution do you need to open?"') lx.eval("user.def gl_viewport_size list Full;Half;Quarter;Tenth") lx.eval('user.def gl_viewport_size listnames "100%;50%;25%;10%"') lx.eval("user.value gl_viewport_size") mode = lx.eval("user.value gl_viewport_size ?") if mode == "Full": percent = 1.0 elif mode == "Half": percent = 0.5 elif mode == "Quarter": percent = 0.25 elif mode == "Tenth": percent = 0.1 else: percent = 1 lx.eval("user.defNew gl_type integer momentary") lx.eval('user.def gl_type username "GL Recording Type"') lx.eval('user.def gl_type dialogname "Do you want to capture a movie or an image sequence?"') lx.eval("user.def gl_type list movie;image") lx.eval('user.def gl_type listnames "Movie;Image Sequence"') lx.eval("user.value gl_type") gl_type = lx.eval("user.value gl_type ?") all_cameras = get_ids("camera") render_camera = lx.eval("render.camera ?") list=str(render_camera) + ";" listnames="Render Camera;" for x in all_cameras: list += x + ";" listnames += lx.eval('query sceneservice item.name ? %s' % x) + ";" lx.out(list) lx.out(listnames) lx.eval("user.defNew viewport_cam integer momentary") lx.eval('user.def viewport_cam username "Pick Viewport Camera"') lx.eval('user.def viewport_cam dialogname "Which camera do you want to capture?"') lx.eval("user.def viewport_cam list " + list) lx.eval('user.def viewport_cam listnames "' + listnames + '"') lx.eval("user.value viewport_cam") capture_camera = lx.eval("user.value viewport_cam ?") capture_camera_name = lx.eval('query sceneservice item.name ? %s' % capture_camera) lx.out(capture_camera) lx.out(capture_camera_name) lx.eval("user.defNew shading_style integer momentary") lx.eval('user.def shading_style username "Pick Viewport Shading"') lx.eval('user.def shading_style dialogname "Which Shading Style do you want?"') lx.eval("user.def shading_style list gnzgl;advgl;texmod;tex;shade;vmap;sket;wire;shd1;shd2;shd3") lx.eval('user.def shading_style listnames "Advanced;Default;Texture Shaded;Texture;Shaded;Vertex Map;Solid;Wireframe;Gooch Toon Shading;Cel Shading;Reflection"') lx.eval("user.value shading_style") shading_style = lx.eval("user.value shading_style ?") # Get selection save_selection = lx.evalN("query sceneservice selection ? all") # Get Render Resolution lx.eval("select.item Render") resX = float(lx.eval("item.channel resX ?")) resY = float(lx.eval("item.channel resY ?")) newResX = int(resX * percent) newResY = int(resY * percent) # Restore selection restoreSelection(save_selection) lx.eval('layout.create %s width:%s height:%s style:palette' % (capture_camera_name, newResX, newResY)) lx.eval('viewport.restore base.3DSceneView false 3Dmodel') lx.eval('view3d.bgEnvironment background solid') lx.eval('view3d.showGrid false') lx.eval('view3d.projection cam') lx.eval('view3d.controls false') lx.eval('view3d.showLights false') lx.eval('view3d.showCameras false') lx.eval('view3d.showLocators false') lx.eval('view3d.showTextureLocators false') lx.eval('view3d.showBackdrop false') lx.eval('view3d.showSelections false') lx.eval('view3d.fillSelected false') lx.eval('view3d.outlineSelected false') lx.eval('view3d.showSelectionRollover false') lx.eval('view3d.shadingStyle ' + shading_style + ' active') lx.eval('view3d.wireframeOverlay none active') lx.eval('view3d.cameraItem ' + capture_camera) lx.eval('view3d.shadingStyle ' + shading_style) lx.eval('view3d.sameAsActive true') if shading_style == "gnzgl": lx.eval("view3d.showGnzFSAA x9") lx.eval("view3d.setGnzTransparency correct") lx.eval("view3d.setGnzSSReflections blurry") lx.eval("view3d.setGnzDitherMode ordered") lx.eval("view3d.showGnzSSAO true") lx.eval("view3d.GnzVisOverride all") lx.eval("view3d.showGnzShadows true") lx.eval("view3d.useGnzNormalMaps true") lx.eval("view3d.useGnzBumpMaps true") lx.eval("view3d.setGnzVisibility render") lx.eval("view3d.setGnzLighting sceneIBLLights") lx.eval("view3d.setGnzBackground environment") if gl_type == "movie": lx.eval("gl.capture") if gl_type == "image": lx.eval("gl.capture seq:true") lx.eval("layout.closeWindow")
def main(): lx.eval("user.defNew overscan_mode integer momentary") lx.eval('user.def overscan_mode username "Overscan Mode"') lx.eval('user.def overscan_mode dialogname "Which overscan mode do you want to use?"') lx.eval("user.def overscan_mode list resolution;scaling") lx.eval("user.value overscan_mode") mode = lx.eval("user.value overscan_mode ?") lx.out(mode) # Get selection save_selection = lx.evalN("query sceneservice selection ? all") # Get Render Camera render_camera = lx.eval("render.camera ?") lx.eval("select.item {%s} set" % render_camera) # Get Film Back apertureX = lx.eval("item.channel apertureX ?") apertureY = lx.eval("item.channel apertureY ?") # Get Render Resolution lx.eval("select.item Render") resX = float(lx.eval("item.channel resX ?")) resY = float(lx.eval("item.channel resY ?")) if mode == "resolution": # Ask for new resolution lx.eval("user.defNew newRes.X integer momentary") lx.eval("user.value newRes.X") newResX = lx.eval("user.value newRes.X ?") lx.eval("user.defNew newRes.Y integer momentary") lx.eval("user.value newRes.Y") newResY = lx.eval("user.value newRes.Y ?") elif mode == "scaling": # Ask for scaling factor lx.eval("user.defNew newRes.scaling float momentary") lx.eval("user.value newRes.scaling") newResScaling = lx.eval("user.value newRes.scaling ?") newResX = resX * newResScaling newResY = resY * newResScaling # Apply Overscan formula to width and height newApertureX = apertureX * (newResX / resX) newApertureY = apertureY * (newResY / resY) # Fill in new render resolution lx.eval("render.res 0 %s" % newResX) lx.eval("render.res 1 %s" % newResY) # Fill in new film back lx.eval("select.item {%s} set" % render_camera) lx.eval("item.channel apertureX %s" % newApertureX) lx.eval("item.channel apertureY %s" % newApertureY) # Restore selection restoreSelection(save_selection)
a[6] * b[1] + a[7] * b[4] + a[8] * b[7], a[6] * b[2] + a[7] * b[5] + a[8] * b[8] ] if lx.eval( "query scriptsysservice userValue.isDefined ? circle3p.divide") == 0: lx.eval("user.defNew circle3p.divide integer temporary") lx.eval("user.def circle3p.divide username \"side\"") lx.eval("user.value circle3p.divide 36") lx.eval("user.value circle3p.divide") divide = lx.eval("user.value circle3p.divide ?") redundancy = 0.00001 lx.eval("select.type vertex") main = lx.eval("query layerservice layers ? main") verts = [int(v) for v in lx.evalN("query layerservice verts ? selected")] spos = set() for v in verts: spos.add(lx.eval("query layerservice vert.pos ? %s" % v)) pos = list(spos) if len(pos) >= 3: pos1 = pos[0] pos2 = pos[1] pos3 = pos[2] normal = outer(vector(pos2, pos1), vector(pos3, pos1)) v1 = crossplanes(normal, [pos2[0] - pos1[0], pos2[1] - pos1[1], pos2[2] - pos1[2]]) p1 = [(pos1[0] + pos2[0]) / 2.0, (pos1[1] + pos2[1]) / 2.0, (pos1[2] + pos2[2]) / 2.0] v2 = crossplanes(normal, [pos3[0] - pos1[0], pos3[1] - pos1[1], pos3[2] - pos1[2]])
#python import lx def selectConectedUV(): lx.eval('!!select.3DElementUnderMouse set') lx.eval('select.polygonConnect m3d false') selType = lx.eval1('query layerservice selmode ?') if selType == 'polygon': p_hover = lx.eval1('query view3dservice element.over ? poly') p_sel = lx.evalN('query layerservice polys ? selected') if isinstance(p_hover, str): selectConectedUV() else: if len(p_sel)>0: lx.eval('select.polygonConnect m3d false') else: lx.eval('select.all') elif selType == 'edge': lx.eval('select.type polygon') e_hover = lx.eval1('query view3dservice element.over ? poly') if isinstance(e_hover, str): selectConectedUV() else: lx.eval('select.all') elif selType == 'vertex': lx.eval('select.type polygon')
# ------------------------------------------------------------------------------- # IF COMPONENTS ARE SELECTED (verts, edges or polys) # ------------------------------------------------------------------------------- if mySelMode in components: # Force to select your Mesh in the Item List, for when components are selected # although some other Item is highlighted on ItemList (a very common issue) myMeshID = lx.eval('query layerservice layer.id ? %s' % myCurrentLayerID) lx.eval('select.subItem %s set mesh;locator' % myMeshID) myMeshName = lx.eval('query sceneservice selection ? mesh') # Query Bounding Box of selected components using external script 'calculate_bbox.py' by James O'Hare aka Farfarer # http://community.thefoundry.co.uk/discussion/post.aspx?f=119&t=93824&p=839842 boundBox = lx.evalN('ffr.getbbox ? world') # Get world space boundBox as (+X, +Y, +Z, -X, -Y, -Z) # Calculate average (arithmetic mean) of resulting coords to get the Center for that Bounding Box # http://stackoverflow.com/questions/7716331/calculating-arithmetic-mean-average-in-python def average(numbers): return float(sum(numbers)) / max(len(numbers), 1) avgX = average([boundBox[0], boundBox[3]]) avgY = average([boundBox[1], boundBox[4]]) avgZ = average([boundBox[2], boundBox[5]]) averagePos = (avgX, avgY, avgZ) # This is the average/center position for selected components # Create a locator, size 0 lx.eval('item.create locator')
#python import lx selectedGroups = lx.evalN('query sceneservice selection ? groupLocator') def scalePos(axis): try: getPos=lx.eval("item.channel pos.%s ?" %(axis)) lx.out(getPos) scaledPos=getPos/100 lx.eval("transform.channel pos.%s %s" %( axis, scaledPos)) except: lx.eval("transform.channel pos.%s 0" %(axis)) for i in selectedGroups: lx.eval('select.item {%s} set' % i) axis=str("X") scalePos(axis) axis=str("Y") scalePos(axis) axis=str("Z") scalePos(axis)
import lx import copy itemNum = lx.eval("query sceneservice item.N ? ") itemNumList = range(0, itemNum) itemList = {} for item in itemNumList: itemID = lx.eval("query sceneservice item.id ? %s" % item) itemName = lx.eval("query sceneservice item.name ? %s" % item) itemList[item] = itemID + ' ' + itemName #itemList.append(itemID); lx.out(itemList) selItems = lx.evalN("query sceneservice selection ? all") lis = list(selItems) #tuple to list conversion lx.out(selItems) #tuple lx.out(lis) #list cha = [] for item in lis: lx.eval("select.subitem %s add mesh 1 1" % item) newSel = lx.eval("query sceneservice selection ? all") for element in newSel: if element not in cha: cha.append(element) chaName = []
def batch_files(self): self.currPath = file.getLatestPath(t.config_browse_src_path) dialog.init_dialog("input", self.currPath) try: # mesh to process dialog lx.eval('dialog.open') except: dialog.init_dialog('cancel', self.currPath) else: files = lx.evalN('dialog.result ?') file.updateExportPath('', os.path.split(files[0])[0], '') self.currPath = file.getLatestPath(t.config_browse_dest_path) dialog.init_dialog("output", self.currPath) try: # output folder dialog lx.eval('dialog.open') except: dialog.init_dialog('cancel', self.currPath) else: output_dir = lx.eval1('dialog.result ?') file.updateExportPath('', '', output_dir) file_count = len(files) self.progress = dialog.init_progress_bar( file_count, 'Exporting files...') self.progression[1] = file_count self.progression[0] = 0 t.set_import_setting() for f in files: dialog.processing_log( '..................................... ' + os.path.basename(f) + ' .....................................') lx.eval('!scene.open "%s" normal' % f) self.scnIndex = lx.eval( 'query sceneservice scene.index ? current') helper.select_compatible_item_type() self.userSelection = self.scn.selected self.userSelectionCount = len(self.userSelection) dialog.print_log( '..................................... ' + str(self.userSelectionCount) + ' mesh item founded .....................................' ) if self.at_least_one_item_selected(exit=False): lx.eval('!scene.close') continue self.filename = os.path.splitext(os.path.basename(f))[0] self.batch_process(output_dir, self.filename) dialog.increment_progress_bar(self, self.progress[0], self.progression) helper.revert_initial_parameter(self) lx.eval('!scene.close') helper.reset_import_settings(self) dialog.init_message( 'info', 'Done', 'Operation completed successfully ! %s file(s) exported' % self.exportedFileCount) helper.open_destination_folder(self, output_dir) dialog.ending_log(self)
# --------------------------------- lx.eval("item.matchWorkplanePos") scene_svc = lx.Service("sceneservice") layer_svc = lx.Service("layerservice") allowed_modes = ('polygon', 'edge', 'vertex') # Query Mode (For the IF item) FirstCheckModoMode = lx.eval('query layerservice selmode ?') itemtypes = ("locator", "light", "sunLight", "camera", "mesh") # Selected layers selMesh = lx.evalN("query sceneservice selection ? all") lx.out(FirstCheckModoMode) # If no layer and no component selected if len(selMesh) == 0 and not FirstCheckModoMode == 'item': lx.out("no component") locator_at_zero() # Check if current selection mode is a component mode if FirstCheckModoMode in allowed_modes: lx.out("component mode") for item in selMesh:
lx.out("INIT RENDER OUTPUT MANAGER") if arg == 'loadPreset': lx.out("LOADING PRESET") loadPreset() if arg == 'savePreset': lx.out("SAVING PRESET") savePreset() #recupere la liste des layer actif "renderOutput" if arg == 'getRender': #On sauve la selection active_scene = lx.eval("query sceneservice scene.name ? current") OSF_saveSelection = lx.evalN("query sceneservice selection ? all") #on eteint tous les flag numList = len(listName) i=0 while ( i < numList): nameFlag = "rom_"+listName[i]+"Flag"; lx.eval('user.value %s {}' % nameFlag) i = i+ 1 #on recupere la liste de tous les layer actif existingRenderOutput = getRenderOuptut() #on regarde chaque layer si il existe on active le boutton correspondant num = len(existingRenderOutput) first = True if (num):
#python import lx def selectConectedUV(): lx.eval('!!select.3DElementUnderMouse set') lx.eval('ffr.selectconnecteduv') selType = lx.eval1('query layerservice selmode ?') if selType == 'polygon': p_hover = lx.eval1('query view3dservice element.over ? poly') p_sel = lx.evalN('query layerservice uv ? selected') if isinstance(p_hover, str): selectConectedUV() else: if len(p_sel) > 0: lx.eval('ffr.selectconnecteduv') else: lx.eval('select.all') elif selType == 'edge': lx.eval('select.type polygon') e_hover = lx.eval1('query view3dservice element.over ? poly') if isinstance(e_hover, str): selectConectedUV() else: lx.eval('select.all')
def getRenderOuptut(): """ Get a list of item IDs of type 'type' Returns a list of item IDs or None if there are no items of the specified tyep or if there's an error. Error printed is to Event log. type - the type of item to be returned (mesh, camera etc) """ global updateOnly global groupSelected global updateExistingOnly updateOnly = False try: """ #Si on fait seulement la mise a jour on recuoere tous les render existant ou ceux que lon a selectionner if (updateExistingOnly): RenderOutputsSelected = lx.evalN('query sceneservice selection ? renderOutput') RenderOutputs = [] if RenderOutputsSelected: for layer in RenderOutputsSelected: lx.out("UPDADE ONLY ",layer) RenderOutputs.append(lx.eval('query sceneservice item.ID ? %s' % layer)) return RenderOutputs # si on a rien selectionner on met a jour tous les éléments else: itemlist = [] numitems = lx.eval('!!query sceneservice renderOutput.N ?') if numitems == 0: return None else: for x in xrange(numitems): #typeLayer = lx.eval( "query sceneservice item.type ? %s" %(x) ) #if( typeLayer == "renderOutput" ) : idRender = lx.eval('query sceneservice renderOutput.ID ? %s' % (x)) itemlist.append(idRender) return itemlist """ #Est ce qu'on a selectionner des render Ouput RenderOutputsSelected = lx.evalN('query sceneservice selection ? renderOutput') RenderOutputs = [] if RenderOutputsSelected: for layer in RenderOutputsSelected: lx.out(layer) lx.out("le parent:"+lx.eval('query sceneservice item.parent ? %s' % layer)) RenderOutputs.append(lx.eval('query sceneservice item.ID ? %s' % layer)) updateOnly = True; return RenderOutputs #Est ce qu'une selection de group exist ? selectionMask = lx.evalN('query sceneservice selection ? mask') masks = [] if selectionMask: layer = selectionMask[0] lx.out(layer) groupSelected = layer #lx.eval('query sceneservice item.name ? %s' % layer) nameGroup = lx.eval('query sceneservice item.name ? %s' % layer) +"_" nameGroup = nameGroup.replace(" (Material)","") nameGroup = nameGroup.replace(" (Item)","") lx.eval('user.value rom_prefixName %s' %(nameGroup)) #Has child output childRender = lx.evalN('query sceneservice item.children ? %s' % layer) lx.out(childRender) return childRender #Est ce qu'une selection de Render principal ? selectionMask = lx.evalN('query sceneservice selection ? polyRender') masks = [] if selectionMask: layer = selectionMask[0] lx.out(layer) groupSelected = layer #lx.eval('query sceneservice item.name ? %s' % layer) #Has child output childRender = lx.evalN('query sceneservice item.children ? %s' % layer) lx.out(childRender) return childRender # On peut cree seulement en selectionnant le poly render, un render output ou un mask itemlist = [] numitems = lx.eval('!!query sceneservice renderOutput.N ?') if numitems == 0: return None else: for x in xrange(numitems): #typeLayer = lx.eval( "query sceneservice item.type ? %s" %(x) ) #if( typeLayer == "renderOutput" ) : itemlist.append(lx.eval('query sceneservice renderOutput.ID ? %s' % (x))) return itemlist except: #exc_log() lx.out("ERROR getRenderOuptut") return None
# File: mc_lxRename_removeX.py # Author: Matt Cox # Description: Bulk renames a selection of items, removing X amount of characters from the start or the end. Based upon the user variable removeX. import lx import re lxRRemoveXString = lx.eval( "user.value mcRename.removeX ?" ) lxRRemoveXArgs = lx.args() lxRRemoveXArg = lxRRemoveXArgs[0] if lxRRemoveXString < 0: lxRRemoveXString = 0 try: lxRSelectedItems = lx.evalN('query sceneservice selection ? all') for x in lxRSelectedItems: lx.eval('select.Item %s' %str(x)) lxRMeshNameM = lx.eval('query sceneservice item.name ? %s' %str(x)) try: if lxRRemoveXArg == "start": lxRNewNameM = lxRMeshNameM[lxRRemoveXString:] else: lxRNewNameM = lxRMeshNameM[:-lxRRemoveXString] lx.eval('item.name "%s"'%(lxRNewNameM)) except: lx.eval('dialog.setup error') lx.eval('dialog.title {Error}') lx.eval('dialog.msg {Unable to rename items.}') lx.eval('dialog.open')
# --------------------------------- lx.eval("item.matchWorkplanePos") scene_svc = lx.Service("sceneservice") layer_svc = lx.Service("layerservice") allowed_modes = ('polygon', 'edge', 'vertex') # Query Mode (For the IF item) FirstCheckModoMode = lx.eval('query layerservice selmode ?') itemtypes = ("locator","light","sunLight","camera","mesh") # Selected layers selMesh = lx.evalN("query sceneservice selection ? all") lx.out(FirstCheckModoMode) # If no layer and no component selected if len(selMesh) == 0 and not FirstCheckModoMode == 'item': lx.out("no component") locator_at_zero() # Check if current selection mode is a component mode if FirstCheckModoMode in allowed_modes: lx.out("component mode") for item in selMesh:
def getBoundarySideFromPolys(polygon_index_set): mainlayer = lx.eval("query layerservice layers ? main") edge_list = [] while polygon_index_set: lx.eval("!!select.drop polygon") lx.eval("!!select.element " + str(mainlayer) + " polygon set " + str(polygon_index_set.pop())) lx.eval("!!select.connect") current_polys = lx.eval("query layerservice polys ? selected") lx.eval("!!select.drop edge") lx.eval("!!select.type polygon") lx.eval("!!select.boundary") boundary_edges = set(eval(x) for x in lx.eval("query layerservice edges ? selected")) loop_edges = [] while boundary_edges: boundary_edge = boundary_edges.pop() lx.eval("select.element " + str(mainlayer) + " edge set " + str(boundary_edge[0]) + " " + str(boundary_edge[1])) lx.eval("select.loop") loop_edges.append([eval(x) for x in lx.eval("query layerservice edges ? selected")]) boundary_edges -= set(loop_edges[len(loop_edges) - 1]) lx.out(len(loop_edges)) lx.out(loop_edges) if len(loop_edges) > 2: error ("Bad Selection", "Polygon selection has holes") sys.exit( "LXe_FAILED:Script failed" ) if len(loop_edges) == 2: error ("Bad Selection", "You selection is a polygon loop") sys.exit( "LXe_FAILED:Script failed" ) edge_verts = set() for poly in current_polys: edge_verts = edge_verts.symmetric_difference(set(lx.eval("query layerservice poly.vertList ? " + str(poly)))) if len(edge_verts) != 4: error ("Bad Selection", "Selection contains broken polygons loops or has polygons with more or less than four vertices. Quads only") sys.exit( "LXe_FAILED:Script failed" ) edge_vert = edge_verts.pop() shortest_edge_vert = 0 steps = 0 lx.eval("select.type vertex") while edge_verts: lx.eval("select.element " + str(mainlayer) + " vert set " + str(edge_vert)) test_vert = edge_verts.pop() lx.eval("select.element " + str(mainlayer) + " vert add " + str(test_vert)) lx.eval("select.between") current_steps = lx.eval("query layerservice vert.N ? selected") if current_steps < steps or steps == 0: steps = current_steps shortest_edge_vert = test_vert lx.eval("select.element " + str(mainlayer) + " vert set " + str(edge_vert)) lx.eval("select.element " + str(mainlayer) + " vert add " + str(shortest_edge_vert)) lx.eval("select.between") lx.eval("select.convert edge") edge_list.append([eval(x) for x in lx.evalN("query layerservice edges ? selected")]) polygon_index_set -= set(current_polys) lx.eval("!!select.drop edge") for edges in edge_list: for edge in edges: lx.eval("select.element " + str(mainlayer) + " edge add " + str(edge[0]) + " " + str(edge[1])) return edge_list
#python import lx selection = lx.evalN('query sceneservice selection ? mesh') for mesh in selection: meshName = lx.eval('query sceneservice item.name ? {%s}' % mesh) lx.eval('select.item {%s} set' % mesh) numMat = lx.eval1('query layerservice material.N ?') for i in range(0, numMat): matID = lx.eval('query layerservice material.id ? {%s}' % i) matParent = lx.eval('query sceneservice item.parent ? {%s}' % matID) if i == 0: lx.eval('select.item {%s} set' % matParent) else: lx.eval('select.item {%s} add' % matParent) lx.eval('shader.group') lx.eval('item.name {%s (Materials)} mask' % meshName) lx.eval('select.drop item')