1
$\begingroup$

To separate an object, I use the edge split modifier in the object mode: enter image description here

then I go into edit mode, put my mouse over the external face and press L. This operation select all the external part and I can separate it from the rest : enter image description here

However when I try to do it with a script it doesn't work because I have to manually put my mouse over the external surface... Have you any ideas on how to seperate this object in two parts (the external part and the rest) with a python script ?

$\endgroup$
7
  • 1
    $\begingroup$ if it is for the case select the vertex with the highest Z component than use 'bpy.ops.mesh.select_linked()' or if the edge split modifier result is 2 meshes use separate loosee $\endgroup$
    – Chebhou
    Commented Mar 19, 2015 at 22:07
  • $\begingroup$ How do you select the vertex with the highest Z component with python ? $\endgroup$
    – reflyon
    Commented Mar 20, 2015 at 8:27
  • $\begingroup$ you sort them , go through them and find the max $\endgroup$
    – Chebhou
    Commented Mar 20, 2015 at 8:33
  • $\begingroup$ I tried to make a script to select the vertex with the highest Z component : me = bpy.context.object.data bm = bmesh.new() bm.from_mesh(me) for face in bm.faces: center = face.calc_center_median() for i in range (100,0): if center.z >= i : face.select_set(True) if face.select_set(True): return bm.to_mesh(me) bm.free() $\endgroup$
    – reflyon
    Commented Mar 20, 2015 at 14:59
  • $\begingroup$ @poor separate by loose my generate more than 2 objects (depends on the object structure ) $\endgroup$
    – Chebhou
    Commented Mar 22, 2015 at 19:37

1 Answer 1

1
$\begingroup$

Here is the script which :

  • goes thorough vertices and find the highest
  • select it and what is linked to it
  • separate it with separate(selected)

after applying the edge split modifier run this script :

import bpy

obj = bpy.context.object
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_all(action ='DESELECT')
max = -9999
for i in obj.data.vertices :
    if i.co[2] > max :
        max_ind = i.index
        max  = i.co[2]
bpy.ops.object.mode_set(mode = 'OBJECT')
obj.data.vertices[max_ind].select = True
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_linked()
bpy.ops.mesh.separate(type='SELECTED')
bpy.ops.object.mode_set(mode = 'OBJECT')

#bpy.context.selected_objects[0].location[2] +=1
$\endgroup$
0

You must log in to answer this question.

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