From 6d537e42151ff3f260fe1c8df261dc238576072c Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sat, 1 Nov 2025 13:26:13 +0100 Subject: [PATCH] Draft: Do not set Make Face property when importing with DXF (#24857) * Draft: Do not set Make Face property when importing with DXF As the title says - this option was taken from last Draft setting, so this disables it to always preserve only wire during import, instead of adding faces on. * Draft: Do not make faces when importing dxf primitives for legacy import --- src/Mod/Draft/importDXF.py | 53 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index 27a39c117b..51520ca6ac 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -849,7 +849,7 @@ def drawLine(line, forceShape=False): if not DraftVecUtils.equals(v1, v2): try: if (dxfCreateDraft or dxfCreateSketch) and (not forceShape): - return Draft.make_wire([v1, v2]) + return Draft.make_wire([v1, v2], face=False) else: return Part.LineSegment(v1, v2).toShape() except Part.OCCError: @@ -891,9 +891,7 @@ def drawPolyline(polyline, forceShape=False, num=None): `dxfCreateDraft` or `dxfCreateSketch` are set, and `forceShape` is `False` it creates a straight `Draft Wire`. - If the polyline is closed, and the global variable `dxfMakeFaceMode` - is set, it will return a `Part.Face`, otherwise it will return - a `Part.Wire`. + Otherwise, it will return a `Part.Wire`. See also -------- @@ -967,19 +965,15 @@ def drawPolyline(polyline, forceShape=False, num=None): else: return Part.Face(w1) elif (dxfCreateDraft or dxfCreateSketch) and (not curves) and (not forceShape): - ob = Draft.make_wire(verts) + # Create parametric Draft.Wire for straight polylines + ob = Draft.make_wire(verts, face=False) ob.Closed = polyline.closed ob.Placement = placementFromDXFOCS(polyline) return ob else: - if polyline.closed and dxfMakeFaceMode: - w = Part.Wire(edges) - w.Placement = placementFromDXFOCS(polyline) - return Part.Face(w) - else: - w = Part.Wire(edges) - w.Placement = placementFromDXFOCS(polyline) - return w + w = Part.Wire(edges) + w.Placement = placementFromDXFOCS(polyline) + return w except Part.OCCError: warn(polyline, num) return None @@ -1134,7 +1128,7 @@ def drawEllipse(ellipse, forceShape=False): shape.Placement = pl return shape else: - return Draft.make_ellipse(majr, minr, pl) + return Draft.make_ellipse(majr, minr, pl, face=False) else: shape = el.toShape(start, end) shape.Placement = pl @@ -1328,10 +1322,7 @@ def drawSplineIterpolation(verts, closed=False, forceShape=False, alwaysDiscreti `dxfDiscretizeCurves` or `alwaysDiscretize` are `True`, and a `Draft BSpline` otherwise. - Otherwise it tries producing a `Part.Edge` - (`dxfDiscretizeCurves` or `alwaysDiscretize` are `True`) - or `Part.Face` - if `closed` and the global variable `dxfMakeFaceMode` are `True`. + Otherwise it produces a `Part.Wire`. To do ----- @@ -1339,9 +1330,9 @@ def drawSplineIterpolation(verts, closed=False, forceShape=False, alwaysDiscreti """ if (dxfCreateDraft or dxfCreateSketch) and (not forceShape): if dxfDiscretizeCurves or alwaysDiscretize: - ob = Draft.make_wire(verts) + ob = Draft.make_wire(verts, face=False) else: - ob = Draft.make_bspline(verts) + ob = Draft.make_bspline(verts, face=False) ob.Closed = closed return ob else: @@ -1352,10 +1343,7 @@ def drawSplineIterpolation(verts, closed=False, forceShape=False, alwaysDiscreti # print(knots) sp.interpolate(verts) sh = Part.Wire(sp.toShape()) - if closed and dxfMakeFaceMode: - return Part.Face(sh) - else: - return sh + return sh def drawSplineOld(spline, forceShape=False): @@ -2332,7 +2320,7 @@ def processdxf(document, filename, getShapes=False, reComputeFlag=True): num = 0 for polyline in polylines: if dxfImportLayouts or (not rawValue(polyline, 67)): - shape = drawPolyline(polyline, num) + shape = drawPolyline(polyline, num=num) if shape: if dxfCreateSketch: if isinstance(shape, Part.Shape): @@ -4297,7 +4285,7 @@ def readPreferences(): `dxfDiscretizeCurves`, `dxfStarBlocks`, `dxfMakeBlocks`, `dxfJoin`, `dxfRenderPolylineWidth`, `dxfImportTexts`, `dxfImportLayouts`, `dxfImportPoints`, `dxfImportHatches`, `dxfUseStandardSize`, - `dxfGetColors`, `dxfUseDraftVisGroups`, `dxfMakeFaceMode`, + `dxfGetColors`, `dxfUseDraftVisGroups`, `dxfBrightBackground`, `dxfDefaultColor`, `dxfUseLegacyImporter`, `dxfExportBlocks`, `dxfScaling`, `dxfUseLegacyExporter` @@ -4310,7 +4298,7 @@ def readPreferences(): global dxfCreatePart, dxfCreateDraft, dxfCreateSketch global dxfDiscretizeCurves, dxfStarBlocks, dxfMakeBlocks, dxfJoin, dxfRenderPolylineWidth global dxfImportTexts, dxfImportLayouts, dxfImportPoints, dxfImportHatches, dxfUseStandardSize - global dxfGetColors, dxfUseDraftVisGroups, dxfMakeFaceMode, dxfBrightBackground, dxfDefaultColor + global dxfGetColors, dxfUseDraftVisGroups, dxfBrightBackground, dxfDefaultColor global dxfUseLegacyImporter, dxfExportBlocks, dxfScaling, dxfUseLegacyExporter # Use the direct C++ API via Python for all parameter access @@ -4371,7 +4359,6 @@ def readPreferences(): dxfUseStandardSize = hGrp.GetBool("dxfStdSize", False) dxfGetColors = hGrp.GetBool("dxfGetOriginalColors", True) dxfUseDraftVisGroups = hGrp.GetBool("dxfUseDraftVisGroups", True) - dxfMakeFaceMode = hGrp.GetBool("MakeFaceMode", False) dxfUseLegacyExporter = hGrp.GetBool("dxfUseLegacyExporter", False) dxfExportBlocks = hGrp.GetBool("dxfExportBlocks", True) dxfScaling = hGrp.GetFloat("dxfScaling", 1.0) @@ -4599,6 +4586,8 @@ class DxfDraftPostProcessor: end_point = FreeCAD.Vector(part_obj.X2.Value, part_obj.Y2.Value, part_obj.Z2.Value) new_obj.Points = [start_point, end_point] + new_obj.MakeFace = False + obj_type_str = "Line" elif part_obj.isDerivedFrom("Part::Circle"): @@ -4637,6 +4626,8 @@ class DxfDraftPostProcessor: and abs(new_obj.LastAngle.Value - 360.0) < 1e-7 ) + new_obj.MakeFace = False + obj_type_str = "Circle" if is_full_circle else "Arc" elif part_obj.isDerivedFrom( @@ -4700,6 +4691,9 @@ class DxfDraftPostProcessor: # Assign the un-transformed shape and the separate placement. new_obj.Shape = shape_at_origin new_obj.Placement = part_obj.Placement + + new_obj.MakeFace = False + obj_type_str = "Shape" # --- Handle generic Part::Feature objects (from C++ importer, wrapping TopoDS_Shapes like Wires, Splines, Ellipses) --- @@ -4741,6 +4735,9 @@ class DxfDraftPostProcessor: new_obj.Closed = ( shape.isClosed() ) # Transfer specific properties expected by Draft.Wire. + + new_obj.MakeFace = False + obj_type_str = "Wire" # Fallback for other Part::Feature shapes (e.g., 3DFACE, SOLID, or unsupported Edge types).