More import fixes

This commit is contained in:
Dion Moult
2024-07-18 19:09:08 +10:00
parent c408bf339c
commit aaac864dcf
15 changed files with 49 additions and 42 deletions
+9 -6
View File
@@ -21,6 +21,7 @@ import bpy
import bmesh import bmesh
import json import json
import os import os
import importlib
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.element import ifcopenshell.util.element
from ..core import tool as core_tool from ..core import tool as core_tool
@@ -34,6 +35,8 @@ from ..bim.ifc import IFC_CONNECTED_TYPE
from typing import Any, Optional, Union, Literal, Iterable, Callable from typing import Any, Optional, Union, Literal, Iterable, Callable
bbim = importlib.import_module("..", package=__package__)
VIEWPORT_ATTRIBUTES = [ VIEWPORT_ATTRIBUTES = [
"view_matrix", "view_matrix",
"view_distance", "view_distance",
@@ -947,11 +950,11 @@ class Blender(core_tool.Blender):
@classmethod @classmethod
def register_toolbar(cls): def register_toolbar(cls):
import bim.module.model.workspace as ws_model from ..bim.module.model import workspace as ws_model
import bim.module.drawing.workspace as ws_drawing from ..bim.module.drawing import workspace as ws_drawing
import bim.module.spatial.workspace as ws_spatial from ..bim.module.spatial import workspace as ws_spatial
import bim.module.structural.workspace as ws_structural from ..bim.module.structural import workspace as ws_structural
import bim.module.covering.workspace as ws_covering from ..bim.module.covering import workspace as ws_covering
if bpy.app.background: if bpy.app.background:
return return
@@ -1110,7 +1113,7 @@ class Blender(core_tool.Blender):
@classmethod @classmethod
def get_blender_addon_package_name(cls) -> str: def get_blender_addon_package_name(cls) -> str:
if bpy.app.version >= (4, 2, 0): if bpy.app.version >= (4, 2, 0):
return blenderbim.BLENDER_PACKAGE_NAME return bbim.BLENDER_PACKAGE_NAME
return "blenderbim" return "blenderbim"
@classmethod @classmethod
+1 -1
View File
@@ -27,7 +27,7 @@ from typing import Any, Sequence
class Boundary(core_tool.Boundary): class Boundary(core_tool.Boundary):
@classmethod @classmethod
def get_assign_connection_geometry_settings(cls, obj: bpy.types.Object) -> dict[str, Any]: def get_assign_connection_geometry_settings(cls, obj: bpy.types.Object) -> dict[str, Any]:
from blenderbim.bim.module.geometry.helper import Helper from ..bim.module.geometry.helper import Helper
ifc = tool.Ifc.get() ifc = tool.Ifc.get()
helper = Helper(ifc) helper = Helper(ifc)
+4 -3
View File
@@ -21,6 +21,7 @@ import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.guid import ifcopenshell.guid
import ifcopenshell.util.brick import ifcopenshell.util.brick
from ..core import brick as core_brick
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
from contextlib import contextmanager from contextlib import contextmanager
@@ -395,17 +396,17 @@ class Brick(core_tool.Brick):
@classmethod @classmethod
def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None): def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None):
return blenderbim.core.brick.assign_brick_reference( return core_brick.assign_brick_reference(
tool.Ifc, tool.Brick, element=element, library=library, brick_uri=brick_uri tool.Ifc, tool.Brick, element=element, library=library, brick_uri=brick_uri
) )
@classmethod @classmethod
def run_refresh_brick_viewer(cls): def run_refresh_brick_viewer(cls):
return blenderbim.core.brick.refresh_brick_viewer(tool.Brick) return core_brick.refresh_brick_viewer(tool.Brick)
@classmethod @classmethod
def run_view_brick_class(cls, brick_class=None, split_screen=False): def run_view_brick_class(cls, brick_class=None, split_screen=False):
return blenderbim.core.brick.view_brick_class(tool.Brick, brick_class=brick_class, split_screen=split_screen) return core_brick.view_brick_class(tool.Brick, brick_class=brick_class, split_screen=split_screen)
@classmethod @classmethod
def select_browser_item(cls, item, split_screen=False): def select_browser_item(cls, item, split_screen=False):
+3 -2
View File
@@ -18,6 +18,7 @@
import bpy import bpy
import ifcopenshell.util.system import ifcopenshell.util.system
from ..bim import helper as bim_helper
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
from ..bim import import_ifc from ..bim import import_ifc
@@ -54,7 +55,7 @@ class Document(core_tool.Document):
@classmethod @classmethod
def export_document_attributes(cls): def export_document_attributes(cls):
return blenderbim.bim.helper.export_attributes(bpy.context.scene.BIMDocumentProperties.document_attributes) return bim_helper.export_attributes(bpy.context.scene.BIMDocumentProperties.document_attributes)
@classmethod @classmethod
def get_active_breadcrumb(cls): def get_active_breadcrumb(cls):
@@ -66,7 +67,7 @@ class Document(core_tool.Document):
def import_document_attributes(cls, document): def import_document_attributes(cls, document):
props = bpy.context.scene.BIMDocumentProperties props = bpy.context.scene.BIMDocumentProperties
props.document_attributes.clear() props.document_attributes.clear()
blenderbim.bim.helper.import_attributes2(document, props.document_attributes) bim_helper.import_attributes2(document, props.document_attributes)
@classmethod @classmethod
def import_project_documents(cls): def import_project_documents(cls):
+14 -13
View File
@@ -31,6 +31,7 @@ import platform
import mathutils import mathutils
import subprocess import subprocess
import numpy as np import numpy as np
from ..bim import helper as bim_helper
from ..core import tool as core_tool from ..core import tool as core_tool
from ..core import geometry as core_geometry from ..core import geometry as core_geometry
from .. import tool from .. import tool
@@ -95,7 +96,7 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def create_annotation_object(cls, drawing: ifcopenshell.entity_instance, object_type: str) -> bpy.types.Object: def create_annotation_object(cls, drawing: ifcopenshell.entity_instance, object_type: str) -> bpy.types.Object:
import blenderbim.bim.module.drawing.annotation as annotation from ..bim.module.drawing import annotation
data_type = cls.get_annotation_data_type(object_type) data_type = cls.get_annotation_data_type(object_type)
obj = annotation.Annotator.get_annotation_obj(drawing, object_type, data_type) obj = annotation.Annotator.get_annotation_obj(drawing, object_type, data_type)
@@ -258,7 +259,7 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def create_svg_schedule(cls, schedule): def create_svg_schedule(cls, schedule):
import blenderbim.bim.module.drawing.scheduler as scheduler from ..bim.module.drawing import scheduler
schedule_creator = scheduler.Scheduler() schedule_creator = scheduler.Scheduler()
schedule_creator.schedule( schedule_creator.schedule(
@@ -267,7 +268,7 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def create_svg_sheet(cls, document: ifcopenshell.entity_instance, titleblock: str) -> str: def create_svg_sheet(cls, document: ifcopenshell.entity_instance, titleblock: str) -> str:
import blenderbim.bim.module.drawing.sheeter as sheeter from ..bim.module.drawing import sheeter
sheet_builder = sheeter.SheetBuilder() sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
@@ -277,7 +278,7 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def add_drawings(cls, sheet): def add_drawings(cls, sheet):
import blenderbim.bim.module.drawing.sheeter as sheeter from ..bim.module.drawing import sheeter
sheet_builder = sheeter.SheetBuilder() sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
@@ -390,7 +391,7 @@ class Drawing(core_tool.Drawing):
def export_text_literal_attributes(cls, obj: bpy.types.Object) -> list[dict[str, Any]]: def export_text_literal_attributes(cls, obj: bpy.types.Object) -> list[dict[str, Any]]:
literals = [] literals = []
for literal_props in obj.BIMTextProperties.literals: for literal_props in obj.BIMTextProperties.literals:
literal_data = blenderbim.bim.helper.export_attributes(literal_props.attributes) literal_data = bim_helper.export_attributes(literal_props.attributes)
literals.append(literal_data) literals.append(literal_data)
return literals return literals
@@ -734,7 +735,7 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def import_camera_props(cls, drawing: ifcopenshell.entity_instance, obj: bpy.types.Object) -> None: def import_camera_props(cls, drawing: ifcopenshell.entity_instance, obj: bpy.types.Object) -> None:
from blenderbim.bim.module.drawing.prop import get_diagram_scales from ..bim.module.drawing.prop import get_diagram_scales
# Temporarily clear the definition id to prevent prop update callbacks to IFC. # Temporarily clear the definition id to prevent prop update callbacks to IFC.
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
@@ -874,14 +875,14 @@ class Drawing(core_tool.Drawing):
@classmethod @classmethod
def import_text_attributes(cls, obj: bpy.types.Object) -> None: def import_text_attributes(cls, obj: bpy.types.Object) -> None:
from blenderbim.bim.module.drawing.prop import BOX_ALIGNMENT_POSITIONS from ..bim.module.drawing.prop import BOX_ALIGNMENT_POSITIONS
props = obj.BIMTextProperties props = obj.BIMTextProperties
props.literals.clear() props.literals.clear()
for ifc_literal in cls.get_text_literal(obj, return_list=True): for ifc_literal in cls.get_text_literal(obj, return_list=True):
literal_props = props.literals.add() literal_props = props.literals.add()
blenderbim.bim.helper.import_attributes2(ifc_literal, literal_props.attributes) bim_helper.import_attributes2(ifc_literal, literal_props.attributes)
box_alignment_mask = [False] * 9 box_alignment_mask = [False] * 9
position_string = literal_props.attributes["BoxAlignment"].string_value position_string = literal_props.attributes["BoxAlignment"].string_value
@@ -889,7 +890,7 @@ class Drawing(core_tool.Drawing):
literal_props.box_alignment = box_alignment_mask literal_props.box_alignment = box_alignment_mask
literal_props.ifc_definition_id = ifc_literal.id() literal_props.ifc_definition_id = ifc_literal.id()
from blenderbim.bim.module.drawing.data import DecoratorData from ..bim.module.drawing.data import DecoratorData
text_data = DecoratorData.get_ifc_text_data(obj) text_data = DecoratorData.get_ifc_text_data(obj)
props.font_size = str(text_data["FontSize"]) props.font_size = str(text_data["FontSize"])
@@ -979,7 +980,7 @@ class Drawing(core_tool.Drawing):
"""updates pset `EPset_Annotation.Classes` value """updates pset `EPset_Annotation.Classes` value
based on current font size from `obj.BIMTextProperties.font_size` based on current font size from `obj.BIMTextProperties.font_size`
""" """
from blenderbim.bim.module.drawing.data import FONT_SIZES from ..bim.module.drawing.data import FONT_SIZES
props = obj.BIMTextProperties props = obj.BIMTextProperties
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
@@ -1185,7 +1186,7 @@ class Drawing(core_tool.Drawing):
reference_element: ifcopenshell.entity_instance, reference_element: ifcopenshell.entity_instance,
context: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance,
) -> ifcopenshell.entity_instance: ) -> ifcopenshell.entity_instance:
import blenderbim.bim.module.drawing.helper as helper from ..bim.module.drawing import helper
camera = tool.Ifc.get_object(drawing) camera = tool.Ifc.get_object(drawing)
bounds = helper.ortho_view_frame(camera.data) if camera.data.type == "ORTHO" else None bounds = helper.ortho_view_frame(camera.data) if camera.data.type == "ORTHO" else None
@@ -1252,7 +1253,7 @@ class Drawing(core_tool.Drawing):
reference_element: ifcopenshell.entity_instance, reference_element: ifcopenshell.entity_instance,
context: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance,
) -> ifcopenshell.entity_instance: ) -> ifcopenshell.entity_instance:
import blenderbim.bim.module.drawing.helper as helper from ..bim.module.drawing import helper
reference_obj = tool.Ifc.get_object(reference_element) reference_obj = tool.Ifc.get_object(reference_element)
reference_obj.matrix_world reference_obj.matrix_world
@@ -1376,7 +1377,7 @@ class Drawing(core_tool.Drawing):
reference_element: ifcopenshell.entity_instance, reference_element: ifcopenshell.entity_instance,
context: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance,
) -> ifcopenshell.entity_instance: ) -> ifcopenshell.entity_instance:
import blenderbim.bim.module.drawing.helper as helper from ..bim.module.drawing import helper
target_view = tool.Drawing.get_drawing_target_view(drawing) target_view = tool.Drawing.get_drawing_target_view(drawing)
+2 -2
View File
@@ -133,7 +133,7 @@ class Ifc(core_tool.Ifc):
if global_id: if global_id:
IfcStore.guid_map[global_id] = obj IfcStore.guid_map[global_id] = obj
blenderbim.bim.handler.subscribe_to(obj, "name", bim_handler.name_callback) bim_handler.subscribe_to(obj, "name", bim_handler.name_callback)
bim_handler.subscribe_to( bim_handler.subscribe_to(
obj, "active_material_index", bim_handler.active_material_index_callback obj, "active_material_index", bim_handler.active_material_index_callback
) )
@@ -151,7 +151,7 @@ class Ifc(core_tool.Ifc):
if style: if style:
IfcStore.id_map[style.id()] = obj IfcStore.id_map[style.id()] = obj
blenderbim.bim.handler.subscribe_to(obj, "name", bim_handler.name_callback) bim_handler.subscribe_to(obj, "name", bim_handler.name_callback)
@classmethod @classmethod
def link(cls, element: ifcopenshell.entity_instance, obj: IFC_CONNECTED_TYPE) -> None: def link(cls, element: ifcopenshell.entity_instance, obj: IFC_CONNECTED_TYPE) -> None:
+5 -4
View File
@@ -17,6 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
from ..bim import helper as bim_helper
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
@@ -29,12 +30,12 @@ class Library(core_tool.Library):
@classmethod @classmethod
def export_library_attributes(cls): def export_library_attributes(cls):
props = bpy.context.scene.BIMLibraryProperties props = bpy.context.scene.BIMLibraryProperties
return blenderbim.bim.helper.export_attributes(props.library_attributes) return bim_helper.export_attributes(props.library_attributes)
@classmethod @classmethod
def export_reference_attributes(cls): def export_reference_attributes(cls):
props = bpy.context.scene.BIMLibraryProperties props = bpy.context.scene.BIMLibraryProperties
return blenderbim.bim.helper.export_attributes(props.reference_attributes) return bim_helper.export_attributes(props.reference_attributes)
@classmethod @classmethod
def get_active_library(cls): def get_active_library(cls):
@@ -48,13 +49,13 @@ class Library(core_tool.Library):
def import_library_attributes(cls, library): def import_library_attributes(cls, library):
props = bpy.context.scene.BIMLibraryProperties props = bpy.context.scene.BIMLibraryProperties
props.library_attributes.clear() props.library_attributes.clear()
blenderbim.bim.helper.import_attributes2(library, props.library_attributes) bim_helper.import_attributes2(library, props.library_attributes)
@classmethod @classmethod
def import_reference_attributes(cls, reference): def import_reference_attributes(cls, reference):
props = bpy.context.scene.BIMLibraryProperties props = bpy.context.scene.BIMLibraryProperties
props.reference_attributes.clear() props.reference_attributes.clear()
blenderbim.bim.helper.import_attributes2(reference, props.reference_attributes) bim_helper.import_attributes2(reference, props.reference_attributes)
@classmethod @classmethod
def import_references(cls, library): def import_references(cls, library):
+1 -1
View File
@@ -31,7 +31,7 @@ from typing import Union, Any, TYPE_CHECKING, Optional
if TYPE_CHECKING: if TYPE_CHECKING:
# Avoid circular imports. # Avoid circular imports.
from blenderbim.bim.module.material.prop import Material as MaterialItem from ..bim.module.material.prop import Material as MaterialItem
class Material(core_tool.Material): class Material(core_tool.Material):
+1 -2
View File
@@ -31,7 +31,6 @@ import ifcopenshell.util.representation
from ..core import geometry as core_geometry from ..core import geometry as core_geometry
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
from ..core. import geometry
from math import atan, degrees from math import atan, degrees
from mathutils import Matrix, Vector from mathutils import Matrix, Vector
from copy import deepcopy from copy import deepcopy
@@ -762,7 +761,7 @@ class Model(core_tool.Model):
ifcopenshell.api.run( ifcopenshell.api.run(
"geometry.assign_representation", ifc_file, product=ifc_element, representation=new_representation "geometry.assign_representation", ifc_file, product=ifc_element, representation=new_representation
) )
geometry.switch_representation( core_geometry.switch_representation(
tool.Ifc, tool.Ifc,
tool.Geometry, tool.Geometry,
obj=obj, obj=obj,
+2 -1
View File
@@ -21,6 +21,7 @@ import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.util.representation import ifcopenshell.util.representation
import ifcopenshell.util.unit import ifcopenshell.util.unit
from ..bim import handler as bim_handler
from ..core import aggregate as core_aggregate from ..core import aggregate as core_aggregate
from ..core import context as core_context from ..core import context as core_context
from ..core import tool as core_tool from ..core import tool as core_tool
@@ -122,7 +123,7 @@ class Project(core_tool.Project):
@classmethod @classmethod
def set_context(cls, context): def set_context(cls, context):
blenderbim.bim.handler.refresh_ui_data() bim_handler.refresh_ui_data()
bpy.context.scene.BIMRootProperties.contexts = str(context.id()) bpy.context.scene.BIMRootProperties.contexts = str(context.id())
@classmethod @classmethod
+2 -1
View File
@@ -19,6 +19,7 @@
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element import ifcopenshell.util.element
from ..bim import helper as bim_helper
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
from ..bim import schema as bim_schema from ..bim import schema as bim_schema
@@ -204,7 +205,7 @@ class Pset(core_tool.Pset):
metadata.bool_value = False if metadata.is_null else bool(data[prop_template.Name]) metadata.bool_value = False if metadata.is_null else bool(data[prop_template.Name])
metadata.ifc_class = pset_template.Name metadata.ifc_class = pset_template.Name
blenderbim.bim.helper.add_attribute_description(metadata, prop_template) bim_helper.add_attribute_description(metadata, prop_template)
@classmethod @classmethod
def import_pset_from_template(cls, pset_template, pset, props): def import_pset_from_template(cls, pset_template, pset, props):
-2
View File
@@ -127,8 +127,6 @@ class Qto(core_tool.Qto):
Example: Example:
.. code::Python .. code::Python
import blenderbim.tool as tool
relating_cost_items = tool.Qto.relating_cost_items(my_beautiful_wall) relating_cost_items = tool.Qto.relating_cost_items(my_beautiful_wall)
for relating_cost_item in relating_cost_items: for relating_cost_item in relating_cost_items:
print(f"RELATING COST ITEM NAME: {relating_cost_item["cost_item_name"]}") print(f"RELATING COST ITEM NAME: {relating_cost_item["cost_item_name"]}")
+1 -1
View File
@@ -22,7 +22,7 @@ import bpy
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
from ..bim import helper as bim_helper from ..bim import helper as bim_helper
from ..bim.module.sequence. import helper from ..bim.module.sequence import helper
import json import json
import time import time
import isodate import isodate
+1 -1
View File
@@ -33,7 +33,7 @@ from ..core import tool as core_tool
from .. import core as core from .. import core as core
from .. import tool from .. import tool
from ..bim import helper as bim_helper from ..bim import helper as bim_helper
from ..bim.module.sequence. import helper from ..bim.module.sequence import helper
from dateutil import parser from dateutil import parser
from datetime import datetime from datetime import datetime
from typing import Optional, Any, Union from typing import Optional, Any, Union
+3 -2
View File
@@ -19,6 +19,7 @@
import bpy import bpy
import json import json
import ifcopenshell import ifcopenshell
from ..bim import helper as bim_helper
from ..core import tool as core_tool from ..core import tool as core_tool
from .. import tool from .. import tool
@@ -47,7 +48,7 @@ class Unit(core_tool.Unit):
return True return True
props = bpy.context.scene.BIMUnitProperties props = bpy.context.scene.BIMUnitProperties
return blenderbim.bim.helper.export_attributes(props.unit_attributes, callback=callback) return bim_helper.export_attributes(props.unit_attributes, callback=callback)
@classmethod @classmethod
def get_scene_unit_name(cls, unit_type): def get_scene_unit_name(cls, unit_type):
@@ -95,7 +96,7 @@ class Unit(core_tool.Unit):
props = bpy.context.scene.BIMUnitProperties props = bpy.context.scene.BIMUnitProperties
props.unit_attributes.clear() props.unit_attributes.clear()
blenderbim.bim.helper.import_attributes2(unit, props.unit_attributes, callback=callback) bim_helper.import_attributes2(unit, props.unit_attributes, callback=callback)
@classmethod @classmethod
def import_units(cls): def import_units(cls):