mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 14:33:28 +00:00
IFC import now supports IFC attributes
This commit is contained in:
@@ -1,8 +1,19 @@
|
|||||||
from . import ifcopenshell
|
from . import ifcopenshell
|
||||||
from .ifcopenshell import geom
|
from .ifcopenshell import geom
|
||||||
import bpy
|
import bpy
|
||||||
|
import os
|
||||||
|
import json
|
||||||
import mathutils
|
import mathutils
|
||||||
|
|
||||||
|
cwd = os.path.dirname(os.path.realpath(__file__)) + os.path.sep
|
||||||
|
|
||||||
|
class IfcSchema():
|
||||||
|
def __init__(self):
|
||||||
|
with open('{}ifc_elements_IFC4.json'.format(cwd + 'schema/')) as f:
|
||||||
|
self.elements = json.load(f)
|
||||||
|
|
||||||
|
ifc_schema = IfcSchema()
|
||||||
|
|
||||||
class MaterialCreator():
|
class MaterialCreator():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mesh = None
|
self.mesh = None
|
||||||
@@ -107,6 +118,7 @@ class IfcImporter():
|
|||||||
return '{}/{}'.format(element.is_a(), element.Name)
|
return '{}/{}'.format(element.is_a(), element.Name)
|
||||||
|
|
||||||
def create_object(self, element):
|
def create_object(self, element):
|
||||||
|
print('Creating object {}'.format(element))
|
||||||
if element.is_a('IfcOpeningElement'):
|
if element.is_a('IfcOpeningElement'):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -122,8 +134,6 @@ class IfcImporter():
|
|||||||
if mesh is None:
|
if mesh is None:
|
||||||
mesh = self.create_mesh(element, shape)
|
mesh = self.create_mesh(element, shape)
|
||||||
self.meshes[mesh_name] = mesh
|
self.meshes[mesh_name] = mesh
|
||||||
else:
|
|
||||||
print('we reused a mesh!')
|
|
||||||
|
|
||||||
for association in element.HasAssociations:
|
for association in element.HasAssociations:
|
||||||
if association.is_a('IfcRelAssociatesMaterial'):
|
if association.is_a('IfcRelAssociatesMaterial'):
|
||||||
@@ -140,6 +150,18 @@ class IfcImporter():
|
|||||||
matrix.transpose()
|
matrix.transpose()
|
||||||
object.matrix_world = matrix
|
object.matrix_world = matrix
|
||||||
|
|
||||||
|
attributes = element.get_info()
|
||||||
|
if element.is_a() in ifc_schema.elements:
|
||||||
|
applicable_attributes = [a['name'] for a in ifc_schema.elements[element.is_a()]['attributes']]
|
||||||
|
for key, value in attributes.items():
|
||||||
|
if key not in applicable_attributes \
|
||||||
|
or value is None:
|
||||||
|
continue
|
||||||
|
attribute = object.BIMObjectProperties.attributes.add()
|
||||||
|
attribute.name = key
|
||||||
|
attribute.data_type = 'string'
|
||||||
|
attribute.string_value = str(value)
|
||||||
|
|
||||||
if hasattr(element, 'ContainedInStructure') \
|
if hasattr(element, 'ContainedInStructure') \
|
||||||
and element.ContainedInStructure \
|
and element.ContainedInStructure \
|
||||||
and element.ContainedInStructure[0].RelatingStructure:
|
and element.ContainedInStructure[0].RelatingStructure:
|
||||||
@@ -147,6 +169,7 @@ class IfcImporter():
|
|||||||
if structure_name in self.spatial_structure_elements:
|
if structure_name in self.spatial_structure_elements:
|
||||||
self.spatial_structure_elements[structure_name]['blender'].objects.link(object)
|
self.spatial_structure_elements[structure_name]['blender'].objects.link(object)
|
||||||
else:
|
else:
|
||||||
|
print('Warning: this object is outside the spatial hierarchy')
|
||||||
bpy.context.scene.collection.objects.link(object)
|
bpy.context.scene.collection.objects.link(object)
|
||||||
|
|
||||||
def get_representation_id(self, element):
|
def get_representation_id(self, element):
|
||||||
|
|||||||
@@ -183,7 +183,9 @@ class ApproveClass(bpy.types.Operator):
|
|||||||
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
||||||
for object in bpy.context.selected_objects:
|
for object in bpy.context.selected_objects:
|
||||||
file.write('Then the element {} is an {}\n'.format(
|
file.write('Then the element {} is an {}\n'.format(
|
||||||
object['IfcGlobalId'], object.name.split('/')[0]))
|
object.BIMObjectProperties.attributes[
|
||||||
|
object.BIMObjectProperties.attributes.find('GlobalId')].string_value,
|
||||||
|
object.name.split('/')[0]))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class RejectClass(bpy.types.Operator):
|
class RejectClass(bpy.types.Operator):
|
||||||
@@ -194,7 +196,9 @@ class RejectClass(bpy.types.Operator):
|
|||||||
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
||||||
for object in bpy.context.selected_objects:
|
for object in bpy.context.selected_objects:
|
||||||
file.write('Then the element {} is an {}\n'.format(
|
file.write('Then the element {} is an {}\n'.format(
|
||||||
object['IfcGlobalId'], bpy.context.scene.BIMProperties.ifc_class))
|
object.BIMObjectProperties.attributes[
|
||||||
|
object.BIMObjectProperties.attributes.find('GlobalId')].string_value,
|
||||||
|
bpy.context.scene.BIMProperties.ifc_class))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class RejectElement(bpy.types.Operator):
|
class RejectElement(bpy.types.Operator):
|
||||||
@@ -205,7 +209,9 @@ class RejectElement(bpy.types.Operator):
|
|||||||
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt', 'a') as file:
|
||||||
for object in bpy.context.selected_objects:
|
for object in bpy.context.selected_objects:
|
||||||
file.write('Then the element {} should not exist because {}\n'.format(
|
file.write('Then the element {} should not exist because {}\n'.format(
|
||||||
object['IfcGlobalId'], bpy.context.scene.BIMProperties.qa_reject_element_reason))
|
object.BIMObjectProperties.attributes[
|
||||||
|
object.BIMObjectProperties.attributes.find('GlobalId')].string_value,
|
||||||
|
bpy.context.scene.BIMProperties.qa_reject_element_reason))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class SelectAudited(bpy.types.Operator):
|
class SelectAudited(bpy.types.Operator):
|
||||||
@@ -216,8 +222,9 @@ class SelectAudited(bpy.types.Operator):
|
|||||||
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt') as file:
|
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt') as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
for object in bpy.context.visible_objects:
|
for object in bpy.context.visible_objects:
|
||||||
if 'IfcGlobalId' in object.keys() \
|
index = object.BIMObjectProperties.attributes.find('GlobalId')
|
||||||
and object['IfcGlobalId'] == line.split(' ')[3]:
|
if index != -1 \
|
||||||
|
and object.BIMObjectProperties.attributes[index].string_value == line.split(' ')[3]:
|
||||||
object.select_set(True)
|
object.select_set(True)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user