@@ -224,6 +224,18 @@ def save_joints_base_file():
224224# --------------------------------------------------
225225current_joint_central_point = None
226226
227+ def create_current_joint_central_point ():
228+ global current_joint_central_point
229+ mesh = bpy .data .meshes .new ('Basic_Sphere' )
230+ current_joint_central_point = bpy .data .objects .new ("Joint center" , mesh )
231+ bm = bmesh .new ()
232+ bmesh .ops .create_uvsphere (bm , u_segments = 4 , v_segments = 4 , diameter = 0.004 )
233+ bm .to_mesh (mesh )
234+ bm .free ()
235+ file_ops .link_to_collection (current_joint_central_point )
236+ current_joint_central_point .hide_select = True
237+
238+
227239def show_central_point (hist ):
228240 global current_joints_base_file
229241 global current_joint_central_point
@@ -240,14 +252,7 @@ def show_central_point(hist):
240252 # Now we have all vertices, we compute the average center
241253 central_point = algorithms .average_center (vertices )
242254 if current_joint_central_point == None :
243- mesh = bpy .data .meshes .new ('Basic_Sphere' )
244- current_joint_central_point = bpy .data .objects .new ("Joint center" , mesh )
245- bm = bmesh .new ()
246- bmesh .ops .create_uvsphere (bm , u_segments = 4 , v_segments = 4 , diameter = 0.004 )
247- bm .to_mesh (mesh )
248- bm .free ()
249- file_ops .link_to_collection (current_joint_central_point )
250- current_joint_central_point .hide_select = True
255+ create_current_joint_central_point ()
251256 current_joint_central_point .location = (central_point .x , central_point .y , central_point .z )
252257
253258# --------------------------------------------------
@@ -346,6 +351,8 @@ def show_offset_point(hist):
346351 if current_offset_point == None :
347352 create_offset_point ()
348353 co = file [hist .name ]
354+ if current_joint_central_point == None : # It happens.
355+ create_current_joint_central_point ()
349356 vect = current_joint_central_point .location
350357 current_offset_point .location = (
351358 vect .x + co [0 ],
@@ -407,6 +414,8 @@ def set_offset_point():
407414 for key , item in current_joints_offset_file .items ():
408415 file = item
409416 # Now we calculate de relative location of the offset
417+ if current_joint_central_point == None : # Security.
418+ create_current_joint_central_point ()
410419 center_point = current_joint_central_point .location
411420 offset_point = current_offset_point .location
412421 file [hist .name ] = [
0 commit comments