Spaces:
Running
Running
# bpydoc.py | |
import pickle | |
from fastapi import APIRouter | |
router = APIRouter() | |
with open("routers/tool_bpy_doc_v4_1.pkl", 'rb') as file: | |
bpy_doc_map = pickle.load(file) | |
bpy_doc_map['__info'] = {'bases': None} | |
def bpy_doc_get_documentation(api): | |
parts = api.split('.') | |
api = "" | |
data = bpy_doc_map | |
ctx = [] | |
for part in parts: | |
try: | |
data = data[part] | |
api += part | |
ctx.append((api, data["__info"]['descr'])) | |
api += '.' | |
except Exception as ex: | |
descr = f"{type(ex).__name__}: {ex}. Perhaps this object was implemented in a later version." | |
ctx.append((api, descr)) | |
break | |
documentation = "" | |
for obj, descr in ctx: | |
documentation += f"{obj}:\n" | |
documentation += f"{descr}\n\n" | |
if len(data) > 1: | |
documentation += f"Members of {api}:\n" | |
info = data["__info"] | |
if info['bases']: | |
documentation += f"Inherits from {info['bases']}\n" | |
for key, val in data.items(): | |
if key != "__info": | |
descr = "" | |
if isinstance(val, list): | |
val = val[0] | |
descr = "`bpy_prop_collection` of {}".format( | |
val['__info']["descr"].replace('\n', ' ')) | |
else: | |
descr = val['__info']["descr"].replace('\n', ' ') | |
documentation += f"- {key}: {descr}\n" | |
return documentation | |
def bpy_doc(api: str = ""): | |
message = bpy_doc_get_documentation(api) | |
return {"message": message} | |
if __name__ == "__main__": | |
test = bpy_doc("bpy.context") | |
print(test) | |