def pywolf_sync_active_layer_models(): return if wolf_version == "": logger.log("PyWolf not available") return #first select nodes of active layer MaxPlus.SelectionManager.ClearNodeSelection() _layer = MaxPlus.LayerManager.GetCurrentLayer() _layer_name = _layer.GetName() if _layer_name == "_Problems_" or _layer_name == "_Boundaries_" or _layer_name == "_Inner_Layers_" or _layer_name == "_Middle_Layers_" or _layer_name == "_Outer_Layers_": logger.log("Could not add following Layers: _Problems_, _Boundaries_, _Inner_Layers_, _Middle_Layers_, _Outer_Layers_") return _selecting_nodes = MaxPlus.INodeTab() for _node in _layer.GetNodes(): _selecting_nodes.Append(_node) if len(_selecting_nodes) != 0: #select MaxPlus.SelectionManager.SelectNodes(_selecting_nodes) #_collada_exp_path = tmp_dir + "\W" + get_unique_name() + ".DAE" #export the scene in the format of OpenCollada _max_sxript_cmd = "exp_classes = exporterPlugin.classes \r\n\ _idx = findItem exp_classes OpenCOLLADAExporter \r\n\ if _idx != 0 do \r\n\ ( \r\n\ file_url = \"c:\\Wolf\\models.DAE\" \r\n\ exportFile (file_url) #noprompt selectedOnly:on using:exp_classes[_idx] \r\n\ )" MaxPlus.Core.EvalMAXScript(_max_sxript_cmd)
def DeleteHierarchy(node): children = GetChildren(node) tab = MaxPlus.INodeTab() for i in children: tab.Append(i) MaxPlus.INode.DeleteNodes(tab) node.Delete()
def findObjectAndBake(target, dummyroot, suffix, oppositeSuffix, copyDirection): bakeSources = list(sdknode.getChildren(dummyroot)) targetChildrens = list(sdknode.getChildren(target)) targetChildrens.append(target) bakeTargets = sdkutility.findObjectBySuffix(oppositeSuffix, targetChildrens) for bakeTarget in bakeTargets: bakeSource = findBakeSource(bakeTarget, bakeSources, oppositeSuffix, suffix) if bakeSource is not None: sdkutility.RemoveScaleKeys(bakeTarget) sdkutility.AddPositionListAndConstraint(bakeTarget) SetPositionConstraintTarget(bakeSource, bakeTarget) sdkutility.AddRotationListAndConstraint(bakeTarget) SetOrientationConstraintTarget(bakeSource, bakeTarget) selectionTab = MaxPlus.INodeTab() for n in bakeTargets: selectionTab.Append(n) MaxPlus.SelectionManager.SelectNodes(selectionTab) plotFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plot.ms") plot = open(plotFile, "r") MaxPlus.Core.EvalMAXScript(plot.read())
def deleteAllChildren(node): '''Delete all children nodes of a node.''' allChildren = collectChildrenNodes(node) nodesToDelete = MaxPlus.INodeTab() for node in allChildren: nodesToDelete.Append(node) node.DeleteNodes(nodesToDelete)
def selectNodes(self, origin): if origin.lw_objects.selectedItems() != []: MaxPlus.SelectionManager_ClearNodeSelection() nodes = MaxPlus.INodeTab() for i in origin.lw_objects.selectedItems(): node = origin.nodes[origin.lw_objects.row(i)] if self.isNodeValid(origin, node): nodes.Append(MaxPlus.INode.GetINodeByHandle(node)) MaxPlus.SelectionManager_SelectNodes(nodes)
def selectCam(self, origin): if self.isNodeValid(origin, origin.curCam): MaxPlus.SelectionManager_ClearNodeSelection() camNode = MaxPlus.INode.GetINodeByHandle(origin.curCam) if camNode.GetTarget().GetUnwrappedPtr() is not None: camNodes = MaxPlus.INodeTab() camNodes.Append(camNode) camNodes.Append(camNode.GetTarget()) MaxPlus.SelectionManager_SelectNodes(camNodes) else: MaxPlus.SelectionManager_SelectNode(camNode)
def deleteNodes(self, origin, handles): nodes = MaxPlus.INodeTab() for i in handles: nodes.Append(MaxPlus.INode.GetINodeByHandle(i)) xref = self.executeScript(origin, "item = objXRefMgr.IsNodeXRefed (maxOps.getNodeByHandle %s)\n\ if item == undefined then (\n\ False\n\ ) else (\n\ objXRefMgr.RemoveRecordFromScene item.xrefRecord\n\ True\n\ )\n\ " % handles[0]) if not xref: MaxPlus.INode.DeleteNodes(nodes)
def mirror_skin(src, target, src_suffix, target_suffix, mirror_axis): MaxPlus.Animation.SetTime(0, False) sdknode.collapseAllModifiers(target) target_skinmodifier = sdkskin.add_skin_modifier(target) MaxPlus.SelectionManager.SelectNode(target) MaxPlus.Core.EvalMAXScript("max modify mode") src_skinmodifier = sdkskin.get_skin_modifier(src) boneslist = sdkskin.get_bones_list_from_skin_modifier(src_skinmodifier) MaxPlus.SelectionManager.SelectNode(target) if boneslist: for bone in boneslist: binomial_bone = find_binomial(bone, src_suffix, target_suffix) if binomial_bone: sdkskin.add_bone_to_skin_modifier_of_selected_node( binomial_bone) else: sdkskin.add_bone_to_skin_modifier_of_selected_node(bone) else: return MaxPlus.SelectionManager.SelectNode(src) MaxPlus.Core_EvalMAXScript("skinUtils.ExtractSkinData $") skin_data = MaxPlus.INode.GetINodeByName("SkinData_" + src.GetName()) sdknode.mirrorNode(skin_data, mirror_axis) target_bone_list = sdkskin.get_bones_list_from_skin_modifier( target_skinmodifier) for target_bone in target_bone_list: name = target_bone.GetName() new_name = re.sub(r'{0}$'.format(target_suffix), src_suffix, name) target_bone.SetName(new_name) MaxPlus.SelectionManager.ClearNodeSelection() selection = MaxPlus.INodeTab() selection.Append(target) selection.Append(skin_data) MaxPlus.SelectionManager.SelectNodes(selection) MaxPlus.Core.EvalMAXScript( "skinUtils.ImportSkinDataNoDialog true false false false false 1 0") target_bone_list = sdkskin.get_bones_list_from_skin_modifier( target_skinmodifier) for target_bone in target_bone_list: name = target_bone.GetName() new_name = re.sub(r'{0}$'.format(src_suffix), target_suffix, name) target_bone.SetName(new_name) MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.INode.Delete(skin_data)
def select_nodes_by_name(names, add=False): """ Selects nodes by name :param names: list<str>, names of nodes to select :param add: bool, Whether to add given node names to an existing selection or not """ names = python.force_list(names) nodes = MaxPlus.INodeTab() for n in names: node = MaxPlus.INode.GetINodeByName(n) if node: nodes.Append(node) # Clear selection if need it if not add: MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(nodes)
def select_nodes(max_nodes, add=False): """ Select given Max nodes :param max_nodes: list<MaxPlus.INode> :param add: bool, Whether to add given node names to an existing selection or not """ # Check if we need to convert given list of MaxPlus.INodes into a MaxPlus.INodeTab if not isinstance(max_nodes, MaxPlus.INodeTab): sel = MaxPlus.INodeTab() for n in max_nodes: sel.Append(n) else: sel = max_nodes # Clear selection if need it if not add: MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(sel)
def SelectByVolume(volumeObj): """ Selects all transforms in the scene that are within the specified argument's bounding box volume. """ # Create bounding box class from object boundingBox = BoundingBox.FromShape(volumeObj) # Get all scene objects asides from bounding box sceneObjs = [ obj for obj in MaxPlus.Core.GetRootNode().Children if obj != volumeObj ] # Compare against every object in our scene to determine what is in our volume newSelection = MaxPlus.INodeTab() for obj in sceneObjs: # If the shape's bounding box intersects with the volume's bounding box if boundingBox.ContainsShape(obj): newSelection.Append(obj) # Update selection to nodes contained in volume if newSelection: MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(newSelection)
def sm_export_exportAppObjects(self, origin, startFrame, endFrame, outputName, scaledExport=False, expNodes=None): if startFrame == endFrame: self.setFrameRange(origin, startFrame=startFrame, endFrame=endFrame + 1) else: self.setFrameRange(origin, startFrame=startFrame, endFrame=endFrame) if expNodes is None: expNodes = origin.nodes if not origin.chb_wholeScene.isChecked() or scaledExport: MaxPlus.SelectionManager_ClearNodeSelection(False) nodes = MaxPlus.INodeTab() for node in expNodes: if self.isNodeValid(origin, node): nodes.Append(MaxPlus.INode.GetINodeByHandle(node)) MaxPlus.SelectionManager_SelectNodes(nodes) if origin.cb_outType.currentText() == ".obj": for i in range(startFrame, endFrame + 1): MaxPlus.Animation.SetTime( i * MaxPlus.Animation.GetTicksPerFrame(), False) foutputName = outputName.replace("####", format(i, '04')) if origin.chb_wholeScene.isChecked(): MaxPlus.FileManager.Export( foutputName, not origin.chb_additionalOptions.isChecked()) else: MaxPlus.FileManager.ExportSelected( foutputName, not origin.chb_additionalOptions.isChecked()) outputName = foutputName elif origin.cb_outType.currentText() == ".fbx": if startFrame == endFrame: self.executeScript(origin, "FbxExporterSetParam \"Animation\" False", returnVal=False) MaxPlus.Animation.SetTime( startFrame * MaxPlus.Animation.GetTicksPerFrame(), False) else: self.executeScript(origin, "FbxExporterSetParam \"Animation\" True", returnVal=False) if origin.chb_wholeScene.isChecked(): MaxPlus.FileManager.Export( outputName, not origin.chb_additionalOptions.isChecked()) else: MaxPlus.FileManager.ExportSelected( outputName, not origin.chb_additionalOptions.isChecked()) elif origin.cb_outType.currentText() == ".abc": self.executeScript(origin, "AlembicExport.CoordinateSystem = #Maya") if self.executeScript( origin, "getFileVersion \"$max/3dsmax.exe\"")[:2] in ["19", "20"]: self.executeScript(origin, "AlembicExport.CacheTimeRange = #StartEnd") self.executeScript(origin, "AlembicExport.StepFrameTime = 1") self.executeScript( origin, "AlembicExport.StartFrameTime = %s" % startFrame) self.executeScript( origin, "AlembicExport.EndFrameTime = %s" % endFrame) self.executeScript(origin, "AlembicExport.ParticleAsMesh = False") else: self.executeScript(origin, "AlembicExport.AnimTimeRange = #StartEnd") self.executeScript(origin, "AlembicExport.SamplesPerFrame = 1") self.executeScript( origin, "AlembicExport.StartFrame = %s" % startFrame) self.executeScript(origin, "AlembicExport.EndFrame = %s" % endFrame) self.executeScript(origin, "AlembicExport.ParticleAsMesh = False") if origin.chb_wholeScene.isChecked(): MaxPlus.FileManager.Export( outputName, not origin.chb_additionalOptions.isChecked()) else: MaxPlus.FileManager.ExportSelected( outputName, not origin.chb_additionalOptions.isChecked()) elif origin.cb_outType.currentText() == ".max": if origin.chb_wholeScene.isChecked(): MaxPlus.FileManager.Save(outputName, True, False) else: MaxPlus.FileManager.SaveSelected(outputName) if not origin.chb_wholeScene.isChecked(): MaxPlus.SelectionManager_ClearNodeSelection(False) if scaledExport: nodes = MaxPlus.INodeTab() for i in expNodes: iNode = MaxPlus.INode.GetINodeByHandle(i) nodes.Append(iNode) scaleHelper = MaxPlus.INode.GetINodeByName("SCALEOVERRIDE_" + iNode.GetName()) if scaleHelper.GetUnwrappedPtr() is not None: nodes.Append(scaleHelper) MaxPlus.INode.DeleteNodes(nodes) elif origin.chb_convertExport.isChecked(): fileName = os.path.splitext(os.path.basename(outputName)) if fileName[1] == ".max": MaxPlus.FileManager.Merge(outputName, True, True) else: if fileName[1] == ".abc": self.executeScript(origin, "AlembicImport.ImportToRoot = True") elif fileName[1] == ".fbx": self.executeScript(origin, "FBXImporterSetParam \"Mode\" #create") self.executeScript( origin, "FBXImporterSetParam \"ConvertUnit\" #cm") self.executeScript( origin, """ fn checkDialog = ( local hwnd = dialogMonitorOps.getWindowHandle() if (uiAccessor.getWindowText hwnd == "Import Name Conflict") then ( uiAccessor.PressButtonByName hwnd "OK" ) true ) dialogMonitorOps.enabled = true dialogMonitorOps.registerNotification checkDialog id:#test """) MaxPlus.FileManager.Import(outputName, True) self.executeScript( origin, """ dialogMonitorOps.unRegisterNotification id:#test dialogMonitorOps.enabled = false""") impNodes = [ x.GetHandle() for x in MaxPlus.SelectionManager_GetNodes() ] scaleNodes = [ x for x in impNodes if (MaxPlus.INode.GetINodeByHandle(x) ).GetParent().GetName() == "Scene Root" ] for i in scaleNodes: self.executeScript( origin, """obj = (maxOps.getNodeByHandle %s) sHelper = point() sHelper.name = ("SCALEOVERRIDE_" + obj.name) obj.parent = sHelper sVal = 0.01 sHelper.scale = [sVal, sVal, sVal]""" % i) MaxPlus.Animation.SetTime(origin.sp_rangeStart.value() * MaxPlus.Animation.GetTicksPerFrame()) # for i in impNodes: # self.executeScript(origin, "ResetXForm (maxOps.getNodeByHandle %s)" % i) outputName = os.path.join( os.path.dirname(os.path.dirname(outputName)), "meter", os.path.basename(outputName)) if not os.path.exists(os.path.dirname(outputName)): os.makedirs(os.path.dirname(outputName)) outputName = self.sm_export_exportAppObjects(origin, startFrame, endFrame, outputName, scaledExport=True, expNodes=impNodes) return outputName
def __init__(self, nodes=MaxPlus.INodeTab()): self.__nodes = nodes
self.__nodes = nodes def __str__(self): name_list = [] for each in self.__nodes: name_list.append(each.GetName()) return str(name_list) def append_selection(self): """add the selected nodes to the specified tab""" new_nodes = MaxPlus.SelectionManager.GetNodes() for each in new_nodes: if not (each in self.__nodes): self.__nodes.Append(each) theNode = MaxPlus.INode.GetINodeByName("Sphere001") theList = MaxPlus.INodeTab() theList.Append(theNode) m = MaxNodes(theList) print m m.append_selection() print m print dir(MaxPlus.INodeTab())
each.Position(MaxPlus.Point3(0,0,0)) #add modifier for each in selected_nodes: mod = MaxPlus.Factory.CreateObjectModifier(MaxPlus.Class_ID(0x9c92c88, 0x13d466dc)) MaxPlus.ModifierPanel.AddToSelection(mod) # Ejemplo de seleccion de tabnodes propios selected_nodes = (MaxPlus.SelectionManager.GetNodes()) myList = MaxPlus.INodeTab() for i in range( 0, len(selected_nodes)): myList.Append(selected_nodes[1]) # print str(selected_nodes[i].GetName()) MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(myList) # Example accesing param blocks in a modifier for each in selected_nodes: mod = MaxPlus.Factory.CreateObjectModifier(MaxPlus.Class_ID(0x9c92c88, 0x13d466dc)) MaxPlus.ModifierPanel.AddToSelection(mod)
''' This file demonstrates multiple ways for collecting scene nodes by name ''' import MaxPlus names = ["Teapot001", "Box001", "Sphere001", "Ball"] nodes = MaxPlus.INodeTab() for n in names: node = MaxPlus.INode.GetINodeByName(n) if node: nodes.Append(node) MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(nodes)