Skip to content

Instantly share code, notes, and snippets.

@johnfredcee
Created July 21, 2011 12:40
Show Gist options
  • Save johnfredcee/1097107 to your computer and use it in GitHub Desktop.
Save johnfredcee/1097107 to your computer and use it in GitHub Desktop.
Dump Blender Scene via introspection
import bpy
import mathutils
def introspect_obj(o, txt):
print (txt)
if len(txt) > 200:
print ("Something is wrong")
print (txt)
return
type_o = type(o)
if (type_o in [ bool, int, float, type(None) ]):
print (o)
return
if (type_o == bpy.types.Scene):
print ("Scene " + o.name)
return
if (type_o == bpy.types.ActionGroup):
print ("Action Group " + o.name)
return
if (type_o == mathutils.Vector):
items = [ 'x', 'y', 'z', 'w' ]
for item in items:
newtxt = txt + '.' + item
introspect_obj( getattr(o, item, None), newtxt)
return
if (type(o) == str):
print ("\"" + o + "\"")
return
try: keys = o.keys()
except: keys = None
if keys != None:
print(txt + '.keys() - ' + str(o.keys()))
try: __members__ = dir(o)
except: __members__ = []
for item in __members__:
if item.startswith("__"):
continue
if item in [ 'rna_type', 'bl_rna' ]:
continue
newtxt = txt + '.' + item
introspect_obj( getattr(o, item, None), newtxt)
if keys:
for k in keys:
newtxt = txt + "[" + k + "]"
introspect_obj(o.__getitem__(k), newtxt)
else:
try: length = len( o )
except: length = 0
for i in range(length):
newtxt = txt + '[' + str(i) + ']'
introspect_obj(o[i], newtxt)
introspect_obj(bpy.data.objects, 'bpy.data.objects')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment