Allow export of objects for spatial tree

This commit is contained in:
Dion Moult
2020-01-28 22:06:58 +11:00
parent 5a3303837d
commit 52fae93a14
+39 -22
View File
@@ -76,6 +76,7 @@ class IfcParser():
self.ifc_export_settings = ifc_export_settings
self.selected_products = []
self.selected_spatial_structure_elements = []
self.product_index = 0
self.product_name_index_map = {}
@@ -128,7 +129,7 @@ class IfcParser():
self.unit_scale = self.get_unit_scale()
self.people = self.get_people()
self.organisations = self.get_organisations()
self.convert_selected_objects_into_products(bpy.context.selected_objects)
self.categorise_selected_objects(bpy.context.selected_objects)
self.psets = self.get_psets()
self.material_psets = self.get_material_psets()
self.documents = self.get_documents()
@@ -352,11 +353,8 @@ class IfcParser():
if product['raw'].name == name:
return index
def get_product(self, selected_product, metadata_override={}, attribute_override={}):
obj = selected_product['raw']
product = {
'ifc': None,
'raw': obj,
def append_product_attributes(self, product, obj):
product.update({
'location': obj.matrix_world.translation,
'up_axis': self.get_axis(obj.matrix_world, 2),
'forward_axis': self.get_axis(obj.matrix_world, 0),
@@ -365,17 +363,25 @@ class IfcParser():
'has_mirror': False,
'array_offset': Vector((0, 0, 0)),
'scale': obj.scale,
'representations': self.get_object_representation_names(obj)
})
def get_product(self, selected_product, metadata_override={}, attribute_override={}):
obj = selected_product['raw']
product = {
'ifc': None,
'raw': obj,
'class': self.get_ifc_class(obj.name),
'relating_structure': None,
'relating_host': None,
'relating_qtos_key': None,
'representations': self.get_object_representation_names(obj),
'attributes': self.get_object_attributes(obj),
'has_boundary_condition': obj.BIMObjectProperties.has_boundary_condition,
'boundary_condition_class': None,
'boundary_condition_attributes': {},
'structural_member_connection': None
}
self.append_product_attributes(product, obj)
product['attributes'].update(attribute_override)
product.update(metadata_override)
@@ -499,16 +505,18 @@ class IfcParser():
if child.name == child_collection.name:
return parent_collection
def convert_selected_objects_into_products(self, objects_to_sort, metadata=None):
def categorise_selected_objects(self, objects_to_sort, metadata=None):
if not metadata:
metadata = {}
for obj in objects_to_sort:
if obj.name[0:3] != 'Ifc':
continue
if not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
elif obj.users_collection and obj.users_collection[0].name == obj.name:
self.selected_spatial_structure_elements.append({'raw': obj, 'metadata': metadata})
elif not self.is_a_library(self.get_ifc_class(obj.users_collection[0].name)):
self.selected_products.append({'raw': obj, 'metadata': metadata})
if obj.instance_type == 'COLLECTION':
self.convert_selected_objects_into_products(
elif obj.instance_type == 'COLLECTION':
self.categorise_selected_objects(
obj.instance_collection.objects,
{'rel_aggregates_relating_object': obj}
)
@@ -706,12 +714,17 @@ class IfcParser():
elements = []
for collection in bpy.data.collections:
if self.is_a_spatial_structure_element(self.get_ifc_class(collection.name)):
elements.append({
raw = bpy.data.objects.get(collection.name)
if not raw:
raw = collection
element = {
'ifc': None,
'raw': collection,
'class': self.get_ifc_class(collection.name),
'attributes': self.get_object_attributes(collection)
})
'raw': raw,
'class': self.get_ifc_class(raw.name),
'attributes': self.get_object_attributes(raw)
}
self.append_product_attributes(element, raw)
elements.append(element)
return elements
def get_structural_analysis_models(self):
@@ -729,7 +742,9 @@ class IfcParser():
def load_representations(self):
if not self.ifc_export_settings.has_representations:
return
for product in self.selected_products + self.type_products:
for product in self.selected_products \
+ self.type_products \
+ self.selected_spatial_structure_elements:
self.load_product_representations(product)
def load_product_representations(self, product):
@@ -1491,7 +1506,8 @@ class IfcExporter():
element = self.ifc_parser.spatial_structure_elements[node['reference']]
element['attributes'].update({
'OwnerHistory': self.owner_history, # TODO: unhardcode
'ObjectPlacement': self.file.createIfcLocalPlacement(placement_rel_to, self.origin)
'ObjectPlacement': self.file.createIfcLocalPlacement(placement_rel_to, self.origin),
'Representation': self.get_product_shape(element)
})
element['ifc'] = self.file.create_entity(element['class'], **element['attributes'])
related_objects.append(element['ifc'])
@@ -1682,11 +1698,12 @@ class IfcExporter():
def get_product_shape(self, product):
try:
shape = self.file.createIfcProductDefinitionShape(None, None,
self.get_product_shape_representations(product))
representations = self.get_product_shape_representations(product)
if representations:
return self.file.createIfcProductDefinitionShape(None, None, representations)
except:
shape = None
return shape
pass
return None
def get_product_shape_representations(self, product):
results = []