mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
You can now import materials from a project library
This commit is contained in:
@@ -172,9 +172,10 @@ class RefreshLibrary(bpy.types.Operator):
|
||||
self.props.active_library_element = ""
|
||||
|
||||
types = IfcStore.library_file.wrapped_data.types_with_super()
|
||||
if "IfcTypeProduct" in types:
|
||||
new = self.props.library_elements.add()
|
||||
new.name = "IfcTypeProduct"
|
||||
for importable_type in ["IfcTypeProduct", "IfcMaterial"]:
|
||||
if importable_type in types:
|
||||
new = self.props.library_elements.add()
|
||||
new.name = importable_type
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -201,7 +202,9 @@ class ChangeLibraryElement(bpy.types.Operator):
|
||||
new.ifc_definition_id = element.id()
|
||||
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
||||
new.is_declared = False
|
||||
elif element.HasContext and element.HasContext[0].RelatingContext.is_a("IfcProjectLibrary"):
|
||||
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a(
|
||||
"IfcProjectLibrary"
|
||||
):
|
||||
new.is_declared = True
|
||||
else:
|
||||
for ifc_class in ifc_classes:
|
||||
@@ -328,10 +331,22 @@ class AppendLibraryElement(bpy.types.Operator):
|
||||
)
|
||||
if not element:
|
||||
return {"FINISHED"}
|
||||
self.import_type_from_ifc(element, context)
|
||||
if element.is_a("IfcTypeProduct"):
|
||||
self.import_type_from_ifc(element, context)
|
||||
elif element.is_a("IfcMaterial"):
|
||||
self.import_material_from_ifc(element, context)
|
||||
blenderbim.bim.handler.purge_module_data()
|
||||
return {"FINISHED"}
|
||||
|
||||
def import_material_from_ifc(self, element, context):
|
||||
self.file = IfcStore.get_file()
|
||||
logger = logging.getLogger("ImportIFC")
|
||||
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
|
||||
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
||||
ifc_importer.file = self.file
|
||||
blender_material = ifc_importer.create_material(element)
|
||||
self.import_material_styles(blender_material, element, ifc_importer)
|
||||
|
||||
def import_type_from_ifc(self, element, context):
|
||||
self.file = IfcStore.get_file()
|
||||
logger = logging.getLogger("ImportIFC")
|
||||
|
||||
@@ -18,6 +18,13 @@ class Usecase:
|
||||
except:
|
||||
pass
|
||||
return self.append_type_product()
|
||||
elif self.settings["element"].is_a("IfcMaterial"):
|
||||
if [e for e in self.file.by_type("IfcMaterial") if e.Name == self.settings["element"].Name]:
|
||||
return
|
||||
return self.append_material()
|
||||
|
||||
def append_material(self):
|
||||
return self.file.add(self.settings["element"])
|
||||
|
||||
def append_type_product(self):
|
||||
self.whitelisted_inverse_attributes = {
|
||||
|
||||
@@ -17,6 +17,9 @@ class Usecase:
|
||||
if self.settings["relating_context"].Declares:
|
||||
declares = self.settings["relating_context"].Declares[0]
|
||||
|
||||
if not hasattr(self.settings["definition"], "HasContext"):
|
||||
return
|
||||
|
||||
has_context = None
|
||||
if self.settings["definition"].HasContext:
|
||||
has_context = self.settings["definition"].HasContext[0]
|
||||
|
||||
Reference in New Issue
Block a user