Reputation: 1086
In the project I am currently working on, I have a task to use an IFC file to read data and save it in a database. I am using ifcopenshell to read the data. However, in the IFC file, I could not figure out how to get the geometry and dimension data. Can anyone help me with this, please?
def extract_geometry(entity):
geometry_data = []
if hasattr(entity, 'Representation'):
representation = entity.Representation
for item in \
(representation.Items if representation.Items else []):
if hasattr(item, 'Representation'):
geometry_data.append({'type': item.is_a(),
'geometry_data': item.Representation.get_info()}) # Get geometry data
return geometry_data
def parse_ifc_structure(ifc_file_path, type):
ifc_file = ifcopenshell.open(ifc_file_path)
entities_data = []
for entity in ifc_file.by_type(type):
entity_data = {
'id': entity.id(),
'global_id': (entity.GlobalId if hasattr(entity, 'GlobalId'
) else None),
'LongName': (entity.LongName if hasattr(entity, 'LongName'
) else None),
'Name': (entity.Name if hasattr(entity, 'Name') else None),
'Phase': (entity.Phase if hasattr(entity, 'Phase'
) else None),
'CompositionType': (entity.CompositionType if hasattr(entity,
'CompositionType') else None),
'type': entity.is_a(),
'geometry': extract_geometry(entity),
'Representation': (entity.Representation if hasattr(entity,
'Representation') else None),
'ObjectPlacement': (entity.Representation if hasattr(entity,
'ObjectPlacement') else None),
}
# "Placement": entity.Representation if hasattr(entity, "Placement") else None,
entities_data.append(entity_data)
return entities_data
This is the code I have but extract_geometry does not retrieve the values (x,y,z) mentioned in the screen shot.
Upvotes: 0
Views: 114