0
$\begingroup$

I am linking Geometry Nodes modifiers of 2 meshes using blender python, but after that, I want the modifier of each mesh to be of a single user copy. Is this possible?

enter image description here

class ADDONNAME_OT_my_op_MPI(bpy.types.Operator):
    bl_label = "Add Motion Preset"
    bl_idname = "addonname.myop_operatormpi"
    
    
    def execute(self, context):
        scene = context.scene
        mytool = scene.my_toolmp
        
        if mytool.my_enumMoPr == 'OOPI1':
            # Replace these with the actual names of your source and target objects
            source_obj_name = "Cube"
            target_obj_name = bpy.context.view_layer.objects.active.name

            # Get the source and target objects
            source_obj = bpy.data.objects.get(source_obj_name)
            target_obj = bpy.data.objects.get(target_obj_name)

            # Check if both objects exist
            if source_obj and target_obj:

                # Iterate through the modifiers of the source object and copy them to the target object
                for modifier in source_obj.modifiers:
                    new_modifier = target_obj.modifiers.new(name=modifier.name, type=modifier.type)

                    # Copy some common settings (adjust as needed)
                    new_modifier.show_viewport = modifier.show_viewport
                    new_modifier.show_render = modifier.show_render
                    new_modifier.show_in_editmode = modifier.show_in_editmode

                    # Handle Geometry Nodes special case
                    if modifier.type == 'NODES':
                        new_modifier.node_group = modifier.node_group

                print("Modifiers copied successfully.")
            else:
                print("Source or target object not found.") 
$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .