﻿import FreeCAD as App
import Part

out_step = r"mounting_bracket.step"
out_fcstd = r"mounting_bracket.FCStd"

doc = App.newDocument("MountingBracket")

# Dimensions in mm
width = 80.0
depth = 50.0
thickness = 6.0
height = 50.0
hole_d = 8.0

# L-bracket body: horizontal base + vertical flange
base = Part.makeBox(width, depth, thickness)
flange = Part.makeBox(thickness, depth, height)
shape = base.fuse(flange)

# Two mounting holes through the base
for x in (25.0, 60.0):
    hole = Part.makeCylinder(hole_d / 2.0, thickness + 2.0, App.Vector(x, depth / 2.0, -1.0))
    shape = shape.cut(hole)

# Two mounting holes through the vertical flange
for z in (18.0, 36.0):
    hole = Part.makeCylinder(hole_d / 2.0, thickness + 2.0,
                             App.Vector(-1.0, depth / 2.0, z),
                             App.Vector(1.0, 0.0, 0.0))
    shape = shape.cut(hole)

obj = doc.addObject("PartDesign::Feature", "Bracket")
obj.Label = "L Mounting Bracket"
obj.Shape = shape
obj.addProperty("App::PropertyLength", "Width", "Dimensions").Width = width
obj.addProperty("App::PropertyLength", "Depth", "Dimensions").Depth = depth
obj.addProperty("App::PropertyLength", "Height", "Dimensions").Height = height
obj.addProperty("App::PropertyLength", "Thickness", "Dimensions").Thickness = thickness
obj.addProperty("App::PropertyLength", "HoleDiameter", "Dimensions").HoleDiameter = hole_d

doc.recompute()
doc.saveAs(out_fcstd)
Part.export([obj], out_step)
print("Created:", out_step)
print("Created:", out_fcstd)

