[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15449] branches/soc-2008-djd/release/ scripts: Testing the support for tree structures and comparison

Dhanannjay Deo dhandeo at gmail.com
Sun Jul 6 15:51:46 CEST 2008


Revision: 15449
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15449
Author:   djd
Date:     2008-07-06 15:51:45 +0200 (Sun, 06 Jul 2008)

Log Message:
-----------
Testing the support for tree structures and comparison 

Modified Paths:
--------------
    branches/soc-2008-djd/release/scripts/dump_libdata.py

Added Paths:
-----------
    branches/soc-2008-djd/release/scripts/tree_sample.py

Modified: branches/soc-2008-djd/release/scripts/dump_libdata.py
===================================================================
--- branches/soc-2008-djd/release/scripts/dump_libdata.py	2008-07-06 11:25:58 UTC (rev 15448)
+++ branches/soc-2008-djd/release/scripts/dump_libdata.py	2008-07-06 13:51:45 UTC (rev 15449)
@@ -21,19 +21,65 @@
 # ===== Non Local Objects ========
 
 sce= bpy.data.scenes.active
-
 print bpy.data.scenes
 
+treeMap = {}
+
+# === For lib tree structure using dictionary ====
+class Node:
+ def __init__(self, n, s):
+     self.id = n
+     self.type = s
+     self.children = []
+
+
+# id is also name
+def AddToTree(id, type, parent):
+    if not id in treeMap:
+        treeMap[id] = Node(id, type)
+        print 'creating node %s as child to %s'%(type,treeMap[parent].type)
+    else:
+        treeMap[id].id = id
+        treeMap[id].type = type
+
+    if not parent in treeMap:
+        treeMap[parent] = Node(0, '')
+    treeMap[parent].children.append(treeMap[id])     
+    
+def print_map(node, lvl=0):
+    #~ print node.type, node.id, node.children
+    for n in node.children:
+        print '    ' * lvl + n.type + n.id
+        if len(n.children) > 0:
+            print_map(n, lvl+1)
+    
+
+# === Creating the root node  ====
+
+ID = 0;
+Name = 'Library_root'
+
+Root = Node(Name, 'Root')
+ID = ID +1
+
+treeMap[Root.id] = Root
+
+# === Browse through all scenes 
+
 for ob in bpy.data.scenes:
     print 'Members of Scene ..%d objects'%len(ob.objects)
     print 'Total objects .. %d'%len(bpy.data.objects)
     print ob;
     
+    # add the scene
+    AddToTree(ob.name, 'Scene', 'Library_root')
+    
     for anObject in ob.objects:
-        #~ print type(anObject)
-        #~ print anObject.getAllProperties()  
         print " %s"%anObject.getName()        
-        
+        Name = anObject.getName();
+
+        AddToTree(Name,'Scene','Library_root')
+            
         if anObject.getData():
             dblock = anObject.getData(0,1)
             try:
@@ -77,4 +123,4 @@
 for ob in bpy.data.meshes:
     print ob
     
-    
\ No newline at end of file
+print_map(Root)
\ No newline at end of file

Added: branches/soc-2008-djd/release/scripts/tree_sample.py
===================================================================
--- branches/soc-2008-djd/release/scripts/tree_sample.py	                        (rev 0)
+++ branches/soc-2008-djd/release/scripts/tree_sample.py	2008-07-06 13:51:45 UTC (rev 15449)
@@ -0,0 +1,54 @@
+
+
+
+# (node, parent, title)
+
+
+
+els = (
+ (1, 0, 'a'),
+ (2, 1, 'b'),
+ (3, 1, 'c'),
+ (4, 0, 'd'),
+ (5, 4, 'e'),
+ (6, 5, 'f'),
+ (7, 4, 'g')
+)
+
+treeMap = {}
+
+class Node:
+ def __init__(self, n, s):
+     self.id = n
+     self.title = s
+     self.children = []
+
+Root = Node(0, "Root")
+treeMap[Root.id] = Root
+
+def AddToTree(id, title, parent):
+    if not nodeId in treeMap:
+        treeMap[id] = Node(id, title)
+        print 'creating node %s as child to %s'%(title,treeMap[parent].title)
+    else:
+        treeMap[id].id = id
+        treeMap[id].title = title
+
+    if not parent in treeMap:
+        treeMap[parent] = Node(0, '')
+    treeMap[parent].children.append(treeMap[id])     
+    
+
+for element in els:
+    nodeId, parentId, title = element
+    AddToTree(nodeId, title, parentId)
+
+def print_map(node, lvl=0):
+    print node.title, node.id, node.children
+    for n in node.children:
+        print '    ' * lvl + n.title
+        if len(n.children) > 0:
+            print_map(n, lvl+1)
+
+print_map(Root)
+print treeMap





More information about the Bf-blender-cvs mailing list