15

Due to the lack of a class diagramm I need to explore the data structures by dumping objects to see what is in there.

How can I dump the Objects internals to the console?

In this snippet I tried to print the objects but I only get error messages 'TypeError'

def assignPose( plIdx ):
    rig = bpy.data.objects.get("rig")

    if rig != None:
        print("rig=" + str(tuple( rig ))) # TypeError: 'Object' object is not iterable
        print( "" + rig.__str__ )         # TypeError: Can't convert 'method-wrapper' object to str implicitly
        pl = rig.pose_library
        pl.poselib_apply_pose( plIdx )
    else:
        print("couldn't find rig.")
stacker
  • 38,549
  • 31
  • 141
  • 243

2 Answers2

17

I found a solution to get started:

def dump(obj):
   for attr in dir(obj):
       if hasattr( obj, attr ):
           print( "obj.%s = %s" % (attr, getattr(obj, attr)))

This is based on one of the methods suggested on this Stackoverflow post and this

Instead of invoking print call dump( anyobject )

This would print something like:

...
obj.copy = <bpy_func Object.copy()>
obj.cycles_visibility = <bpy_struct, CyclesVisibilitySettings("")>
obj.data = <bpy_struct, Armature("rig")>
obj.delta_location = <Vector (0.0000, 0.0000, 0.0000)>
obj.delta_rotation_euler = <Euler (x=0.0000, y=0.0000, z=0.0000), order='XYZ'>
obj.delta_rotation_quaternion = <Quaternion (w=1.0000, x=0.0000, y=0.0000, z=0.0
000)>
obj.delta_scale = <Vector (1.0000, 1.0000, 1.0000)>
obj.dimensions = <Vector (0.0000, 0.0000, 0.0000)>
obj.draw_bounds_type = BOX
obj.draw_type = WIRE
obj.dupli_faces_scale = 1.0
...
stacker
  • 38,549
  • 31
  • 141
  • 243
3

There is already an addon called API Navigator to explore the API. It has to be enabeld first in the User Preferences

enter image description here

enter image description here

stacker
  • 38,549
  • 31
  • 141
  • 243
  • Looked for this in 2.80, but guessing it may not be maintained :( See above comment for my hacky workaround based on object enumeration. – Eric Cousineau Oct 19 '19 at 00:45