| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | """ |
| | This module recreates the whole structure of an IFC file in FreeCAD (ie. |
| | one FreeCAD object per IFC entity). It serves mostly as a proof of concept |
| | and test to see how doable it is with large files. |
| | |
| | The geometry of objects is not imported, only attributes, which are mapped |
| | to FreeCAD properties. |
| | |
| | The IfcOpenHouse model, included with ifcopenshell, imports in 4 sec on |
| | my ryzen9 machine, for 2700 objects. Larger files like the King Arch file |
| | (20 Mb / 750 000 objects) would import in 18 minutes... |
| | """ |
| |
|
| | import time |
| |
|
| | import ifcopenshell |
| |
|
| | from PySide import QtWidgets |
| |
|
| |
|
| | class ViewProvider: |
| | """A simple view provider to gather children""" |
| |
|
| | def __init__(self, vobj): |
| | vobj.Proxy = self |
| |
|
| | def attach(self, vobj): |
| | self.Object = vobj.Object |
| |
|
| | def claimChildren(self): |
| | children = [] |
| | relprops = ["Item", "ForLayerSet"] |
| | for prop in self.Object.PropertiesList: |
| | if prop.startswith("Relating") or (prop in relprops): |
| | continue |
| | else: |
| | value = getattr(self.Object, prop) |
| | if hasattr(value, "ViewObject"): |
| | children.append(value) |
| | elif isinstance(value, list): |
| | for item in value: |
| | if hasattr(item, "ViewObject"): |
| | children.append(item) |
| | for parent in self.Object.InList: |
| | for prop in parent.PropertiesList: |
| | if prop.startswith("Relating") or (prop in relprops): |
| | value = getattr(parent, prop) |
| | if value == self.Object: |
| | children.append(parent) |
| | return children |
| |
|
| |
|
| | def create(ifcentity): |
| | """The main function that creates objects and fills properties""" |
| |
|
| | name = "Entity" + str(ifcentity.id()) |
| | obj = FreeCAD.ActiveDocument.getObject(name) |
| | if obj: |
| | return obj |
| | obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython", name) |
| | if getattr(ifcentity, "Name", None): |
| | obj.Label = ifcentity.Name |
| | else: |
| | obj.Label = ifcentity.is_a() |
| | for attr, value in ifcentity.get_info().items(): |
| | if attr not in obj.PropertiesList: |
| | if attr == "id": |
| | attr = "StepId" |
| | elif attr == "type": |
| | attr = "Type" |
| | elif attr == "Name": |
| | continue |
| | if hasattr(obj, attr): |
| | continue |
| | elif isinstance(value, int): |
| | obj.addProperty("App::PropertyInteger", attr, "IFC", locked=True) |
| | setattr(obj, attr, value) |
| | elif isinstance(value, float): |
| | obj.addProperty("App::PropertyFloat", attr, "IFC", locked=True) |
| | setattr(obj, attr, value) |
| | elif isinstance(value, ifcopenshell.entity_instance): |
| | value = create(value) |
| | obj.addProperty("App::PropertyLink", attr, "IFC", locked=True) |
| | setattr(obj, attr, value) |
| | elif isinstance(value, (list, tuple)) and value: |
| | if isinstance(value[0], ifcopenshell.entity_instance): |
| | nvalue = [] |
| | for elt in value: |
| | nvalue.append(create(elt)) |
| | obj.addProperty("App::PropertyLinkList", attr, "IFC", locked=True) |
| | setattr(obj, attr, nvalue) |
| | else: |
| | obj.addProperty("App::PropertyString", attr, "IFC", locked=True) |
| | if value is not None: |
| | setattr(obj, attr, str(value)) |
| | for parent in ifcfile.get_inverse(ifcentity): |
| | create(parent) |
| | if FreeCAD.GuiUp: |
| | ViewProvider(obj.ViewObject) |
| | return obj |
| |
|
| |
|
| | |
| |
|
| | filepath = QtWidgets.QFileDialog.getOpenFileName( |
| | None, "Select IFC File", None, "IFC Files (*.ifc)" |
| | )[0] |
| | stime = time.time() |
| | ifcfile = ifcopenshell.open(filepath) |
| | project = ifcfile.by_type("IfcProject")[0] |
| | if not FreeCAD.ActiveDocument: |
| | FreeCAD.newDocument() |
| | create(project) |
| | FreeCAD.ActiveDocument.recompute() |
| | endtime = "%02d:%02d" % (divmod(round(time.time() - stime, 1), 60)) |
| | lenobjects = str(len(FreeCAD.ActiveDocument.Objects)) + " objects" |
| | print("Import done:", endtime, ",", lenobjects) |
| |
|