File size: 2,439 Bytes
41d6e2b
 
 
 
 
 
 
 
 
 
 
 
 
dddf9a7
41d6e2b
 
 
 
 
 
dddf9a7
41d6e2b
 
 
dddf9a7
41d6e2b
 
dddf9a7
41d6e2b
 
 
dddf9a7
41d6e2b
 
 
 
dddf9a7
41d6e2b
 
 
 
dddf9a7
41d6e2b
 
 
dddf9a7
41d6e2b
 
 
dddf9a7
41d6e2b
 
 
 
 
 
 
 
 
dddf9a7
 
 
 
41d6e2b
dddf9a7
 
 
 
41d6e2b
 
 
 
 
 
 
 
 
 
dddf9a7
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import FreeCAD as App
import FreeCADGui as Gui
from FreeCAD import Vector
import math


def createFlangeAssembly():
    doc = App.newDocument("Flange")

    FLANGE_OUTER_DIAMETER = 100.0
    FLANGE_THICKNESS = 7.5
    BORE_INNER_DIAMETER = 50.0
    NECK_HEIGHT = 15.0
    NECK_OUTER_DIAMETER = 60.0
    NUM_BOLT_HOLES = 6
    BOLT_HOLE_DIAMETER = 12.0
    PCD = 75.0

    total_height = FLANGE_THICKNESS + NECK_HEIGHT

    flange = doc.addObject("Part::Cylinder", "Flange")
    flange.Radius = FLANGE_OUTER_DIAMETER / 2
    flange.Height = FLANGE_THICKNESS

    bore = doc.addObject("Part::Cylinder", "CentralBore")
    bore.Radius = BORE_INNER_DIAMETER / 2
    bore.Height = FLANGE_THICKNESS
    bore_cut = doc.addObject("Part::Cut", "FlangeWithBore")
    bore_cut.Base = flange
    bore_cut.Tool = bore

    neck_outer = doc.addObject("Part::Cylinder", "NeckOuter")
    neck_outer.Radius = NECK_OUTER_DIAMETER / 2
    neck_outer.Height = NECK_HEIGHT
    neck_outer.Placement.Base = Vector(0, 0, FLANGE_THICKNESS)

    neck_inner = doc.addObject("Part::Cylinder", "NeckInner")
    neck_inner.Radius = BORE_INNER_DIAMETER / 2
    neck_inner.Height = NECK_HEIGHT
    neck_inner.Placement.Base = Vector(0, 0, FLANGE_THICKNESS)

    neck_hollow = doc.addObject("Part::Cut", "HollowNeck")
    neck_hollow.Base = neck_outer
    neck_hollow.Tool = neck_inner

    fused = doc.addObject("Part::Fuse", "FlangeAndNeck")
    fused.Base = bore_cut
    fused.Tool = neck_hollow

    current_shape = fused
    bolt_radius = BOLT_HOLE_DIAMETER / 2
    bolt_circle_radius = PCD / 2

    for i in range(NUM_BOLT_HOLES):
        angle_deg = 360 * i / NUM_BOLT_HOLES
        angle_rad = math.radians(angle_deg)
        x = bolt_circle_radius * math.cos(angle_rad)
        y = bolt_circle_radius * math.sin(angle_rad)

        hole = doc.addObject("Part::Cylinder", f"BoltHole_{i+1:02d}")
        hole.Radius = bolt_radius
        hole.Height = total_height
        hole.Placement.Base = Vector(x, y, 0)

        cut = doc.addObject("Part::Cut", f"Cut_Bolt_{i+1:02d}")
        cut.Base = current_shape
        cut.Tool = hole
        current_shape = cut

    doc.recompute()
    Gui.activeDocument().activeView().viewAxometric()
    Gui.SendMsgToActiveView("ViewFit")

    return doc

if __name__ == "__main__":
    createFlangeAssembly()


import FreeCADGui
FreeCADGui.activeDocument().activeView().viewAxometric()
FreeCADGui.SendMsgToActiveView("ViewFit")