Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import bpy
  2.  
  3.  
  4.  
  5. object = bpy.context.object
  6. current_object_mode = bpy.context.active_object.mode
  7.  
  8. if object.type == 'ARMATURE':
  9.  
  10. armature = object.data
  11. print(" " + object.name + " is selected. \n \n")
  12.  
  13. inputted_keywords = input(" Keyword(s) to filter for resetting limit distance (case insensitive): ")
  14.  
  15.  
  16.  
  17. print("\n Scanning... \n")
  18.  
  19. keyword_array_items = inputted_keywords.split()
  20. number_of_keywords = len(keyword_array_items)
  21.  
  22. bone_names = []
  23. matched_bone_names = []
  24.  
  25.  
  26. for b in armature.bones:
  27. current_bone = b.name
  28. bone_names.append(current_bone)
  29.  
  30. if any(words in b.name.casefold() for words in keyword_array_items):
  31. print(current_bone)
  32. matched_bone_names.append(current_bone)
  33.  
  34. bpy.ops.object.mode_set(mode='POSE')
  35. pose_bone = object.pose.bones[current_bone]
  36.  
  37. has_constraints = getattr(pose_bone, "constraints")
  38.  
  39. #temp = has_constraint[0].name
  40.  
  41. if not has_constraints:
  42. print("No constraints.")
  43.  
  44. for c in pose_bone.constraints:
  45. constraint_name = getattr(c, "name")
  46. print(constraint_name)
  47.  
  48.  
  49. if constraint_name == "Limit Distance":
  50.  
  51. print("Limit distance found, resetting value...")
  52.  
  53. #bpy.ops.constraint["Limit Distance"].limitdistance_reset()
  54.  
  55. ob = bpy.context.object
  56. con = ob.pose.bones[0].constraints[constraint_name.name]
  57. ctx = bpy.context.copy()
  58. ctx['constraint'] = con
  59. while ob.pose.bones[0].constraints[0] != con:
  60. bpy.ops.constraint.limitdistance_reset(ctx, constraint=con.name, owner='BONE.001')
  61.  
  62.  
  63. c.limitdistance_reset()
  64.  
  65. #object has no attribute 'limitdestance_reset'
  66.  
  67.  
  68.  
  69.  
  70. intersecting_bones = set.intersection(set(bone_names), set(matched_bone_names))
  71.  
  72. if intersecting_bones:
  73. print("\n Intersecting bones: ", format(intersecting_bones))
  74.  
  75. elif not intersecting_bones:
  76. print("\n Sorry, nothing found.")
  77.  
  78. bpy.ops.object.mode_set(mode = str(current_object_mode))
  79.  
  80. print ("\n Number of filter words used: " + str(number_of_keywords) + "\n")
  81.  
  82.  
  83. elif object.type != 'ARMATURE':
  84. print ("This object is not an armature.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement