[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3758] branches/protopipe: Rather than importing prototype objects manually,

Aurel W aurel.w at gmail.com
Wed Sep 19 02:31:18 CEST 2012


Revision: 3758
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3758
Author:   aurel
Date:     2012-09-19 00:31:16 +0000 (Wed, 19 Sep 2012)
Log Message:
-----------
Rather than importing prototype objects manually,
just search in available scenes (link manually).

Adding a post_load handler in __init__.py

Init util.py

Modified Paths:
--------------
    branches/protopipe/__init__.py
    branches/protopipe/jointproto.py
    branches/protopipe/ppapp.py

Added Paths:
-----------
    branches/protopipe/utils.py

Modified: branches/protopipe/__init__.py
===================================================================
--- branches/protopipe/__init__.py	2012-09-18 22:47:38 UTC (rev 3757)
+++ branches/protopipe/__init__.py	2012-09-19 00:31:16 UTC (rev 3758)
@@ -37,15 +37,28 @@
 
 if "bpy" in locals():
     import imp
-    imp.reload(ppapp)
+    imp.reload(bpy)
 else:
-    from . import ppapp
+    import bpy
 
+from . import ppapp
+from bpy.app.handlers import persistent
 
-def register():
+
+ at persistent
+def postLoad(arg):
+    """ Handler which gets called post blend load. """
+    print("ProtoPipe post load handler.")
     ppapp.loadLibs()
 
 
+def register():
+    # register a handler which is called
+    # after the blend file is loaded
+    bpy.app.handlers.load_post.append(postLoad)
+
+
+
 def unregister():
     pass
 

Modified: branches/protopipe/jointproto.py
===================================================================
--- branches/protopipe/jointproto.py	2012-09-18 22:47:38 UTC (rev 3757)
+++ branches/protopipe/jointproto.py	2012-09-19 00:31:16 UTC (rev 3758)
@@ -248,16 +248,18 @@
         self.protos = []
         pass
 
-    def loadFromBlendFile(self, fpath):
+    def loadFromScene(self, scenename):
+        self.name = scenename
+        # BROKEN This is shit and just leads to data weirdness
         # import external scene
-        with bpy.data.libraries.load(fpath,True) as (ext_data, int_data):
-            for scenename in ext_data.scenes:
-                if scenename[:3] == "pp_":
-                    self.name = scenename
-            # append
-            if not self.name in int_data.scenes:
-                print("appending library scene")
-                int_data.scenes = [self.name]
+        #with bpy.data.libraries.load(fpath,True) as (ext_data, int_data):
+        #    for scenename in ext_data.scenes:
+        #        if scenename[:3] == "pp_":
+        #            self.name = scenename
+        #    # append
+        #    if not self.name in int_data.scenes:
+        #        print("appending library scene")
+        #        int_data.scenes = [self.name]
 
         # scan the scene for prototype objects
         objects = bpy.data.scenes[self.name].objects

Modified: branches/protopipe/ppapp.py
===================================================================
--- branches/protopipe/ppapp.py	2012-09-18 22:47:38 UTC (rev 3757)
+++ branches/protopipe/ppapp.py	2012-09-19 00:31:16 UTC (rev 3758)
@@ -22,14 +22,18 @@
 from protopipe.jointproto import ProtoLibrary
 from protopipe.jointproto import JointFactory
 
+import protopipe.utils
 
+
 #### globals #####
 jointFactory = None
 
 def loadLibs():
     global jointFactory
     jointLib = ProtoLibrary()
-    jointLib.loadFromBlendFile("/home/aurel/pvclib.blend")
+    protopipe.utils.printAllSceneNames()
+    protopipe.utils.printAllObjectNames()
+    jointLib.loadFromScene("pp_40mmpvc")
 
     jointFactory = JointFactory()
     jointFactory.addJointProtoProvider(jointLib)

Added: branches/protopipe/utils.py
===================================================================
--- branches/protopipe/utils.py	                        (rev 0)
+++ branches/protopipe/utils.py	2012-09-19 00:31:16 UTC (rev 3758)
@@ -0,0 +1,35 @@
+
+#
+# Copyright 2012, Aurel Wildfellner.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+import bpy
+
+
+
+def printAllSceneNames():
+    s = "Scenes: "
+    for scene in bpy.data.scenes:
+        s += "\'" + scene.name + "\',"
+    print(s[:-1])
+
+
+def printAllObjectNames():
+    s = "Objects: "
+    for obj in bpy.data.objects:
+        s += "\'" + obj.name + "\',"
+    print(s[:-1])



More information about the Bf-extensions-cvs mailing list