rna_dump.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # Contributor(s): Campbell Barton
  18. #
  19. # ##### END GPL LICENSE BLOCK #####
  20. # <pep8 compliant>
  21. if 1:
  22. # Print once every 1000
  23. GEN_PATH = True
  24. PRINT_DATA = False
  25. PRINT_DATA_INT = 1000
  26. VERBOSE = False
  27. VERBOSE_TYPE = False
  28. MAX_RECURSIVE = 8
  29. else:
  30. # Print everything
  31. GEN_PATH = True
  32. PRINT_DATA = True
  33. PRINT_DATA_INT = 0
  34. VERBOSE = False
  35. VERBOSE_TYPE = False
  36. MAX_RECURSIVE = 8
  37. seek_count = [0]
  38. def seek(r, txt, recurs):
  39. seek_count[0] += 1
  40. if PRINT_DATA_INT:
  41. if not (seek_count[0] % PRINT_DATA_INT):
  42. print(seek_count[0], txt)
  43. if PRINT_DATA:
  44. print(txt)
  45. newtxt = ''
  46. if recurs > MAX_RECURSIVE:
  47. #print ("Recursion is over max")
  48. #print (txt)
  49. return
  50. type_r = type(r)
  51. # print(type_r)
  52. # print(dir(r))
  53. # basic types
  54. if type_r in (float, int, bool, type(None)):
  55. if PRINT_DATA:
  56. print(txt + ' -> ' + str(r))
  57. return
  58. if type_r == str:
  59. if PRINT_DATA:
  60. print(txt + ' -> "' + str(r) + '"')
  61. return
  62. try:
  63. keys = r.keys()
  64. except:
  65. keys = None
  66. if keys is not None:
  67. if PRINT_DATA:
  68. print(txt + '.keys() - ' + str(r.keys()))
  69. try:
  70. __members__ = dir(r)
  71. except:
  72. __members__ = []
  73. for item in __members__:
  74. if item.startswith("__"):
  75. continue
  76. if GEN_PATH:
  77. newtxt = txt + '.' + item
  78. if item == 'rna_type' and VERBOSE_TYPE is False: # just avoid because it spits out loads of data
  79. continue
  80. value = getattr(r, item, None)
  81. seek(value, newtxt, recurs + 1)
  82. if keys:
  83. for k in keys:
  84. if GEN_PATH:
  85. newtxt = txt + '["' + k + '"]'
  86. seek(r.__getitem__(k), newtxt, recurs + 1)
  87. else:
  88. try:
  89. length = len(r)
  90. except:
  91. length = 0
  92. if VERBOSE is False and length >= 4:
  93. for i in (0, length - 1):
  94. if i > 0:
  95. if PRINT_DATA:
  96. print((" " * len(txt)) + " ... skipping " + str(length - 2) + " items ...")
  97. if GEN_PATH:
  98. newtxt = txt + '[' + str(i) + ']'
  99. seek(r[i], newtxt, recurs + 1)
  100. else:
  101. for i in range(length):
  102. if GEN_PATH:
  103. newtxt = txt + '[' + str(i) + ']'
  104. seek(r[i], newtxt, recurs + 1)
  105. seek(bpy.data, 'bpy.data', 0)
  106. # seek(bpy.types, 'bpy.types', 0)
  107. '''
  108. for d in dir(bpy.types):
  109. t = getattr(bpy.types, d)
  110. try: r = t.bl_rna
  111. except: r = None
  112. if r:
  113. seek(r, 'bpy.types.' + d + '.bl_rna', 0)
  114. '''
  115. #print dir(bpy)
  116. #import sys
  117. #sys.exit()
  118. print("iter over ", seek_count, "rna items")