Repository: FreeCAD/FreeCAD
File: src/Mod/BIM/bimcommands/BimWall.py (Python)

Code before:
        FreeCADGui.doCommand("import FreeCAD")
        FreeCADGui.doCommand("import Part")
        FreeCADGui.addModule("WorkingPlane")
        FreeCADGui.doCommand(trace_cmd)

        if self.baseline_mode == WallBaselineMode.DRAFT_LINE:
            FreeCADGui.doCommand("import Draft")

            # Execute creation command. FreeCAD will ensure a unique name.
            FreeCADGui.doCommand("base = Draft.make_line(trace)")

            # Execute placement command.
            FreeCADGui.doCommand(f"base.Placement = {placement_str}")

            # The created line should not stay selected as this causes an issue in continue mode.
            # Two walls would then be created based on the same line.
            FreeCADGui.Selection.clearSelection()
            FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")

        elif self.baseline_mode == WallBaselineMode.SKETCH:
            import ArchSketchObject

            # Check ArchSketchLock and makeArchSketch() here
            useArchSketch = hasattr(ArchSketchObject, "makeArchSketch") and (
                not hasattr(FreeCAD, "ArchSketchLock") or FreeCAD.ArchSketchLock
            )

            if not useArchSketch:
                # Regular path without SketchArch add-on installed. Execute creation command with a
                # suggested name. FreeCAD will ensure uniqueness.
                FreeCADGui.doCommand(
                    "base = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject', 'WallTrace')"
                )
                user_label = translate("BimWall", "Wall Trace")
                # Set the user-facing, translated label.
                FreeCADGui.doCommand(f"base.Label = {repr(user_label)}")
            else:
                # Use ArchSketch if SketchArch add-on is present
                # TODO 2026.1.18 Do translation in Add-on
                FreeCADGui.doCommand("import ArchSketchObject")
                FreeCADGui.doCommand("base = ArchSketchObject.makeArchSketch()")

            # Apply placement and geometry using the correctly identified object name.
            FreeCADGui.doCommand(f"base.Placement = {placement_str}")
            FreeCADGui.doCommand(f"base.addGeometry(trace)")

        FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")

        # Get a reference to the newly created object
        baseline_obj = getattr(__main__, "base")


Review comment (suggestion):
```suggestion
            useArchSketch = hasattr(ArchSketchObject, "makeArchSketch") and getattr(FreeCAD, "ArchSketchLock", True)
```
This can be more compact

Code after:
        FreeCADGui.doCommand("import FreeCAD")
        FreeCADGui.doCommand("import Part")
        FreeCADGui.addModule("WorkingPlane")
        FreeCADGui.doCommand(trace_cmd)

        if self.baseline_mode == WallBaselineMode.DRAFT_LINE:
            FreeCADGui.doCommand("import Draft")

            # Execute creation command. FreeCAD will ensure a unique name.
            FreeCADGui.doCommand("base = Draft.make_line(trace)")

            # Execute placement command.
            FreeCADGui.doCommand(f"base.Placement = {placement_str}")

            # The created line should not stay selected as this causes an issue in continue mode.
            # Two walls would then be created based on the same line.
            FreeCADGui.Selection.clearSelection()
            FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")

        elif self.baseline_mode == WallBaselineMode.SKETCH:
            import ArchSketchObject

            # Check ArchSketchLock and makeArchSketch() here
            useArchSketch = hasattr(ArchSketchObject, "makeArchSketch") and getattr(
                FreeCAD, "ArchSketchLock", True
            )

            if not useArchSketch:
                # Regular path without SketchArch add-on installed. Execute creation command with a
                # suggested name. FreeCAD will ensure uniqueness.
                FreeCADGui.doCommand(
                    "base = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject', 'WallTrace')"
                )
                user_label = translate("BimWall", "Wall Trace")
                # Set the user-facing, translated label.
                FreeCADGui.doCommand(f"base.Label = {repr(user_label)}")
            else:
                # Use ArchSketch if SketchArch add-on is present
                FreeCADGui.doCommand("import ArchSketchObject")
                FreeCADGui.doCommand("base = ArchSketchObject.makeArchSketch()")

            # Apply placement and geometry using the correctly identified object name.
            FreeCADGui.doCommand(f"base.Placement = {placement_str}")
            FreeCADGui.doCommand(f"base.addGeometry(trace)")

        FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")

        # Get a reference to the newly created object
        baseline_obj = getattr(__main__, "base")

        return baseline_obj