Advertisement
ludwik_janiuk

Blender crashing

Apr 26th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.57 KB | None | 0 0
  1. # LUCID JOINT ADDON
  2.  
  3. import bpy
  4. import bgl
  5. from bpy.app.handlers import persistent
  6. from bpy.types import Operator
  7. from bpy.props import FloatVectorProperty, BoolProperty
  8. from bpy_extras.object_utils import AddObjectHelper, object_data_add
  9. from mathutils import Vector
  10.  
  11.  
  12. def draw_callback_px(self, context):
  13.     pass
  14.     # # 50% alpha, 2 pixel width line
  15.     # bgl.glEnable(bgl.GL_BLEND)
  16.     # bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
  17.     # bgl.glLineWidth(2)
  18.  
  19.     # bgl.glBegin(bgl.GL_LINE_STRIP)
  20.     # for obj in bpy.data.objects:
  21.     #     l = obj.location
  22.     #     try:
  23.     #         c  = obj.constraints
  24.     #         if "Child Of" in c:
  25.     #             l = c["Child Of"].target.location + l
  26.     #     except AttributeError as ex:
  27.     #         pass
  28.     #     bgl.glVertex3f(l.x, l.y, l.z)  
  29.     # bgl.glEnd()
  30.  
  31.     # # restore opengl defaults
  32.     # bgl.glLineWidth(1)
  33.     # bgl.glDisable(bgl.GL_BLEND)
  34.     # bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
  35.  
  36. def add_object(self, context):
  37.     def unselect_all():
  38.         bpy.ops.object.select_all(action="DESELECT")
  39.  
  40.     selected = bpy.context.selected_objects
  41.     if len(selected) is not 2:
  42.         return True
  43.  
  44.     'FINISHED' in bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
  45.     joint = bpy.context.active_object
  46.     'FINISHED' in bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
  47.     a = bpy.context.active_object
  48.     'FINISHED' in bpy.ops.object.empty_add(type='PLAIN_AXES', location=(0, 0, 0))
  49.     b = bpy.context.active_object
  50.  
  51.     a.protected = True
  52.     b.protected = True
  53.  
  54.     joint.select = True
  55.     a.select = True
  56.     b.select = True
  57.     bpy.context.scene.objects.active = joint
  58.     bpy.ops.object.parent_set()
  59.  
  60.     unselect_all()
  61.  
  62.     bpy.context.scene.objects.active = a
  63.     selected[0].select = True
  64.     bpy.ops.object.constraint_add_with_targets(type="CHILD_OF")
  65.  
  66.     unselect_all()
  67.  
  68.     bpy.context.scene.objects.active = b
  69.     selected[1].select = True
  70.     bpy.ops.object.constraint_add_with_targets(type="CHILD_OF")
  71.  
  72.    
  73.     # return {'RUNNING_MODAL'}
  74.  
  75.     return False
  76.  
  77.  
  78. class OBJECT_OT_add_object(Operator, AddObjectHelper):
  79.     """Create a new LUCID Joint"""
  80.     bl_idname = "mesh.add_b2joint"
  81.     bl_label = "Add LUCID Joint"
  82.     bl_options = {'REGISTER', 'UNDO'}
  83.  
  84.     @classmethod
  85.     def register(cls):
  86.         # the arguments we pass the the callback
  87.         # args = (self, context)
  88.         # Add the region OpenGL drawing callback
  89.         # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
  90.         pass
  91.  
  92.  
  93.  
  94.     def modal(self, context, event):
  95.         context.area.tag_redraw()
  96.  
  97.         if event.type in {'ESC'}:
  98.             bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
  99.             return {'CANCELLED'}
  100.  
  101.         return {'PASS_THROUGH'}
  102.  
  103.     def execute(self, context):
  104.         print("QWEQWEQWEQWEQWEQWEQWE")
  105.         self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, (), 'WINDOW', 'POST_VIEW')
  106.         bpy.context.window_manager.modal_handler_add(self)
  107.         return {'FINISHED'}
  108.  
  109.     def invoke(self, context, event):
  110.         return {'CANCELLED'} if add_object(self, context) else {'FINISHED'}
  111.  
  112.  
  113. # Registration
  114.  
  115. def add_object_button(self, context):
  116.     self.layout.operator(
  117.         OBJECT_OT_add_object.bl_idname,
  118.         text="LUCID Joint",
  119.         icon='PLUGIN')
  120.  
  121. #Protectedness follows
  122. bpy.types.Object.protected = BoolProperty(name = 'protected', default = False)
  123. def main_prot(context):
  124.     for obj in context.selected_objects:
  125.         if not obj.protected :
  126.             bpy.context.scene.objects.unlink(obj)
  127.             bpy.data.objects.remove(obj)
  128.         else :
  129.             print(obj.name +' is protected')
  130.  
  131.  
  132. class delete_override(bpy.types.Operator):
  133.     """Tooltip"""
  134.     bl_idname = "object.delete"
  135.     bl_label = "Simple Object Operator"
  136.  
  137.     @classmethod
  138.     def poll(cls, context):
  139.         return context.active_object is not None
  140.  
  141.     def execute(self, context):
  142.         main_prot(context)
  143.         return {'FINISHED'}
  144.  
  145. @persistent
  146. def load_handler(dummy):
  147.     bpy.ops.mesh.add_b2joint()
  148.  
  149. def register():
  150.     bpy.utils.register_class(delete_override)
  151.     bpy.utils.register_class(OBJECT_OT_add_object)
  152.     bpy.types.INFO_MT_mesh_add.append(add_object_button)
  153.     bpy.app.handlers.load_post.append(load_handler)
  154.     bpy.ops.mesh.add_b2joint()
  155.    
  156. def unregister():
  157.     bpy.utils.unregister_class(delete_override)
  158.     bpy.utils.unregister_class(OBJECT_OT_add_object)
  159.     bpy.types.INFO_MT_mesh_add.remove(add_object_button)
  160.  
  161. if __name__ == "__main__":
  162.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement