def importDXFface(filename,layer=None,doc=None): import FreeCAD,importDXF importDXF.readPreferences() importDXF.getDXFlibs() importDXF.dxfMakeBlocks = False doc = doc or FreeCAD.activeDocument() layers = importDXF.processdxf(doc,filename) or importDXF.layers for l in layers: if FreeCAD.GuiUp: for o in l.Group: o.ViewObject.hide() l.ViewObject.hide() groupobj=[go for go in layers if (not layer) or go.Label == layer] edges=[] if not groupobj: raise ValueError, 'import of layer %s failed' % layer for shapeobj in groupobj[0].Group: edges.extend(shapeobj.Shape.Edges) faces = edgestofaces(edges) # in order to allow multiple import with the same layer name # we need to remove used objects from the layer group #shapeobj.Document.removeObject(shapeobj.Name) #groupobj[0].Document.removeObject(groupobj[0].Name) for layer in layers: #remove everything that has been imported layer.removeObjectsFromDocument() #for obj in layer.Group: # obj.Document.removeObject(obj.Name) layer.Document.removeObject(layer.Name) return faces
def importDXFface(filename, layer=None, doc=None): import FreeCAD, importDXF importDXF.readPreferences() importDXF.getDXFlibs() importDXF.dxfMakeBlocks = False doc = doc or FreeCAD.activeDocument() layers = importDXF.processdxf(doc, filename, False, False) or importDXF.layers for l in layers: if FreeCAD.GuiUp: for o in l.Group: o.ViewObject.hide() l.ViewObject.hide() groupobj = [go for go in layers if (not layer) or go.Label == layer] edges = [] if not groupobj: raise ValueError('import of layer %s failed' % layer) for shapeobj in groupobj[0].Group: edges.extend(shapeobj.Shape.Edges) faces = edgestofaces(edges) # in order to allow multiple import with the same layer name # we need to remove used objects from the layer group #shapeobj.Document.removeObject(shapeobj.Name) #groupobj[0].Document.removeObject(groupobj[0].Name) for layer in layers: #remove everything that has been imported removeOp = getattr(layer, "removeObjectsFromDocument", None) if callable(removeOp): layer.removeObjectsFromDocument() #for obj in layer.Group: # obj.Document.removeObject(obj.Name) layer.Document.removeObject(layer.Name) return faces
def import_dxf(self): filename = self.form.filename.text() if not filename: return scale = self.form.scale_box.value() p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") p.SetFloat("dxfScaling", scale) p.SetBool("dxfUseLegacyImporter", True) p.GetBool("dxfGetOriginalColors", True) import importDXF importDXF.readPreferences() doc = FreeCAD.ActiveDocument importDXF.getDXFlibs() gui = FreeCAD.GuiUp if importDXF.dxfReader: # groupname = str(Path(filename).name) # importgroup = doc.addObject("App::DocumentObjectGroup", groupname) # importgroup.Label = groupname importDXF.processdxf(doc, filename) # for l in layers: # importgroup.addObject(l) else: importDXF.errorDXFLib(gui) self.accept() if gui: Gui.SendMsgToActiveView("ViewFit")