3
$\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

1 Answer 1

6
$\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$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .