From c0e45f9ea0523e5e6bf66bf7fa1597fca7232326 Mon Sep 17 00:00:00 2001
From: Martin Buerbaum <martin.buerbaum@gmx.at>
Date: Tue, 13 Apr 2010 12:57:44 +0000
Subject: [PATCH] * Added new Submenu "Fracture Objects" (Bomb, Recorder,
 Projectile) in the "Add" menu. * Fixed usage of "relative_path" in
 bpy.ops.wm.link_append() * Added "fracture" name to all operators somewhere.

---
 fracture/__init__.py       | 50 +++++++++++++++++++++++++++++---------
 fracture/fracture_ops.py   | 18 ++++++++------
 fracture/fracture_setup.py |  9 ++-----
 3 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/fracture/__init__.py b/fracture/__init__.py
index 097daa723..697101f58 100644
--- a/fracture/__init__.py
+++ b/fracture/__init__.py
@@ -17,7 +17,7 @@
 # ##### END GPL LICENSE BLOCK #####
 
 bl_addon_info = {
-    'name': 'Object: Fracture tools',
+    'name': 'Object: Fracture Tools',
     'author': 'pildanovak',
     'version': '2.0',
     'blender': (2, 5, 3),
@@ -27,26 +27,54 @@ bl_addon_info = {
     'category': 'Object'}
 
 import bpy
+from fracture import fracture_ops, fracture_setup
+
+
+class INFO_MT_add_fracture_objects(bpy.types.Menu):
+    bl_idname = "INFO_MT_add_fracture_objects"
+    bl_label = "Fracture Objects"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.operator_context = 'INVOKE_REGION_WIN'
+
+        layout.operator("object.import_fracture_bomb",
+            text="Bomb")
+        layout.operator("object.import_fracture_projectile",
+            text="Projectile")
+        layout.operator("object.import_fracture_recorder",
+            text="Rigidbody Recorder")
+
+import space_info
+# Define the submenu
+menu_func = (lambda self,
+    context: self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN"))
 
 
 def register():
-    from fracture import fracture_ops, fracture_setup
     bpy.types.register(fracture_ops.FractureSimple)
     bpy.types.register(fracture_ops.FractureGroup)
-    bpy.types.register(fracture_ops.ImportRecorder)
-    bpy.types.register(fracture_ops.ImportBomb)
-    bpy.types.register(fracture_ops.ImportProjectile)
-    bpy.types.register(fracture_setup.SetupShards)
+    bpy.types.register(fracture_ops.ImportFractureRecorder)
+    bpy.types.register(fracture_ops.ImportFractureBomb)
+    bpy.types.register(fracture_ops.ImportFractureProjectile)
+    bpy.types.register(fracture_setup.SetupFractureShards)
+    bpy.types.register(INFO_MT_add_fracture_objects)
+
+    # Add the "add fracture objects" menu to the "Add" menu
+    space_info.INFO_MT_add.append(menu_func)
 
 
 def unregister():
-    from fracture import fracture_ops, fracture_setup
     bpy.types.unregister(fracture_ops.FractureSimple)
     bpy.types.unregister(fracture_ops.FractureGroup)
-    bpy.types.unregister(fracture_ops.ImportRecorder)
-    bpy.types.unregister(fracture_ops.ImportBomb)
-    bpy.types.unregister(fracture_ops.ImportProjectile)
-    bpy.types.unregister(fracture_setup.SetupShards)
+    bpy.types.unregister(fracture_ops.ImportFractureRecorder)
+    bpy.types.unregister(fracture_ops.ImportFractureBomb)
+    bpy.types.unregister(fracture_ops.ImportFractureProjectile)
+    bpy.types.unregister(fracture_setup.SetupFractureShards)
+    bpy.types.unregister(INFO_MT_add_fracture_objects)
+
+    # Remove "add fracture objects" menu from the "Add" menu.
+    space_info.INFO_MT_add.remove(menu_func)
 
 if __name__ == "__main__":
     register()
diff --git a/fracture/fracture_ops.py b/fracture/fracture_ops.py
index ab226da6f..bf6405d64 100644
--- a/fracture/fracture_ops.py
+++ b/fracture/fracture_ops.py
@@ -431,7 +431,9 @@ def import_object(obname):
         s = os.sep
         dpath = bpy.utils.script_paths()[0] + \
             '%saddons%sfracture%sdata.blend\\Object\\' % (s, s, s)
-        print(opath)
+
+        # DEBUG
+        #print('import_object: ' + opath)
 
         bpy.ops.wm.link_append(
                 path=opath,
@@ -442,15 +444,15 @@ def import_object(obname):
                 autoselect=True,
                 active_layer=True,
                 instance_groups=True,
-                relative_paths=True)
+                relative_path=True)
 
         for ob in bpy.context.selected_objects:
             ob.location = bpy.context.scene.cursor_location
 
 
-class ImportRecorder(bpy.types.Operator):
+class ImportFractureRecorder(bpy.types.Operator):
     '''Imports a rigidbody recorder'''
-    bl_idname = "object.import_recorder"
+    bl_idname = "object.import_fracture_recorder"
     bl_label = "Add Rigidbody Recorder (Fracture)"
     bl_options = {'REGISTER', 'UNDO'}
 
@@ -460,9 +462,9 @@ class ImportRecorder(bpy.types.Operator):
         return {'FINISHED'}
 
 
-class ImportBomb(bpy.types.Operator):
+class ImportFractureBomb(bpy.types.Operator):
     '''Import a bomb'''
-    bl_idname = "object.import_bomb"
+    bl_idname = "object.import_fracture_bomb"
     bl_label = "Add Bomb (Fracture)"
     bl_options = {'REGISTER', 'UNDO'}
 
@@ -472,9 +474,9 @@ class ImportBomb(bpy.types.Operator):
         return {'FINISHED'}
 
 
-class ImportProjectile(bpy.types.Operator, ):
+class ImportFractureProjectile(bpy.types.Operator, ):
     '''Imports a projectile'''
-    bl_idname = "object.import_projectile"
+    bl_idname = "object.import_fracture_projectile"
     bl_label = "Add Projectile (Fracture)"
     bl_options = {'REGISTER', 'UNDO'}
 
diff --git a/fracture/fracture_setup.py b/fracture/fracture_setup.py
index d8256da32..235dd2136 100644
--- a/fracture/fracture_setup.py
+++ b/fracture/fracture_setup.py
@@ -61,9 +61,9 @@ def setupshards(context):
         #print(ob)
 
 
-class SetupShards(bpy.types.Operator):
+class SetupFractureShards(bpy.types.Operator):
     ''''''
-    bl_idname = "object.fracture_setup_shards"
+    bl_idname = "object.setup_fracture_shards"
     bl_label = "Setup Fracture Shards"
     bl_options = {'REGISTER', 'UNDO'}
 
@@ -72,8 +72,3 @@ class SetupShards(bpy.types.Operator):
     def execute(self, context):
         setupshards(context)
         return {'FINISHED'}
-
-#bpy.types.register(SetupShards)
-
-#if __name__ == "__main__":
-#    bpy.ops.object.fracture_setup_shards()
-- 
GitLab