def insert(filename, docname=None, preferences=None): """imports the contents of an IFC file in the given document""" import ifcopenshell from ifcopenshell import geom # reset global values global layers global materials global objects global adds global subs layers = {} materials = {} objects = {} adds = {} subs = {} # statistics starttime = time.time() # in seconds filesize = os.path.getsize(filename) * 0.000001 # in megabytes print("Opening", filename + ",", round(filesize, 2), "Mb") # setup ifcopenshell if not preferences: preferences = importIFC.getPreferences() settings = ifcopenshell.geom.settings() settings.set(settings.USE_BREP_DATA, True) settings.set(settings.SEW_SHELLS, True) settings.set(settings.USE_WORLD_COORDS, True) if preferences['SEPARATE_OPENINGS']: settings.set(settings.DISABLE_OPENING_SUBTRACTIONS, True) if preferences['SPLIT_LAYERS'] and hasattr(settings, "APPLY_LAYERSETS"): settings.set(settings.APPLY_LAYERSETS, True) # setup document if not FreeCAD.ActiveDocument: if not docname: docname = os.path.splitext(os.path.basename(filename))[0] doc = FreeCAD.newDocument(docname) doc.Label = docname FreeCAD.setActiveDocument(doc.Name) # open the file ifcfile = ifcopenshell.open(filename) progressbar = Base.ProgressIndicator() productscount = len(ifcfile.by_type("IfcProduct")) progressbar.start("Importing " + str(productscount) + " products...", productscount) cores = preferences["MULTICORE"] iterator = ifcopenshell.geom.iterator(settings, ifcfile, cores) iterator.initialize() count = 0 # process objects while True: item = iterator.get() if item: brep = item.geometry.brep_data ifcproduct = ifcfile.by_id(item.guid) obj = createProduct(ifcproduct, brep) progressbar.next(True) writeProgress(count, productscount, starttime) count += 1 if not iterator.next(): break # post-processing processRelationships() storeColorDict() # finished progressbar.stop() FreeCAD.ActiveDocument.recompute() endtime = round(time.time() - starttime, 1) fs = round(filesize, 1) ratio = int(endtime / filesize) endtime = "%02d:%02d" % (divmod(endtime, 60)) writeProgress() # this cleans the line print("Finished importing", fs, "Mb in", endtime, "s, or", ratio, "s/Mb") return FreeCAD.ActiveDocument
def getsettings(self): return importIFC.getPreferences()