Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. __bpydoc__ = """\
  20. The DeCouple addon is really simple but useful: the selected parent object will be decoupled
  21. temporarily from its children so youll be able to reposition the parent without influencing
  22. the children. This is mainly a workflow shortcut, cause unparenting and reparenting
  23. can take some time when there are many children.
  24.  
  25.  
  26. Documentation
  27.  
  28. First go to User Preferences->Addons and enable the DeCouple addon in the Object category.
  29. Select the parent object of your choice and click "Unparent" (button in the Object Tools panel)
  30. to unparent all children while keeping transform. Now ex-parent can be transformed.
  31. Then click "Reparent" to reparent all children to the ex-parent object.
  32.  
  33. If you wish to hotkey DeCouple:
  34. In the Input section of User Preferences at the bottom of the 3D View > Object Mode section click 'Add New' button.
  35. In the Operator Identifier box put 'object.decouple'.
  36. Assign a hotkey.
  37. Save as Default (Optional).
  38. """
  39.  
  40.  
  41. bl_info = {
  42. "name": "DeCouple",
  43. "author": "Gert De Roost",
  44. "version": (0, 2, 0),
  45. "blender": (2, 6, 5),
  46. "location": "View3D > Tools",
  47. "description": "Temporarily decouples parent and children",
  48. "warning": "",
  49. "wiki_url": "",
  50. "tracker_url": "",
  51. "category": "Object"}
  52.  
  53.  
  54.  
  55. import bpy
  56.  
  57.  
  58.  
  59.  
  60.  
  61. class DeCouple(bpy.types.Operator):
  62. bl_idname = "object.decouple"
  63. bl_label = "DeCouple"
  64. bl_description = "Temporarily decouples parent and children"
  65. bl_options = {"REGISTER", "UNDO"}
  66.  
  67.  
  68. @classmethod
  69. def poll(cls, context):
  70. obj = context.active_object
  71. return (obj and context.mode == 'OBJECT')
  72.  
  73. def execute(self, context):
  74.  
  75. global unparented
  76.  
  77. self.do_decouple(context)
  78. unparented = True
  79.  
  80. return {'FINISHED'}
  81.  
  82.  
  83. def do_decouple(self, context):
  84.  
  85. global parent, children
  86.  
  87. parent = context.active_object
  88. if len(parent.children) == 0:
  89. return
  90. parent.select = 0
  91. children = []
  92. for child in parent.children:
  93. children.append(child)
  94. child.select = 1
  95. bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
  96. for child in children:
  97. child.select = 0
  98. parent.select = 1
  99. context.scene.objects.active = parent
  100.  
  101.  
  102. class ReCouple(bpy.types.Operator):
  103. bl_idname = "object.recouple"
  104. bl_label = "ReCouple"
  105. bl_description = "Recouples decoupled parent and children"
  106. bl_options = {"REGISTER", "UNDO"}
  107.  
  108. @classmethod
  109. def poll(cls, context):
  110. obj = context.active_object
  111. return (obj and context.mode == 'OBJECT')
  112.  
  113. def execute(self, context):
  114.  
  115. global unparented, children
  116.  
  117. self.do_recouple(context)
  118. unparented = False
  119.  
  120. return {'FINISHED'}
  121.  
  122. def do_recouple(self, context):
  123. parent.select = 0
  124. for child in children:
  125. child.select = 1
  126. parent.select = 1
  127. context.scene.objects.active = parent
  128. bpy.ops.object.parent_set()
  129. for child in children:
  130. child.select = 0
  131.  
  132.  
  133.  
  134.  
  135.  
  136. def panel_func(self, context):
  137.  
  138. self.layout.label(text="DeCouple:")
  139. if not(unparented):
  140. self.layout.operator("object.decouple", text = "Unparent")
  141. else:
  142. self.layout.operator("object.recouple", text = "Reparent")
  143.  
  144.  
  145. def register():
  146.  
  147. global unparented
  148.  
  149. unparented = False
  150.  
  151. bpy.utils.register_module(__name__)
  152. bpy.types.VIEW3D_PT_tools_object.append(panel_func)
  153.  
  154.  
  155. def unregister():
  156. bpy.utils.unregister_module(__name__)
  157. bpy.types.VIEW3D_PT_tools_object.remove(panel_func)
  158.  
  159.  
  160. if __name__ == "__main__":
  161. register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement