2
$\begingroup$

I am dealing with an obj import from a different program - which I have no control on.

The output is one single mesh, different logical parts of which are assigned different materials.

I would like to separate the mesh by material - so that from the state below:

enter image description here

I could get to one with two separate meshes, one per material.

How is that done - both manually and (ideally) with python/bpy?

$\endgroup$
0
3
$\begingroup$

bpy.ops.mesh.separate(type='MATERIAL')

Separate selected geometry into a new mesh

You can use mesh.separate() in Edit Mode and pass 'MATERIAL' to its type argument:

import bpy

C = bpy.context

# If object type is mesh and mode is set to object
if C.object.type == 'MESH' and C.mode == 'OBJECT':
    # Edit Mode
    bpy.ops.object.mode_set(mode='EDIT')
    # Seperate by material
    bpy.ops.mesh.separate(type='MATERIAL')
    # Object Mode
    bpy.ops.object.mode_set(mode='OBJECT')
$\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.