Refactor right click context menu

This commit is contained in:
Gorgious
2022-10-31 17:30:33 +01:00
parent d05d430642
commit c0b91848a3
+28 -6
View File
@@ -19,11 +19,15 @@
import os import os
import bpy import bpy
from pathlib import Path from pathlib import Path
from ifcopenshell.util.doc import (
get_entity_doc,
get_property_set_doc,
get_type_doc,
)
from . import ifc from . import ifc
from bpy.types import Panel from bpy.types import Panel
from bpy.props import StringProperty, IntProperty, BoolProperty from bpy.props import StringProperty, IntProperty, BoolProperty
from blenderbim.bim.helper import IfcHeaderExtractor from blenderbim.bim.helper import IfcHeaderExtractor
from blenderbim.bim.prop import get_ifc_entity_doc_url, get_property_set_doc_url
import blenderbim.tool as tool import blenderbim.tool as tool
@@ -385,8 +389,6 @@ class BIM_PT_misc_object(Panel):
def draw_custom_context_menu(self, context): def draw_custom_context_menu(self, context):
if not hasattr(context, "button_pointer") or not hasattr(context, "button_prop"):
return
# https://blender.stackexchange.com/a/275555/86891 # https://blender.stackexchange.com/a/275555/86891
if ( if (
not hasattr(context, "button_pointer") not hasattr(context, "button_pointer")
@@ -399,9 +401,29 @@ def draw_custom_context_menu(self, context):
prop_value = getattr(prop, prop_name, None) prop_value = getattr(prop, prop_name, None)
if prop_value is None: if prop_value is None:
return return
url = get_ifc_entity_doc_url(prop_value) schema = tool.Ifc.get_schema()
if not bool(url):
url = get_property_set_doc_url(prop_value) docs = {}
try:
docs = get_entity_doc(schema, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
try:
docs = get_type_doc(schema, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
try:
docs = get_property_set_doc(schema, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
pass
if docs:
url = docs.get("spec_url", "")
else:
url = ""
description = getattr(context.button_pointer, "description", None) description = getattr(context.button_pointer, "description", None)
if not url and not description: if not url and not description: