Paste Code
Paste Blends
Paste Images
import bpy, bmesh
from bpy import context as C

from bpy.types import Panel
bl_info = {
"name": "DecoupeObj",
"author": "Marc ",
"version": (1, 0),
"blender": (2, 75, 0),
"location": "View3D > Add > Mesh > New Object",
"description": "coupe un objet",
"warning": "",
"wiki_url": "",
"category": "Add Mesh",
}

class SimpleToolPanel(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_label = 'BricoKit'
bl_context = 'objectmode'
bl_category = 'Bricolage'
def draw(self, context):
layout = self.layout
layout.operator("object.simple_operator" , text='Decoupe' , icon="MODIFIER")

class SimpleToolPanel1(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_label = 'Objet'
bl_context = 'objectmode'
bl_category = 'Bricolage'
def draw(self, context):
layout = self.layout
layout.operator("object.simple_operator" , text='Proportion' , icon="MODIFIER")

def main(context,bm):
bpy.ops.object.mode_set(mode='EDIT')
C=bpy.context
bm = bmesh.from_edit_mesh(C.object.data)

edges = []
for i in range(-10, 10, 2):
ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(i,0,0), plane_no=(-1,0,0))
bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])

for i in range(-10, 10, 2):
ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(0,i,0), plane_no=(0,1,0))
bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])


bmesh.update_edit_mesh(C.object.data)

bpy.ops.mesh.separate(type='LOOSE')
bpy.ops.object.mode_set(mode='OBJECT')

def main1(context):
obj=bpy.context.selected_objects


class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
bpy.ops.object.mode_set(mode='EDIT')
C=context
bm = bmesh.from_edit_mesh(C.object.data)
main(context,bm)
return {'FINISHED'}

class SimpleOperator1(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator1"
bl_label = "Simple Object Operator1"

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
main1(context)
return {'FINISHED'}


def register():
bpy.utils.register_class(SimpleToolPanel)
bpy.utils.register_class(SimpleToolPanel1)
bpy.utils.register_class(SimpleOperator)


def unregister():
bpy.utils.register_class(SimpleToolPanel)
bpy.utils.register_class(SimpleToolPanel1)
bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
register()

# test call
#bpy.ops.object.simple_operator()

  1. import bpy, bmesh
  2. from bpy import context as C
  3.  
  4. from bpy.types import Panel
  5. bl_info = {
  6.     "name": "DecoupeObj",
  7.     "author": "Marc ",
  8.     "version": (1, 0),
  9.     "blender": (2, 75, 0),
  10.     "location": "View3D > Add > Mesh > New Object",
  11.     "description": "coupe un objet",
  12.     "warning": "",
  13.     "wiki_url": "",
  14.     "category": "Add Mesh",
  15.     }
  16.  
  17. class SimpleToolPanel(Panel):
  18.     bl_space_type = 'VIEW_3D'
  19.     bl_region_type = 'TOOLS'
  20.     bl_label = 'BricoKit'
  21.     bl_context = 'objectmode'
  22.     bl_category = 'Bricolage'
  23.     def draw(self, context):
  24.         layout = self.layout
  25.         layout.operator("object.simple_operator" , text='Decoupe' , icon="MODIFIER")
  26.  
  27. class SimpleToolPanel1(Panel):
  28.     bl_space_type = 'VIEW_3D'
  29.     bl_region_type = 'TOOLS'
  30.     bl_label = 'Objet'
  31.     bl_context = 'objectmode'
  32.     bl_category = 'Bricolage'
  33.     def draw(self, context):
  34.         layout = self.layout
  35.         layout.operator("object.simple_operator" , text='Proportion' , icon="MODIFIER")
  36.  
  37. def main(context,bm):
  38.     bpy.ops.object.mode_set(mode='EDIT')
  39.     C=bpy.context
  40.     bm = bmesh.from_edit_mesh(C.object.data)
  41.  
  42.     edges = []
  43.     for i in range(-10, 10, 2):
  44.         ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(i,0,0), plane_no=(-1,0,0))
  45.         bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])
  46.  
  47.     for i in range(-10, 10, 2):
  48.         ret = bmesh.ops.bisect_plane(bm, geom=bm.verts[:]+bm.edges[:]+bm.faces[:], plane_co=(0,i,0), plane_no=(0,1,0))
  49.         bmesh.ops.split_edges(bm, edges=[e for e in ret['geom_cut'] if isinstance(e, bmesh.types.BMEdge)])
  50.  
  51.  
  52.     bmesh.update_edit_mesh(C.object.data)
  53.  
  54.     bpy.ops.mesh.separate(type='LOOSE')
  55.     bpy.ops.object.mode_set(mode='OBJECT')
  56.  
  57. def main1(context):
  58.     obj=bpy.context.selected_objects
  59.    
  60.  
  61. class SimpleOperator(bpy.types.Operator):
  62.     """Tooltip"""
  63.     bl_idname = "object.simple_operator"
  64.     bl_label = "Simple Object Operator"
  65.  
  66.     @classmethod
  67.     def poll(cls, context):
  68.         return context.active_object is not None
  69.  
  70.     def execute(self, context):
  71.         bpy.ops.object.mode_set(mode='EDIT')
  72.         C=context
  73.         bm = bmesh.from_edit_mesh(C.object.data)
  74.         main(context,bm)
  75.         return {'FINISHED'}
  76.  
  77. class SimpleOperator1(bpy.types.Operator):
  78.     """Tooltip"""
  79.     bl_idname = "object.simple_operator1"
  80.     bl_label = "Simple Object Operator1"
  81.  
  82.     @classmethod
  83.     def poll(cls, context):
  84.         return context.active_object is not None
  85.  
  86.     def execute(self, context):
  87.         main1(context)
  88.         return {'FINISHED'}
  89.  
  90.  
  91. def register():
  92.     bpy.utils.register_class(SimpleToolPanel)
  93.     bpy.utils.register_class(SimpleToolPanel1)
  94.     bpy.utils.register_class(SimpleOperator)
  95.  
  96.  
  97. def unregister():
  98.     bpy.utils.register_class(SimpleToolPanel)
  99.     bpy.utils.register_class(SimpleToolPanel1)
  100.     bpy.utils.unregister_class(SimpleOperator)
  101.  
  102.  
  103. if __name__ == "__main__":
  104.     register()
  105.  
  106.     # test call
  107.     #bpy.ops.object.simple_operator()
  108.  
  109.  
go to heaven