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) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
=IFC Query Syntax= | =IFC Query Syntax= | ||
Line 326: | Line 281: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Exploring IFC schema= | =Exploring IFC schema= | ||
Line 387: | Line 332: | ||
<entity IfcFlowSegment> | <entity IfcFlowSegment> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Get subtypes : | Get subtypes : | ||
Line 413: | Line 342: | ||
<entity IfcPipeSegment>) | <entity IfcPipeSegment>) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
=Property and quantity sets (Pset and Qto)= | =Property and quantity sets (Pset and Qto)= | ||
Line 467: | Line 395: | ||
</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. | ||
Line 500: | Line 406: | ||
# To convert it to datetime (UTC+1 in this example) | # To convert it to datetime (UTC+1 in this example) | ||
>>> import datetime | >>> import datetime | ||
− | >>> datetime | + | >>> datetime.fromtimestamp(0) |
− | datetime. | + | datetime.datetime(1970, 1, 1, 1, 0) |
− | >>> datetime | + | >>> datetime.fromtimestamp(1610829915) |
− | datetime. | + | datetime.datetime(2021, 1, 16, 21, 45, 15) |
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
==IfcDateTime== | ==IfcDateTime== | ||
[https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2_TC1/HTML/link/ifcdatetime.htm IfcDateTime] is stored in ISO 8601 format : YYYY-MM-DDThh:mm:ss | [https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2_TC1/HTML/link/ifcdatetime.htm IfcDateTime] is stored in ISO 8601 format : YYYY-MM-DDThh:mm:ss |