YSMlearnsCode
commited on
Commit
·
89f261c
1
Parent(s):
66f12a9
tweaked UI again
Browse files- app.py +12 -7
- generated/result_script.py +9 -0
app.py
CHANGED
@@ -42,9 +42,13 @@ css = """
|
|
42 |
.title { text-align: center; font-size: 2.5em; margin-bottom: 0.1em; }
|
43 |
.description { text-align: center; font-size: 1.1em; margin-bottom: 1em; color: #ccc; }
|
44 |
.preview-box {
|
45 |
-
height: 400px;
|
46 |
-
background-color: #111;
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
.download-container {
|
50 |
display: flex;
|
@@ -54,7 +58,7 @@ css = """
|
|
54 |
padding-left: 15px;
|
55 |
height: 400px;
|
56 |
justify-content: flex-start;
|
57 |
-
width:
|
58 |
}
|
59 |
.download-button { width: 100%; }
|
60 |
.instructions {
|
@@ -75,6 +79,7 @@ css = """
|
|
75 |
"""
|
76 |
|
77 |
# Description
|
|
|
78 |
cadomatic_description_md = """
|
79 |
<div style="text-align: center;">
|
80 |
|
@@ -93,7 +98,7 @@ with gr.Blocks(css=css) as demo:
|
|
93 |
|
94 |
description_input = gr.Textbox(
|
95 |
label="Describe your desired CAD model below-",
|
96 |
-
lines=
|
97 |
placeholder="e.g., Create a flange with OD 100mm, bore size 50mm and 6 m8 holes at PCD 75mm..."
|
98 |
)
|
99 |
|
@@ -111,7 +116,7 @@ with gr.Blocks(css=css) as demo:
|
|
111 |
elem_classes="download-button"
|
112 |
)
|
113 |
with gr.Column(scale=1):
|
114 |
-
gr.Markdown(
|
115 |
"""
|
116 |
<div class='instructions'>
|
117 |
<b>Instructions:</b><br>
|
@@ -119,7 +124,7 @@ with gr.Blocks(css=css) as demo:
|
|
119 |
- Click on "Generate Script".<br>
|
120 |
- Preview the generated Python code.<br>
|
121 |
- Paste the generated code into the python console of your FreeCAD app.<br>
|
122 |
-
- (or)<br>
|
123 |
- Download the script.<br>
|
124 |
- In your FreeCAD python console, paste - exec(open(r"path to your python script").read())
|
125 |
</div>
|
|
|
42 |
.title { text-align: center; font-size: 2.5em; margin-bottom: 0.1em; }
|
43 |
.description { text-align: center; font-size: 1.1em; margin-bottom: 1em; color: #ccc; }
|
44 |
.preview-box {
|
45 |
+
max-height: 400px;
|
46 |
+
background-color: #111;
|
47 |
+
border: 1px solid #444;
|
48 |
+
padding: 10px;
|
49 |
+
font-family: monospace;
|
50 |
+
white-space: pre-wrap;
|
51 |
+
color: #0f0;
|
52 |
}
|
53 |
.download-container {
|
54 |
display: flex;
|
|
|
58 |
padding-left: 15px;
|
59 |
height: 400px;
|
60 |
justify-content: flex-start;
|
61 |
+
width: 500px;
|
62 |
}
|
63 |
.download-button { width: 100%; }
|
64 |
.instructions {
|
|
|
79 |
"""
|
80 |
|
81 |
# Description
|
82 |
+
# ToDo write as features
|
83 |
cadomatic_description_md = """
|
84 |
<div style="text-align: center;">
|
85 |
|
|
|
98 |
|
99 |
description_input = gr.Textbox(
|
100 |
label="Describe your desired CAD model below-",
|
101 |
+
lines=2,
|
102 |
placeholder="e.g., Create a flange with OD 100mm, bore size 50mm and 6 m8 holes at PCD 75mm..."
|
103 |
)
|
104 |
|
|
|
116 |
elem_classes="download-button"
|
117 |
)
|
118 |
with gr.Column(scale=1):
|
119 |
+
gr.Markdown( #ToDo
|
120 |
"""
|
121 |
<div class='instructions'>
|
122 |
<b>Instructions:</b><br>
|
|
|
124 |
- Click on "Generate Script".<br>
|
125 |
- Preview the generated Python code.<br>
|
126 |
- Paste the generated code into the python console of your FreeCAD app.<br>
|
127 |
+
- (or)<br>
|
128 |
- Download the script.<br>
|
129 |
- In your FreeCAD python console, paste - exec(open(r"path to your python script").read())
|
130 |
</div>
|
generated/result_script.py
CHANGED
@@ -7,6 +7,7 @@ import math
|
|
7 |
def createFlangeAssembly():
|
8 |
doc = App.newDocument("Flange")
|
9 |
|
|
|
10 |
FLANGE_OUTER_DIAMETER = 100.0
|
11 |
FLANGE_THICKNESS = 7.5
|
12 |
BORE_INNER_DIAMETER = 50.0
|
@@ -18,10 +19,12 @@ def createFlangeAssembly():
|
|
18 |
|
19 |
total_height = FLANGE_THICKNESS + NECK_HEIGHT
|
20 |
|
|
|
21 |
flange = doc.addObject("Part::Cylinder", "Flange")
|
22 |
flange.Radius = FLANGE_OUTER_DIAMETER / 2
|
23 |
flange.Height = FLANGE_THICKNESS
|
24 |
|
|
|
25 |
bore = doc.addObject("Part::Cylinder", "CentralBore")
|
26 |
bore.Radius = BORE_INNER_DIAMETER / 2
|
27 |
bore.Height = FLANGE_THICKNESS
|
@@ -29,6 +32,7 @@ def createFlangeAssembly():
|
|
29 |
bore_cut.Base = flange
|
30 |
bore_cut.Tool = bore
|
31 |
|
|
|
32 |
neck_outer = doc.addObject("Part::Cylinder", "NeckOuter")
|
33 |
neck_outer.Radius = NECK_OUTER_DIAMETER / 2
|
34 |
neck_outer.Height = NECK_HEIGHT
|
@@ -43,10 +47,12 @@ def createFlangeAssembly():
|
|
43 |
neck_hollow.Base = neck_outer
|
44 |
neck_hollow.Tool = neck_inner
|
45 |
|
|
|
46 |
fused = doc.addObject("Part::Fuse", "FlangeAndNeck")
|
47 |
fused.Base = bore_cut
|
48 |
fused.Tool = neck_hollow
|
49 |
|
|
|
50 |
current_shape = fused
|
51 |
bolt_radius = BOLT_HOLE_DIAMETER / 2
|
52 |
bolt_circle_radius = PCD / 2
|
@@ -67,6 +73,9 @@ def createFlangeAssembly():
|
|
67 |
cut.Tool = hole
|
68 |
current_shape = cut
|
69 |
|
|
|
|
|
|
|
70 |
doc.recompute()
|
71 |
Gui.activeDocument().activeView().viewAxometric()
|
72 |
Gui.SendMsgToActiveView("ViewFit")
|
|
|
7 |
def createFlangeAssembly():
|
8 |
doc = App.newDocument("Flange")
|
9 |
|
10 |
+
# === Parameters ===
|
11 |
FLANGE_OUTER_DIAMETER = 100.0
|
12 |
FLANGE_THICKNESS = 7.5
|
13 |
BORE_INNER_DIAMETER = 50.0
|
|
|
19 |
|
20 |
total_height = FLANGE_THICKNESS + NECK_HEIGHT
|
21 |
|
22 |
+
# === 1. Create flange base ===
|
23 |
flange = doc.addObject("Part::Cylinder", "Flange")
|
24 |
flange.Radius = FLANGE_OUTER_DIAMETER / 2
|
25 |
flange.Height = FLANGE_THICKNESS
|
26 |
|
27 |
+
# === 2. Cut central bore from flange ===
|
28 |
bore = doc.addObject("Part::Cylinder", "CentralBore")
|
29 |
bore.Radius = BORE_INNER_DIAMETER / 2
|
30 |
bore.Height = FLANGE_THICKNESS
|
|
|
32 |
bore_cut.Base = flange
|
33 |
bore_cut.Tool = bore
|
34 |
|
35 |
+
# === 3. Create neck ===
|
36 |
neck_outer = doc.addObject("Part::Cylinder", "NeckOuter")
|
37 |
neck_outer.Radius = NECK_OUTER_DIAMETER / 2
|
38 |
neck_outer.Height = NECK_HEIGHT
|
|
|
47 |
neck_hollow.Base = neck_outer
|
48 |
neck_hollow.Tool = neck_inner
|
49 |
|
50 |
+
# === 4. Fuse flange (with central hole) and neck ===
|
51 |
fused = doc.addObject("Part::Fuse", "FlangeAndNeck")
|
52 |
fused.Base = bore_cut
|
53 |
fused.Tool = neck_hollow
|
54 |
|
55 |
+
# === 5. Cut bolt holes sequentially ===
|
56 |
current_shape = fused
|
57 |
bolt_radius = BOLT_HOLE_DIAMETER / 2
|
58 |
bolt_circle_radius = PCD / 2
|
|
|
73 |
cut.Tool = hole
|
74 |
current_shape = cut
|
75 |
|
76 |
+
# === 6. Final result ===
|
77 |
+
|
78 |
+
|
79 |
doc.recompute()
|
80 |
Gui.activeDocument().activeView().viewAxometric()
|
81 |
Gui.SendMsgToActiveView("ViewFit")
|