2
$\begingroup$

I'm not much into scripting nor fit in the blender API, so I don't know how bpy.ops.mesh.separate(type='MATERIAL') behaves, What I need for my script is to rename the separated parts as the material they have been separated by, but this should be done in a for loop in the function separate() and I don't know how to access it.

Someone knows how to rename by material in this API function? Or how to edit temporarily the function so that it works in the script?

$\endgroup$
3
$\begingroup$

This script will rename all separated objects according to the material applied to each. It assumes the object you want to split and rename is selected and active.

import bpy

bpy.ops.object.mode_set( mode = 'EDIT' )
bpy.ops.mesh.select_all( action = 'SELECT' )
bpy.ops.mesh.separate( type = 'MATERIAL' )    # Separate by material
bpy.ops.object.mode_set( mode = 'OBJECT' )

# After separating, all pieces are selected
for o in bpy.context.selected_objects:
    # Rename object by the material applied to it
    o.name = o.active_material.name
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.