Last active
August 29, 2015 14:12
-
-
Save sweenist/4bc031fb53c9fee6f74c to your computer and use it in GitHub Desktop.
Blender API: simple script tp cross reference context and data attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple script to identify what bpy.context and bpy.data attributes have | |
some crossover. data attributes tend to end with "s", where the context is | |
singular | |
eg: bpy.data.objects[i] and bpy.context.object both inherit from: | |
bpy.types.Object | |
""" | |
import bpy | |
context_dict = {} | |
data_dict = {} | |
for attr in dir(bpy.context): | |
context_dict[attr] = {"class":str(getattr(bpy.context, attr)), | |
"type": exec("type(bpy.context." + attr + ")") | |
} | |
for attr in dir(bpy.data): | |
data_dict[attr] = {"class":str(getattr(bpy.data, attr)), | |
"type": exec("type(bpy.data." + attr + ")") | |
} | |
#make a list from keys then sort | |
kcl = list(context_dict.keys()) | |
kdl = list(data_dict.keys()) | |
kcl.sort() | |
kdl.sort() | |
print("Context Attributes:") | |
for kc in kcl: | |
print("\t", kc) | |
print("\nData Attributes:") | |
for kd in kdl: | |
print ("\t", kd) | |
l = [] | |
for kd in data_dict.keys(): | |
if kd[-1] == "s": | |
l.append(kd[:-1]) | |
for i in l: | |
if i in context_dict.keys(): | |
print(i + " context: " + str(context_dict[i]["class"]) + "\n\t" + str(context_dict[i]["type"])) | |
print(i + "s data: " + str(data_dict[i + "s"]["class"]) + "\n\t" + str(data_dict[i + "s"]["type"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this because I wanted to see what bpy attributes cross inherited. I was doing some research for someone else and boom, I came up with this.