Editing IfcOpenShell code examples
From Wiki.OSArch
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 10: | Line 10: | ||
import ifcopenshell | import ifcopenshell | ||
ifc = ifcopenshell.open('/path/to/your/file.ifc') | ifc = ifcopenshell.open('/path/to/your/file.ifc') | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 199: | Line 191: | ||
The usage of IfcOpenShell for geometry processing is currently considered to be moderate to advanced. There are two approaches to processing geometry. One approach is to traverse the <code>Representation</code> attribute of the IFC element, and parse it yourself. This requires an in-depth understanding of IFC geometric representations, as well as its many caveats with units and transformations, but can be very simple to extract specific types of geometry. The second approach is to use IfcOpenShell's shape processing features, which will convert almost all IFC representations into a triangulated mesh. Regardless of the source format, once it is in a mesh representation, you may use standard mesh geometry processing algorithms to analyse the geometry. This makes it easier to write generic code for any representation, but may be harder to extract certain geometric features. | The usage of IfcOpenShell for geometry processing is currently considered to be moderate to advanced. There are two approaches to processing geometry. One approach is to traverse the <code>Representation</code> attribute of the IFC element, and parse it yourself. This requires an in-depth understanding of IFC geometric representations, as well as its many caveats with units and transformations, but can be very simple to extract specific types of geometry. The second approach is to use IfcOpenShell's shape processing features, which will convert almost all IFC representations into a triangulated mesh. Regardless of the source format, once it is in a mesh representation, you may use standard mesh geometry processing algorithms to analyse the geometry. This makes it easier to write generic code for any representation, but may be harder to extract certain geometric features. | ||
− | + | Note: this article is a work in progress. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | TODO: talk about [https://github.com/IfcOpenShell/IfcOpenShell/issues/866 naming in ids]. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
Line 240: | Line 208: | ||
iterator = ifcopenshell.geom.iterator(settings, ifc_file, multiprocessing.cpu_count()) | iterator = ifcopenshell.geom.iterator(settings, ifc_file, multiprocessing.cpu_count()) | ||
if iterator.initialize(): | if iterator.initialize(): | ||
− | while | + | while iterator.next(): |
shape = iterator.get() | shape = iterator.get() | ||
element = ifc_file.by_guid(shape.guid) | element = ifc_file.by_guid(shape.guid) | ||
Line 251: | Line 219: | ||
grouped_verts = [[verts[i], verts[i + 1], verts[i + 2]] for i in range(0, len(verts), 3)] | grouped_verts = [[verts[i], verts[i + 1], verts[i + 2]] for i in range(0, len(verts), 3)] | ||
grouped_faces = [[faces[i], faces[i + 1], faces[i + 2]] for i in range(0, len(faces), 3)] | grouped_faces = [[faces[i], faces[i + 1], faces[i + 2]] for i in range(0, len(faces), 3)] | ||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
=IFC Query Syntax= | =IFC Query Syntax= | ||
Line 326: | Line 289: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Exploring IFC schema= | =Exploring IFC schema= | ||
Line 387: | Line 340: | ||
<entity IfcFlowSegment> | <entity IfcFlowSegment> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Get subtypes : | Get subtypes : | ||
Line 413: | Line 350: | ||
<entity IfcPipeSegment>) | <entity IfcPipeSegment>) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
=Property and quantity sets (Pset and Qto)= | =Property and quantity sets (Pset and Qto)= | ||
Line 467: | Line 403: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Date and time in IFC= | =Date and time in IFC= | ||
Date and time conversion can be error prone. Fortunately IFC has chosen wide used definitions so standard python [https://docs.python.org/3/library/datetime.html datetime] and [https://docs.python.org/3/library/time.html time] modules have tools to handle most of them. | Date and time conversion can be error prone. Fortunately IFC has chosen wide used definitions so standard python [https://docs.python.org/3/library/datetime.html datetime] and [https://docs.python.org/3/library/time.html time] modules have tools to handle most of them. |