Make some of the more complex imports relative

This commit is contained in:
Dion Moult
2024-07-18 14:18:17 +10:00
parent 93a1355c5e
commit cec732138c
4 changed files with 17 additions and 8 deletions
+3 -3
View File
@@ -25,7 +25,7 @@ from . import handler, ui, prop, operator, helper
from typing import Callable, Union from typing import Callable, Union
try: try:
from blenderbim.translations import translations_dict from .translations import translations_dict
except ImportError: except ImportError:
translations_dict = {} translations_dict = {}
cwd = os.path.dirname(os.path.realpath(__file__)) cwd = os.path.dirname(os.path.realpath(__file__))
@@ -91,7 +91,7 @@ modules = {
for name in modules.keys(): for name in modules.keys():
modules[name] = importlib.import_module(f"blenderbim.bim.module.{name}") modules[name] = importlib.import_module(f".module.{name}", package=__package__)
classes = [ classes = [
@@ -289,7 +289,7 @@ def unregister():
km.keymap_items.remove(kmi) km.keymap_items.remove(kmi)
addon_keymaps.clear() addon_keymaps.clear()
import blenderbim.tool as tool from . import tool
# use tuple() as method will be removing keys from dict # use tuple() as method will be removing keys from dict
for panel in tuple(original_scene_panels_polls.keys()): for panel in tuple(original_scene_panels_polls.keys()):
+4 -3
View File
@@ -24,10 +24,10 @@ import hashlib
import zipfile import zipfile
import tempfile import tempfile
import traceback import traceback
import importlib
import ifcopenshell import ifcopenshell
import ifcopenshell.geom import ifcopenshell.geom
import ifcopenshell.ifcopenshell_wrapper import ifcopenshell.ifcopenshell_wrapper
import blenderbim
import blenderbim.bim.handler import blenderbim.bim.handler
import blenderbim.tool as tool import blenderbim.tool as tool
from pathlib import Path from pathlib import Path
@@ -35,6 +35,7 @@ from blenderbim.tool.brick import BrickStore
from typing import Set, Union, Optional, TypedDict, Callable from typing import Set, Union, Optional, TypedDict, Callable
bbim = importlib.import_module("..", package=__package__)
IFC_CONNECTED_TYPE = Union[bpy.types.Material, bpy.types.Object] IFC_CONNECTED_TYPE = Union[bpy.types.Material, bpy.types.Object]
@@ -364,7 +365,7 @@ class IfcStore:
@staticmethod @staticmethod
def execute_ifc_operator(operator: bpy.types.Operator, context: bpy.types.Context, is_invoke=False): def execute_ifc_operator(operator: bpy.types.Operator, context: bpy.types.Context, is_invoke=False):
blenderbim.last_actions.append({"type": "operator", "name": operator.bl_idname}) bbim.last_actions.append({"type": "operator", "name": operator.bl_idname})
bpy.context.scene.BIMProperties.is_dirty = True bpy.context.scene.BIMProperties.is_dirty = True
is_top_level_operator = not bool(IfcStore.current_transaction) is_top_level_operator = not bool(IfcStore.current_transaction)
@@ -385,7 +386,7 @@ class IfcStore:
else: else:
result = getattr(operator, "_execute")(context) result = getattr(operator, "_execute")(context)
except: except:
blenderbim.last_error = traceback.format_exc() bbim.last_error = traceback.format_exc()
raise raise
if is_top_level_operator: if is_top_level_operator:
@@ -22,6 +22,7 @@ import time
import json import json
import logging import logging
import tempfile import tempfile
import importlib
import traceback import traceback
import subprocess import subprocess
import datetime import datetime
@@ -58,6 +59,9 @@ from blenderbim.bim.module.project.decorator import ProjectDecorator, ClippingPl
from typing import Union from typing import Union
bbim = importlib.import_module("..", package=__package__)
class NewProject(bpy.types.Operator): class NewProject(bpy.types.Operator):
bl_idname = "bim.new_project" bl_idname = "bim.new_project"
bl_label = "New Project" bl_label = "New Project"
@@ -742,7 +746,7 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
if not self.is_advanced: if not self.is_advanced:
bpy.ops.bim.load_project_elements() bpy.ops.bim.load_project_elements()
except: except:
blenderbim.last_error = traceback.format_exc() bbim.last_error = traceback.format_exc()
raise raise
return {"FINISHED"} return {"FINISHED"}
+5 -1
View File
@@ -25,6 +25,7 @@ import logging
import textwrap import textwrap
import shutil import shutil
import platform import platform
import importlib
import subprocess import subprocess
import tempfile import tempfile
import webbrowser import webbrowser
@@ -44,6 +45,9 @@ from collections import namedtuple
from typing import List from typing import List
bbim = importlib.import_module("..", package=__package__)
class SetTab(bpy.types.Operator): class SetTab(bpy.types.Operator):
bl_idname = "bim.set_tab" bl_idname = "bim.set_tab"
# NOTE: bl_label is set to empty string intentionally # NOTE: bl_label is set to empty string intentionally
@@ -95,7 +99,7 @@ class CloseError(bpy.types.Operator):
bl_label = "Close Error" bl_label = "Close Error"
def execute(self, context): def execute(self, context):
blenderbim.last_error = None bbim.last_error = None
return {"FINISHED"} return {"FINISHED"}
def draw(self, context): def draw(self, context):