python SME error

python SME error

fubing666
Observer Observer
838 Views
2 Replies
Message 1 of 3

python SME error

fubing666
Observer
Observer

from pymxs import runtime as rt
rt.MatEditor.Open()

if rt.maxOps.mtlDlgMode == rt.Name('basic'):
rt.meditMaterials[0] = rt.selection[0].material
elif rt.maxOps.mtlDlgMode == rt.Name('advanced'):
if rt.sme.activeView == 0:
rt.sme.CreateView(rt.uniquename("MaterialView_"))
active_view = rt.sme.GetView(rt.sme.activeView)
new_node = active_view.CreateNode(rt.selection[0].material, rt.Point2(400, 800))

nodes_array = rt.Array(new_node)
active_view.LayoutAll()
#1:
active_view.SetSelectedNodes(new_node )

# Unable to convert: <MixinInterface:Node> to type: MaxObject
# 2:
#active_view.SetSelectedNodes(nodes_array)

# Unable to convert: <MixinInterface:Node> to type: MaxObject


active_view.ZoomExtents(type=rt.Name('selected'))

 

 

i use #1: or #2:    max send back:# Unable to convert: <MixinInterface:Node> to type: MaxObject

 

please help me!!3q

0 Likes
839 Views
2 Replies
Replies (2)
Message 2 of 3

istan
Advisor
Advisor
0 Likes
Message 3 of 3

ads_decatae
Autodesk
Autodesk

Hello @fubing666 ,

 

Let me know if this is what you were looking for: 

 

from pymxs import runtime as rt

def main():
    try:
        # Open Material Editor
        rt.MatEditor.Open()
        
        # Check if there are any selected objects
        if rt.selection.count == 0:
            raise Exception("No objects selected.")
        
        # Check the mode of the Material Editor
        if rt.maxOps.mtlDlgMode == rt.Name('basic'):
            rt.meditMaterials[0] = rt.selection[0].material
        elif rt.maxOps.mtlDlgMode == rt.Name('advanced'):
            if rt.sme.activeView == 0:
                rt.sme.CreateView(rt.uniquename("MaterialView_"))
            
            active_view = rt.sme.GetView(rt.sme.activeView)
            
            # Ensure there's a material to work with
            if not hasattr(rt.selection[0], 'material'):
                raise Exception("Selected object does not have a material.")
            
            new_node = active_view.CreateNode(rt.selection[0].material, rt.Point2(400, 800))
            
            # Convert new_node to a MaxObject
            max_node = rt.GetMaxObject(new_node)
            
            # Use the correct node type for SetSelectedNodes
            nodes_array = rt.Array(max_node)
            active_view.LayoutAll()
            
            # Set selected nodes properly
            active_view.SetSelectedNodes(nodes_array)
            
            # Zoom to extents of selected nodes
            active_view.ZoomExtents(type=rt.Name('selected'))
        
    except Exception as e:
        print(f"Error: {e}")

main()


Elena de Catalina
Sr. QA Analyst
Entertainment Creation Products, ECP
0 Likes