def link_selection_to_splint(context, odc_splint,clear = False, debug = False): #TODO check univ vs intl system teeth = odcutils.tooth_selection(context) implants = odcutils.implant_selection(context) t_names = [tooth.name for tooth in teeth] i_names = [imp.name for imp in implants] t_names.sort() i_names.sort() if clear: if len(teeth): odc_splint.tooth_string = ":".join(t_names) odc_splint.implant_string =":".join(i_names) else: if len(teeth): t_existing = odc_splint.tooth_string.split(':') print(t_existing) final_teeth = list(set(t_existing) | set(t_names)) final_teeth.sort() print(final_teeth) odc_splint.tooth_string = ":".join(final_teeth) if len(implants): i_existing = odc_splint.implant_string.split(':') print(i_existing) final_imps = list(set(i_existing) | set(i_names)) final_imps.sort() odc_splint.implant_string = ":".join(final_imps) print(final_imps)
def execute(self, context): settings = get_settings() dbg = settings.debug odcutils.scene_verification(context.scene, debug=dbg) spaces = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') for space in spaces: if not space.implant: self.report( {'WARNING'}, "It seems you have not yet placed an implant for %s" % space.name) else: if self.use_thickness: thickness = self.thickness else: thickness = None implant_utils.implant_inner_cylinder(context, space, thickness=thickness, debug=dbg) odcutils.material_management(context, context.scene.odc_implants) odcutils.layer_management(context.scene.odc_implants, debug=dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[9] = True return {'FINISHED'}
def poll(cls, context): #restoration exists and is in scene teeth = odcutils.tooth_selection(context) #TODO:...make this poll work for all selected teeth... condition_1 = len(teeth) > 0 implants = odcutils.implant_selection(context) condition_2 = len(implants) > 0 return condition_1 or condition_2
def execute(self,context): settings = get_settings() dbg = settings.debug odcutils.scene_verification(context.scene, debug = dbg) spaces = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') for space in spaces: if not space.implant: self.report({'WARNING'}, "It seems you have not yet placed an implant for %s" % space.name) else: if self.use_thickness: thickness = self.thickness else: thickness = None implant_utils.implant_inner_cylinder(context, space, thickness = thickness, debug = dbg) odcutils.material_management(context, context.scene.odc_implants) odcutils.layer_management(context.scene.odc_implants, debug = dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[9] = True return {'FINISHED'}
def execute(self, context): #add a textbox to display information. attach it to this #add a persisetent callback on scene update #which monitors the status of the ODC #clear previous handlers clear_help_handlers() global implant_help_app_handle implant_help_app_handle = bpy.app.handlers.scene_update_pre.append( implant_help_parser) global help_display_box if help_display_box != None: del help_display_box help_text = 'Open Dental Implant Help Wizard \n' selections = odcutils.implant_selection( bpy.context) #weird, how do I specify better arguments? sel_names = [item.name for item in selections] help_text += 'Selected Implants: ' + ', '.join(sel_names) + '\n' help_text += 'Next Step: ' + 'TBA' help_display_box = TextBox(context, 500, 500, 300, 100, 10, 20, help_text) help_display_box.snap_to_corner(context, corner=[0, 1]) global implant_help_draw_handle implant_help_draw_handle = bpy.types.SpaceView3D.draw_handler_add( odc_help_draw, (self, context), 'WINDOW', 'POST_PIXEL') return {'FINISHED'}
def link_selection_to_splint(context, odc_splint, clear=False, debug=False): #TODO check univ vs intl system teeth = odcutils.tooth_selection(context) implants = odcutils.implant_selection(context) t_names = [tooth.name for tooth in teeth] i_names = [imp.name for imp in implants] t_names.sort() i_names.sort() if clear: if len(teeth): odc_splint.tooth_string = ":".join(t_names) odc_splint.implant_string = ":".join(i_names) else: if len(teeth): t_existing = odc_splint.tooth_string.split(':') print(t_existing) final_teeth = list(set(t_existing) | set(t_names)) final_teeth.sort() print(final_teeth) odc_splint.tooth_string = ":".join(final_teeth) if len(implants): i_existing = odc_splint.implant_string.split(':') print(i_existing) final_imps = list(set(i_existing) | set(i_names)) final_imps.sort() odc_splint.implant_string = ":".join(final_imps) print(final_imps)
def implant_help_parser(scene): if not hasattr(scene, 'odc_props'): print('no ODC') return selections = odcutils.implant_selection( bpy.context) #weird, how do I specify better arguments? sel_names = [item.name for item in selections] global help_display_box help_text = 'Implant Help Wizard \n' help_text += 'Selected Unit: ' + ', '.join(sel_names) + '\n' for implant in selections: help_text += implant_help_text(implant) if help_text != help_display_box.raw_text: help_display_box.raw_text = help_text help_display_box.format_and_wrap_text() help_display_box.fit_box_width_to_text_lines() help_display_box.fit_box_height_to_text_lines() help_display_box.snap_to_corner(bpy.context, corner=[0, 1])
def execute(self, context): settings = get_settings() dbg = settings.debug #if bpy.context.mode != 'OBJECT': # bpy.ops.object.mode_set(mode = 'OBJECT') sce = context.scene implants = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if implants != []: for implant_space in implants: #check if space already has an implant object. #if so, delete, replace, print warning Implant = bpy.data.objects[implant_space.implant] if Implant.rotation_mode != 'QUATERNION': Implant.rotation_mode = 'QUATERNION' Implant.update_tag() sce.update() if bpy.data.objects.get(implant_space.drill): self.report( {'WARNING'}, "replacing the existing drill with the one you chose") Sleeve = bpy.data.objects[implant_space.drill] #unlink it from the scene, clear it's users, remove it. sce.objects.unlink(Sleeve) Implant.user_clear() #remove the object bpy.data.objects.remove(Sleeve) current_obs = [ob.name for ob in bpy.data.objects] #link the new implant from the library settings = get_settings() odcutils.obj_from_lib(settings.drill_lib, self.drill) #this is slightly more robust than trusting we don't have duplicate names. for ob in bpy.data.objects: if ob.name not in current_obs: Sleeve = ob sce.objects.link(Sleeve) Sleeve.layers[19] = True mx_w = Implant.matrix_world.copy() #point the right direction Sleeve.rotation_mode = 'QUATERNION' Sleeve.rotation_quaternion = mx_w.to_quaternion() Sleeve.update_tag() context.scene.update() Trans = Sleeve.rotation_quaternion * Vector( (0, 0, -self.depth)) Sleeve.matrix_world[0][3] = mx_w[0][3] + Trans[0] Sleeve.matrix_world[1][3] = mx_w[1][3] + Trans[1] Sleeve.matrix_world[2][3] = mx_w[2][3] + Trans[2] Sleeve.name = implant_space.name + '_' + Sleeve.name implant_space.drill = Sleeve.name Sleeve.update_tag() context.scene.update() odcutils.parent_in_place(Sleeve, Implant) odcutils.layer_management(sce.odc_implants, debug=dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[19] = True return {'FINISHED'}
def execute(self, context): settings = get_settings() dbg = settings.debug #if bpy.context.mode != 'OBJECT': # bpy.ops.object.mode_set(mode = 'OBJECT') sce = context.scene n = sce.odc_implant_index implant_space = sce.odc_implants[n] implants = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] if implants != []: for implant_space in implants: #check if space already has an implant object. #if so, delete, replace, print warning if implant_space.implant and implant_space.implant in bpy.data.objects: self.report({ 'WARNING' }, "replacing the existing implant with the one you chose") Implant = bpy.data.objects[implant_space.implant] #the origin/location of the implant is it's apex L = Implant.location.copy() world_mx = Implant.matrix_world.copy() #the platorm is the length of the implant above the apex, in the local Z direction #local Z positive is out the apex, soit's negative. #Put the cursor there sce.cursor_location = L - Implant.dimensions[ 2] * world_mx.to_3x3() * Vector((0, 0, 1)) #first get rid of children...so we can use the #parent to find out who the children are if Implant.children: for child in Implant.children: sce.objects.unlink(child) child.user_clear() bpy.data.objects.remove(child) #unlink it from the scene, clear it's users, remove it. sce.objects.unlink(Implant) Implant.user_clear() #remove the object bpy.data.objects.remove(Implant) #TDOD what about the children/hardwares? else: world_mx = Matrix.Identity(4) world_mx[0][3] = sce.cursor_location[0] world_mx[1][3] = sce.cursor_location[1] world_mx[2][3] = sce.cursor_location[2] #is this more memory friendly than listing all objects? current_obs = [ob.name for ob in bpy.data.objects] #link the new implant from the library odcutils.obj_from_lib(settings.imp_lib, self.imp) #this is slightly more robust than trusting we don't have duplicate names. for ob in bpy.data.objects: if ob.name not in current_obs: Implant = ob sce.objects.link(Implant) #this relies on the associated hardware objects having the parent implant #name inside them if self.hardware: current_obs = [ob.name for ob in bpy.data.objects] inc = self.imp + '_' hardware_list = odcutils.obj_list_from_lib( settings.imp_lib, include=inc) print(hardware_list) for ob in hardware_list: odcutils.obj_from_lib(settings.imp_lib, ob) for ob in bpy.data.objects: if ob.name not in current_obs: sce.objects.link(ob) ob.parent = Implant ob.layers[11] = True delta = Implant.dimensions[2] * world_mx.to_3x3() * Vector( (0, 0, 1)) print(delta.length) world_mx[0][3] += delta[0] world_mx[1][3] += delta[1] world_mx[2][3] += delta[2] Implant.matrix_world = world_mx if sce.odc_props.master: Master = bpy.data.objects[sce.odc_props.master] odcutils.parent_in_place(Implant, Master) else: self.report({ 'WARNING' }, 'No Master Model, placing implant anyway, moving objects may not preserve spatial relationships' ) #looks a little redundant, but it ensure if any #duplicates exist our referencing stays accurate Implant.name = implant_space.name + '_' + Implant.name implant_space.implant = Implant.name odcutils.layer_management(sce.odc_implants, debug=dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[11] = True return {'FINISHED'}
def execute(self, context): settings = get_settings() dbg = settings.debug #if bpy.context.mode != 'OBJECT': # bpy.ops.object.mode_set(mode = 'OBJECT') sce = context.scene implants = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] = True if implants != []: for implant_space in implants: #check if space already has an implant object. #if so, delete, replace, print warning Implant = bpy.data.objects[implant_space.implant] if Implant.rotation_mode != 'QUATERNION': Implant.rotation_mode = 'QUATERNION' Implant.update_tag() sce.update() if bpy.data.objects.get(implant_space.drill): self.report({'WARNING'}, "replacing the existing drill with the one you chose") Sleeve = bpy.data.objects[implant_space.drill] #unlink it from the scene, clear it's users, remove it. sce.objects.unlink(Sleeve) Implant.user_clear() #remove the object bpy.data.objects.remove(Sleeve) current_obs = [ob.name for ob in bpy.data.objects] #link the new implant from the library settings = get_settings() odcutils.obj_from_lib(settings.drill_lib,self.drill) #this is slightly more robust than trusting we don't have duplicate names. for ob in bpy.data.objects: if ob.name not in current_obs: Sleeve = ob sce.objects.link(Sleeve) Sleeve.layers[19] = True mx_w = Implant.matrix_world.copy() #point the right direction Sleeve.rotation_mode = 'QUATERNION' Sleeve.rotation_quaternion = mx_w.to_quaternion() Sleeve.update_tag() context.scene.update() Trans = Sleeve.rotation_quaternion * Vector((0,0,-self.depth)) Sleeve.matrix_world[0][3] = mx_w[0][3] + Trans[0] Sleeve.matrix_world[1][3] = mx_w[1][3] + Trans[1] Sleeve.matrix_world[2][3] = mx_w[2][3] + Trans[2] Sleeve.name = implant_space.name + '_' + Sleeve.name implant_space.drill = Sleeve.name Sleeve.update_tag() context.scene.update() odcutils.parent_in_place(Sleeve, Implant) odcutils.layer_management(sce.odc_implants, debug = dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[19] = True return {'FINISHED'}
def execute(self, context): settings = get_settings() dbg = settings.debug #if bpy.context.mode != 'OBJECT': # bpy.ops.object.mode_set(mode = 'OBJECT') sce = context.scene n = sce.odc_implant_index implant_space = sce.odc_implants[n] implants = odcutils.implant_selection(context) layers_copy = [layer for layer in context.scene.layers] context.scene.layers[0] if implants != []: for implant_space in implants: #check if space already has an implant object. #if so, delete, replace, print warning if implant_space.implant and implant_space.implant in bpy.data.objects: self.report({'WARNING'}, "replacing the existing implant with the one you chose") Implant = bpy.data.objects[implant_space.implant] #the origin/location of the implant is it's apex L = Implant.location.copy() world_mx = Implant.matrix_world.copy() #the platorm is the length of the implant above the apex, in the local Z direction #local Z positive is out the apex, soit's negative. #Put the cursor there sce.cursor_location = L - Implant.dimensions[2] * world_mx.to_3x3() * Vector((0,0,1)) #first get rid of children...so we can use the #parent to find out who the children are if Implant.children: for child in Implant.children: sce.objects.unlink(child) child.user_clear() bpy.data.objects.remove(child) #unlink it from the scene, clear it's users, remove it. sce.objects.unlink(Implant) Implant.user_clear() #remove the object bpy.data.objects.remove(Implant) #TDOD what about the children/hardwares? else: world_mx = Matrix.Identity(4) world_mx[0][3]=sce.cursor_location[0] world_mx[1][3]=sce.cursor_location[1] world_mx[2][3]=sce.cursor_location[2] #is this more memory friendly than listing all objects? current_obs = [ob.name for ob in bpy.data.objects] #link the new implant from the library odcutils.obj_from_lib(settings.imp_lib,self.imp) #this is slightly more robust than trusting we don't have duplicate names. for ob in bpy.data.objects: if ob.name not in current_obs: Implant = ob sce.objects.link(Implant) #this relies on the associated hardware objects having the parent implant #name inside them if self.hardware: current_obs = [ob.name for ob in bpy.data.objects] inc = self.imp + '_' hardware_list = odcutils.obj_list_from_lib(settings.imp_lib, include = inc) print(hardware_list) for ob in hardware_list: odcutils.obj_from_lib(settings.imp_lib,ob) for ob in bpy.data.objects: if ob.name not in current_obs: sce.objects.link(ob) ob.parent = Implant ob.layers[11] = True delta = Implant.dimensions[2] * world_mx.to_3x3() * Vector((0,0,1)) print(delta.length) world_mx[0][3] += delta[0] world_mx[1][3] += delta[1] world_mx[2][3] += delta[2] Implant.matrix_world = world_mx if sce.odc_props.master: Master = bpy.data.objects[sce.odc_props.master] odcutils.parent_in_place(Implant, Master) else: self.report({'WARNING'}, 'No Master Model, placing implant anyway, moving objects may not preserve spatial relationships') #looks a little redundant, but it ensure if any #duplicates exist our referencing stays accurate Implant.name = implant_space.name + '_' + Implant.name implant_space.implant = Implant.name odcutils.layer_management(sce.odc_implants, debug = dbg) for i, layer in enumerate(layers_copy): context.scene.layers[i] = layer context.scene.layers[11] = True return {'FINISHED'}