Changing Material Value at once without double click every single materials

Hi, I would like to swap my current constant node to the material function node which is named"CommonAttribs_MF", in the every selected materialss’ material editors. And here’s the script but it doesn’t work.
How should I fix this script?

import unreal

def swap_constant_node_to_material_function():
    # Get the selected materials from the Content Browser
    selected_materials = unreal.EditorUtilityLibrary.get_selected_assets()

    # Get the Editor Level Library
    editor_level_lib = unreal.EditorLevelLibrary()

    # Iterate over the selected materials
    for material_asset in selected_materials:
        if isinstance(material_asset, unreal.Material):
            # Load the material
            material = material_asset

            # Open the material in the material editor

            # Get the material editor instance
            material_editor_instance = unreal.MaterialEditingLibrary.get_singleton().get_editor_instance()
            if material_editor_instance:
                # Get all nodes in the material editor graph
                graph_nodes = material_editor_instance.get_all_nodes()

                # Iterate over the nodes and find the constant nodes
                for node in graph_nodes:
                    if isinstance(node, unreal.MaterialExpressionConstant):
                        # Create a new Material Function node
                        material_function_node = material_editor_instance.create_new_node(unreal.MaterialExpressionFunction, node.pos_x, node.pos_y)

                        # Disconnect the links from the constant node

                        # Connect the links to the Material Function node
                        material_editor_instance.connect_material_node_outputs(node, material_function_node)

                        # Remove the constant node from the graph

                        # Save the changes to the material asset

            # Close the material editor

    # Print a message indicating the completion of the script
    print("Constant node swapped with Material Function node in selected materials.")

# Call the function to execute the swapping

My goal is to achieve this below so if you have alternate suggestion that will also be great help for me :slightly_smiling_face: : Change multiple selected materialss’ emmisive color value at once which is connected to Multiply node’s Output. Multiply node’s A input is connected to Texture node’s RGB Output and B input is connected to constant node. Also, the texture node’s RGB Output is connected to the main material node’s Base Color Input as well.