[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [504] trunk/py/scripts/addons/ add_mesh_pipe_joint.py: * add_mesh_pipe_joint.py - Version 0.10

Martin Bürbaum martin.buerbaum at gmx.at
Tue Mar 23 22:10:31 CET 2010


Revision: 504
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=504
Author:   pontiac
Date:     2010-03-23 22:10:31 +0100 (Tue, 23 Mar 2010)

Log Message:
-----------
* add_mesh_pipe_joint.py - Version 0.10
* Store "recall" properties in the created objects. (Only usable in combination with the "Recall object operator" script enabled in the Add-Ons)
* Align the geometry to the view if the user preference says so.

Modified Paths:
--------------
    trunk/py/scripts/addons/add_mesh_pipe_joint.py

Modified: trunk/py/scripts/addons/add_mesh_pipe_joint.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_pipe_joint.py	2010-03-23 20:37:41 UTC (rev 503)
+++ trunk/py/scripts/addons/add_mesh_pipe_joint.py	2010-03-23 21:10:31 UTC (rev 504)
@@ -24,7 +24,7 @@
 bl_addon_info = {
     'name': 'Add Mesh: Pipe Joints',
     'author': 'Buerbaum Martin (Pontiac)',
-    'version': '0.9.10',
+    'version': '0.10',
     'blender': (2, 5, 3),
     'location': 'View3D > Add > Mesh > Pipe Joint',
     'url':
@@ -46,6 +46,8 @@
 Note: Currently only the "Elbow" type supports odd number of vertices.
 
 Version history:
+v0.10 - Store "recall" properties in the created objects.
+    Align the geometry to the view if the user preference says so.
 v0.9.10 - Use bl_addon_info for Add-On information.
 v0.9.9 - Changed the script so it can be managed from the "Add-Ons" tab in
     the user preferences.
@@ -110,6 +112,33 @@
 """
 
 
+# Stores the values of a list of properties in a
+# property group (named like the operator) in the object.
+# Always replaces any existing property group with the same name!
+# @todo: Should we do this in EDIT Mode? Sounds dangerous.
+def obj_store_recall_properties(ob, op, prop_list):
+    if ob and op and prop_list:
+        #print("Storing recall data for operator: " + op.bl_idname)  # DEBUG
+
+        # Store new recall properties.
+        prop_list['recall_op'] = op.bl_idname
+        ob['recall'] = prop_list
+
+
+# Apply view rotation to objects if "Align To" for new objects
+# was set to "VIEW" in the User Preference.
+def apply_view_rotation(context, ob):
+    align = bpy.context.user_preferences.edit.object_align
+
+    if (context.space_data.type == 'VIEW_3D'
+        and align == 'VIEW'):
+            view3d = context.space_data
+            region = view3d.region_3d
+            viewMatrix = region.view_matrix
+            rot = viewMatrix.rotation_part()
+            ob.rotation_euler = rot.invert().to_euler()
+
+
 def createFaces(vertIdx1, vertIdx2):
     '''
     A very simple "bridge" tool.
@@ -139,9 +168,11 @@
     return faces
 
 
-def createObject(scene, verts, faces, name):
+def createObject(context, verts, faces, name):
     '''Creates Meshes & Objects for the given lists of vertices and faces.'''
 
+    scene = context.scene
+
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
 
@@ -176,6 +207,8 @@
 
     obj_act = scene.objects.active
 
+    apply_view_rotation(context, ob_new)
+
     if obj_act and obj_act.mode == 'EDIT':
         # We are in EditMode, switch to ObjectMode.
         bpy.ops.object.mode_set(mode='OBJECT')
@@ -197,7 +230,9 @@
         # Make the new object the active one.
         scene.objects.active = ob_new
 
+    return ob_new
 
+
 class AddElbowJoint(bpy.types.Operator):
     # Create the vertices and polygons for a simple elbow (bent pipe).
     '''Add an Elbow pipe mesh'''
@@ -292,8 +327,17 @@
         faces.extend(createFaces(loop1, loop2))
         faces.extend(createFaces(loop2, loop3))
 
-        createObject(context.scene, verts, faces, "Elbow Joint")
+        obj = createObject(context, verts, faces, "Elbow Joint")
 
+        # Store 'recall' properties in the object.
+        recall_prop_list = {
+            "radius": radius,
+            "div": div,
+            "angle": angle,
+            "startLength": startLength,
+            "endLength": endLength}
+        obj_store_recall_properties(obj, self, recall_prop_list)
+
         return {'FINISHED'}
 
 
@@ -470,8 +514,18 @@
         faces.extend(createFaces(loopJoint2, loopArm))
         faces.extend(createFaces(loopJoint3, loopMainEnd))
 
-        createObject(context.scene, verts, faces, "Tee Joint")
+        obj = createObject(context, verts, faces, "Tee Joint")
 
+        # Store 'recall' properties in the object.
+        recall_prop_list = {
+            "radius": radius,
+            "div": div,
+            "angle": angle,
+            "startLength": startLength,
+            "endLength": endLength,
+            "branchLength": branchLength}
+        obj_store_recall_properties(obj, self, recall_prop_list)
+
         return {'FINISHED'}
 
 
@@ -663,8 +717,19 @@
         faces.extend(createFaces(loopJoint2, loopArm1))
         faces.extend(createFaces(loopJoint3, loopArm2))
 
-        createObject(context.scene, verts, faces, "Wye Joint")
+        obj = createObject(context, verts, faces, "Wye Joint")
 
+        # Store 'recall' properties in the object.
+        recall_prop_list = {
+            "radius": radius,
+            "div": div,
+            "angle1": angle1,
+            "angle2": angle2,
+            "startLength": startLength,
+            "branch1Length": branch1Length,
+            "branch2Length": branch2Length}
+        obj_store_recall_properties(obj, self, recall_prop_list)
+
         return {'FINISHED'}
 
 
@@ -917,8 +982,21 @@
         faces.extend(createFaces(loopJoint3, loopArm2))
         faces.extend(createFaces(loopJoint4, loopArm3))
 
-        createObject(context.scene, verts, faces, "Cross Joint")
+        obj = createObject(context, verts, faces, "Cross Joint")
 
+        # Store 'recall' properties in the object.
+        recall_prop_list = {
+            "radius": radius,
+            "div": div,
+            "angle1": angle1,
+            "angle2": angle2,
+            "angle3": angle3,
+            "startLength": startLength,
+            "branch1Length": branch1Length,
+            "branch2Length": branch2Length,
+            "branch3Length": branch3Length}
+        obj_store_recall_properties(obj, self, recall_prop_list)
+
         return {'FINISHED'}
 
 
@@ -1074,8 +1152,16 @@
                 createFaces(loopsJoints[loopIdx],
                 loopsEndCircles[loopIdx]))
 
-        createObject(context.scene, verts, faces, "N Joint")
+        obj = createObject(context, verts, faces, "N Joint")
 
+        # Store 'recall' properties in the object.
+        recall_prop_list = {
+            "radius": radius,
+            "div": div,
+            "number": number,
+            "length": length}
+        obj_store_recall_properties(obj, self, recall_prop_list)
+
         return {'FINISHED'}
 
 




More information about the Bf-extensions-cvs mailing list