You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importifcopenshell.api.rootimportifcopenshell.api.unitimportifcopenshell.api.contextimportifcopenshell.api.projectimportifcopenshell.api.geometryimportnumpyasnp# Let's create a new project using millimeters with a single furniture element at the origin.model=ifcopenshell.api.project.create_file(version="IFC4X3")
project=ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject", name="FloorPlanner export")
# add unitsifcopenshell.api.unit.assign_unit(
model,
length={"is_metric": True, "raw": "METERS"},
area={"is_metric": True, "raw": "METERS"},
volume={"is_metric": True, "raw": "METERS"},
)
# We want our representation to be the 3D body of the element.# This representation context is only created once per project.# You must reuse the same body context every time you create a new representation.model3d=ifcopenshell.api.context.add_context(model, context_type="Model")
body=ifcopenshell.api.context.add_context(model,
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
# add site, building, storeysite=ifcopenshell.api.root.create_entity(model, ifc_class="IfcSite", name="My Site")
building=ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuilding", name="My Building")
storey=ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuildingStorey", name="My Floor")
ifcopenshell.api.aggregate.assign_object(model, relating_object=project, products=[site])
ifcopenshell.api.aggregate.assign_object(model, relating_object=site, products=[building])
ifcopenshell.api.aggregate.assign_object(model, relating_object=building, products=[storey])
I added the site, building and storey parts myself.
Why is this not mentioned in the example?
I can recreate the part with the mesh representation:
# Create our element with an object placement.element=ifcopenshell.api.root.create_entity(model, ifc_class="IfcFurniture")
ifcopenshell.api.geometry.edit_object_placement(model, product=element, matrix=np.eye(4))
vertices= [[(0.,0.,0.), (0.,2.,0.), (2.,2.,0.), (2.,0.,0.), (1.,1.,1.)]]
faces= [[(0,1,2,3), (0,4,1), (1,4,2), (2,4,3), (3,4,0)]]
representation=ifcopenshell.api.geometry.add_mesh_representation(model, context=body, vertices=vertices, faces=faces)
# extremely important!ifcopenshell.api.spatial.assign_container(model, products=[element], relating_structure=storey)
# Assign our new body representation back to our elementifcopenshell.api.geometry.assign_representation(model, product=element, representation=representation)
# write file:model.write("./representation.ifc")
Here I have my second question:
Why is the assign_container part left out in the tutorial?
Without it the mesh representation does not get displayed when I open the ifc file in bonsai.
According to this "All physical IFC model elements must be part of a hierarchical tree ..."
Now trying to create an I-Beam, I copied this part from the example:
# I-shapes are typically used in hot-rolled or welded steel. FilletRadius onwards is optional.profile=model.create_entity("IfcIShapeProfileDef", ProfileName="I-EXAMPLE", ProfileType="AREA",
OverallWidth=100, OverallDepth=200, WebThickness=10, FlangeThickness=15, FilletRadius=10)
profile_context=ifcopenshell.api.context.add_context(model,
context_type="Model", context_identifier="Profile", target_view="MODEL_VIEW", parent=model3d)
# A profile-based representation, 1 meter longrepresentation=ifcopenshell.api.geometry.add_profile_representation(model, context=body, profile=profile, depth=1)
Using:
ifcopenshell.api.spatial.assign_container(model, products=[profile], relating_structure=storey)
# Assign our new body representation back to our elementifcopenshell.api.geometry.assign_representation(model, product=representation, representation=representation)
# write file:model.write("./beam.ifc")
gives me the following error message: AttributeError: entity instance of type 'IFC4X3_ADD2.IfcIShapeProfileDef' has no attribute 'ContainedInStructure'. However when I do not use assign_container nothing gets displayed in bonsai.
So there must be some part here that is not in the example or that I must have overlooked.
It would be great if someone could point that out to me.
Thanks
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am fairly new to this and I don't understand the Profile-based Representations.
I followed the documentation and got this code:
I added the site, building and storey parts myself.
Why is this not mentioned in the example?
I can recreate the part with the mesh representation:
Here I have my second question:
Why is the
assign_container
part left out in the tutorial?Without it the mesh representation does not get displayed when I open the ifc file in bonsai.
According to this "All physical IFC model elements must be part of a hierarchical tree ..."
Now trying to create an I-Beam, I copied this part from the example:
Using:
gives me the following error message:
AttributeError: entity instance of type 'IFC4X3_ADD2.IfcIShapeProfileDef' has no attribute 'ContainedInStructure'
. However when I do not useassign_container
nothing gets displayed in bonsai.So there must be some part here that is not in the example or that I must have overlooked.
It would be great if someone could point that out to me.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions