mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +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 = ""
|
self.props.active_library_element = ""
|
||||||
|
|
||||||
types = IfcStore.library_file.wrapped_data.types_with_super()
|
types = IfcStore.library_file.wrapped_data.types_with_super()
|
||||||
if "IfcTypeProduct" in types:
|
for importable_type in ["IfcTypeProduct", "IfcMaterial"]:
|
||||||
new = self.props.library_elements.add()
|
if importable_type in types:
|
||||||
new.name = "IfcTypeProduct"
|
new = self.props.library_elements.add()
|
||||||
|
new.name = importable_type
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,7 +202,9 @@ class ChangeLibraryElement(bpy.types.Operator):
|
|||||||
new.ifc_definition_id = element.id()
|
new.ifc_definition_id = element.id()
|
||||||
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
||||||
new.is_declared = False
|
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
|
new.is_declared = True
|
||||||
else:
|
else:
|
||||||
for ifc_class in ifc_classes:
|
for ifc_class in ifc_classes:
|
||||||
@@ -328,10 +331,22 @@ class AppendLibraryElement(bpy.types.Operator):
|
|||||||
)
|
)
|
||||||
if not element:
|
if not element:
|
||||||
return {"FINISHED"}
|
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()
|
blenderbim.bim.handler.purge_module_data()
|
||||||
return {"FINISHED"}
|
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):
|
def import_type_from_ifc(self, element, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
logger = logging.getLogger("ImportIFC")
|
logger = logging.getLogger("ImportIFC")
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ class Usecase:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return self.append_type_product()
|
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):
|
def append_type_product(self):
|
||||||
self.whitelisted_inverse_attributes = {
|
self.whitelisted_inverse_attributes = {
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class Usecase:
|
|||||||
if self.settings["relating_context"].Declares:
|
if self.settings["relating_context"].Declares:
|
||||||
declares = self.settings["relating_context"].Declares[0]
|
declares = self.settings["relating_context"].Declares[0]
|
||||||
|
|
||||||
|
if not hasattr(self.settings["definition"], "HasContext"):
|
||||||
|
return
|
||||||
|
|
||||||
has_context = None
|
has_context = None
|
||||||
if self.settings["definition"].HasContext:
|
if self.settings["definition"].HasContext:
|
||||||
has_context = self.settings["definition"].HasContext[0]
|
has_context = self.settings["definition"].HasContext[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user