Featured image of post FreeCADで台座を作ったメモ

FreeCADで台座を作ったメモ

目次

背景

  • PCモニターの台座がほしかったので作ったメモ
  • FreeCADでデザインして3Dプリンターで生成した
  • 大昔にSolidWorksを学んだがLinuxユーザーなのでFreeCADにした

前提

  • FreeCAD1.1.1
  • Bambu Studioは最新を使用した

CAD

寸法仕様

  • 本当はモニターの台座の下に、HHKBを収納するように作りたかった
  • しかし、3Dプリンターのサイズからはみ出るので、キーボード収納はやめた
  • その変わりに、半分のパーツ2つに分ける事にした
  • キーボードはしまえないが、筆箱などをしまえる収納になっている

寸法:

  • 1個あたり外寸:165 × 230 × 80mm
  • 2個完成外寸:330 × 230 × 80mm
  • 内側空間:141 × 220 × 68mm が左右に2区画
  • 中央支え:24mm
  • 横ケーブル穴:60 × 28mm / R8 / 入口R2
  • 後ろケーブル穴:70 × 28mm / R8 / 入口R2
  • 結束バンド穴:φ5.5mm
  • 結束バンド穴位置:前後2か所 × 縦2穴
  • 小穴入口:R0.8

FreeCADマクロ

AIに作ってもらったマクロ。

  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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import FreeCAD as App
import Part

doc = App.newDocument("DeskRiser_Half_165x230x80_RoundedCableHoles_TieHoles_2x2")

# =====================
# 1個分の外寸
# =====================
outer_w = 165.0
outer_d = 230.0
outer_h = 80.0

# =====================
# 板厚
# =====================
top_t = 12.0
side_t = 12.0
back_t = 10.0

inner_h = outer_h - top_t  # 68mm

# =====================
# 角丸ケーブル穴寸法
# =====================
side_hole_w = 60.0   # 横支え穴の幅(Y方向)
side_hole_h = 28.0   # 横支え穴の高さ(Z方向)

back_hole_w = 70.0   # 後ろ穴の幅(X方向)
back_hole_h = 28.0   # 後ろ穴の高さ(Z方向)

hole_r = 8.0         # 穴そのものの角丸半径
entry_fillet_r = 2.0 # 大きいケーブル穴入口のフチの丸み

# =====================
# 結束バンド用の小穴
# =====================
tie_hole_d = 5.5
tie_hole_r = tie_hole_d / 2.0
tie_hole_entry_fillet_r = 0.8

# 前後位置
tie_hole_front_y = 28.0
tie_hole_back_y = outer_d - 28.0  # 202mm

# 縦に2穴
tie_hole_zs = [18.0, 32.0]

# =====================
# 穴位置
# =====================
side_hole_center_y = outer_d / 2.0
side_hole_center_z = inner_h / 2.0

back_hole_center_x = outer_w / 2.0
back_hole_center_z = inner_h / 2.0

tol = 0.3

# =====================
# 本体
# =====================
top = Part.makeBox(
    outer_w,
    outer_d,
    top_t,
    App.Vector(0, 0, inner_h)
)

left_side = Part.makeBox(
    side_t,
    outer_d,
    inner_h,
    App.Vector(0, 0, 0)
)

right_side = Part.makeBox(
    side_t,
    outer_d,
    inner_h,
    App.Vector(outer_w - side_t, 0, 0)
)

back_wall = Part.makeBox(
    outer_w,
    back_t,
    inner_h,
    App.Vector(0, outer_d - back_t, 0)
)

shape = top.fuse(left_side).fuse(right_side).fuse(back_wall)

# =====================
# 角丸長方形カット:横支え用
# Y-Z平面の穴をX方向に貫通
# =====================
def make_side_rounded_cut(x_start, cut_depth, center_y, center_z, width, height, r):
    box1 = Part.makeBox(
        cut_depth,
        width - 2 * r,
        height,
        App.Vector(
            x_start,
            center_y - (width - 2 * r) / 2,
            center_z - height / 2
        )
    )

    box2 = Part.makeBox(
        cut_depth,
        width,
        height - 2 * r,
        App.Vector(
            x_start,
            center_y - width / 2,
            center_z - (height - 2 * r) / 2
        )
    )

    cut = box1.fuse(box2)

    corner_centers = [
        (center_y - width / 2 + r, center_z - height / 2 + r),
        (center_y + width / 2 - r, center_z - height / 2 + r),
        (center_y - width / 2 + r, center_z + height / 2 - r),
        (center_y + width / 2 - r, center_z + height / 2 - r),
    ]

    for y, z in corner_centers:
        cyl = Part.makeCylinder(
            r,
            cut_depth,
            App.Vector(x_start, y, z),
            App.Vector(1, 0, 0)
        )
        cut = cut.fuse(cyl)

    return cut

# =====================
# 角丸長方形カット:後ろ補強用
# X-Z平面の穴をY方向に貫通
# =====================
def make_back_rounded_cut(y_start, cut_depth, center_x, center_z, width, height, r):
    box1 = Part.makeBox(
        width - 2 * r,
        cut_depth,
        height,
        App.Vector(
            center_x - (width - 2 * r) / 2,
            y_start,
            center_z - height / 2
        )
    )

    box2 = Part.makeBox(
        width,
        cut_depth,
        height - 2 * r,
        App.Vector(
            center_x - width / 2,
            y_start,
            center_z - (height - 2 * r) / 2
        )
    )

    cut = box1.fuse(box2)

    corner_centers = [
        (center_x - width / 2 + r, center_z - height / 2 + r),
        (center_x + width / 2 - r, center_z - height / 2 + r),
        (center_x - width / 2 + r, center_z + height / 2 - r),
        (center_x + width / 2 - r, center_z + height / 2 - r),
    ]

    for x, z in corner_centers:
        cyl = Part.makeCylinder(
            r,
            cut_depth,
            App.Vector(x, y_start, z),
            App.Vector(0, 1, 0)
        )
        cut = cut.fuse(cyl)

    return cut

# =====================
# 結束バンド用の丸穴
# 側板をX方向に貫通
# =====================
def make_tie_hole_x(x_start, cut_depth, center_y, center_z, radius):
    return Part.makeCylinder(
        radius,
        cut_depth,
        App.Vector(x_start, center_y, center_z),
        App.Vector(1, 0, 0)
    )

# =====================
# 大きいケーブル穴を開ける
# =====================
left_cut = make_side_rounded_cut(
    -1.0,
    side_t + 2.0,
    side_hole_center_y,
    side_hole_center_z,
    side_hole_w,
    side_hole_h,
    hole_r
)

right_cut = make_side_rounded_cut(
    outer_w - side_t - 1.0,
    side_t + 2.0,
    side_hole_center_y,
    side_hole_center_z,
    side_hole_w,
    side_hole_h,
    hole_r
)

back_cut = make_back_rounded_cut(
    outer_d - back_t - 1.0,
    back_t + 2.0,
    back_hole_center_x,
    back_hole_center_z,
    back_hole_w,
    back_hole_h,
    hole_r
)

shape = shape.cut(left_cut)
shape = shape.cut(right_cut)
shape = shape.cut(back_cut)

# =====================
# 結束バンド用の小穴を開ける
# 前後2か所 × 縦2穴
# 左右側板にも同じ穴を開ける
# =====================
tie_positions_y = [tie_hole_front_y, tie_hole_back_y]

for y in tie_positions_y:
    for z in tie_hole_zs:
        left_tie = make_tie_hole_x(
            -1.0,
            side_t + 2.0,
            y,
            z,
            tie_hole_r
        )

        right_tie = make_tie_hole_x(
            outer_w - side_t - 1.0,
            side_t + 2.0,
            y,
            z,
            tie_hole_r
        )

        shape = shape.cut(left_tie)
        shape = shape.cut(right_tie)

# =====================
# フィレット用ヘルパー
# =====================
def is_close(a, b, tol=0.3):
    return abs(a - b) <= tol

def in_range(v, vmin, vmax, tol=0.3):
    return (v >= vmin - tol) and (v <= vmax + tol)

# =====================
# 大きいケーブル穴の入口フィレット
# =====================
def collect_large_cable_hole_edges(shape):
    edges = []

    side_ymin = side_hole_center_y - side_hole_w / 2.0
    side_ymax = side_hole_center_y + side_hole_w / 2.0
    side_zmin = side_hole_center_z - side_hole_h / 2.0
    side_zmax = side_hole_center_z + side_hole_h / 2.0

    back_xmin = back_hole_center_x - back_hole_w / 2.0
    back_xmax = back_hole_center_x + back_hole_w / 2.0
    back_zmin = back_hole_center_z - back_hole_h / 2.0
    back_zmax = back_hole_center_z + back_hole_h / 2.0

    x_planes = [0.0, side_t, outer_w - side_t, outer_w]
    y_planes = [outer_d - back_t, outer_d]

    for edge in shape.Edges:
        bb = edge.BoundBox

        # 横穴の開口部まわり
        if bb.XLength <= tol:
            x_plane = bb.XMin
            if any(is_close(x_plane, p, tol) for p in x_planes):
                cy = (bb.YMin + bb.YMax) / 2.0
                cz = (bb.ZMin + bb.ZMax) / 2.0
                if in_range(cy, side_ymin, side_ymax, tol) and in_range(cz, side_zmin, side_zmax, tol):
                    edges.append(edge)
                    continue

        # 後ろ穴の開口部まわり
        if bb.YLength <= tol:
            y_plane = bb.YMin
            if any(is_close(y_plane, p, tol) for p in y_planes):
                cx = (bb.XMin + bb.XMax) / 2.0
                cz = (bb.ZMin + bb.ZMax) / 2.0
                if in_range(cx, back_xmin, back_xmax, tol) and in_range(cz, back_zmin, back_zmax, tol):
                    edges.append(edge)
                    continue

    return edges

large_edges = collect_large_cable_hole_edges(shape)

if large_edges:
    try:
        shape = shape.makeFillet(entry_fillet_r, large_edges)
    except Exception as e:
        print("Large cable-hole fillet failed. Try entry_fillet_r = 1.0")
        print(e)

# =====================
# 結束バンド用の小穴にも入口フィレット
# =====================
def collect_tie_hole_edges(shape):
    edges = []

    x_planes = [0.0, side_t, outer_w - side_t, outer_w]
    tie_ys = [tie_hole_front_y, tie_hole_back_y]

    for edge in shape.Edges:
        bb = edge.BoundBox

        # 小穴の開口エッジはX面上に出る円形エッジ
        if bb.XLength <= tol:
            x_plane = bb.XMin

            if any(is_close(x_plane, p, tol) for p in x_planes):
                cy = (bb.YMin + bb.YMax) / 2.0
                cz = (bb.ZMin + bb.ZMax) / 2.0

                if any(is_close(cy, y, 1.0) for y in tie_ys) and any(is_close(cz, z, 1.0) for z in tie_hole_zs):
                    # 直径5.5mm穴周辺だけ拾う
                    if bb.YLength <= tie_hole_d + 1.5 and bb.ZLength <= tie_hole_d + 1.5:
                        edges.append(edge)

    return edges

tie_edges = collect_tie_hole_edges(shape)

if tie_edges:
    try:
        shape = shape.makeFillet(tie_hole_entry_fillet_r, tie_edges)
    except Exception as e:
        print("Tie-hole fillet failed. Try tie_hole_entry_fillet_r = 0.5")
        print(e)

# =====================
# FreeCADに表示
# =====================
obj = doc.addObject(
    "Part::Feature",
    "DeskRiser_Half_165x230x80_RoundedCableHoles_TieHoles_2x2"
)
obj.Shape = shape

doc.recompute()

try:
    App.Gui.activeDocument().activeView().viewAxometric()
    App.Gui.SendMsgToActiveView("ViewFit")
except Exception:
    pass

モデリング手順

  • Menu > ファイル > 新規ドキュメント
  • Menu > マクロ > マクロ > 新規 > 新規マクロでPythonを貼り付け
  • Menu > マクロ > マクロを実行

その後、保存は以下の手順でやる。

  • Menu > ファイル > エクスポート > STL Mesh

3Dプリンター

モデルのインポート

Bambu Studioを起動して以下でSTLをImportする。

  • Menu > File > Import > Import 3MF/…

印刷の設定

Process > Objectから次の設定をした。

  • 材料:PLA
  • 向き: 天板が下 (Lay on Face > 天板を選択)
  • Nozzle Diameter: 0.4 (デフォルト)
  • Layer Height:0.2mm(デフォルト)
  • Wall loops:5
  • Top shell layers:5
  • Bottom shell layers:5
  • Infill:20%
  • Infill pattern:grid
  • Support:on (台形穴用)

Gridパターンによる違い

ちなみに、infill patternの違いは以下らしい。

  • Grid = 速いけど、交差点でノズルが擦ることがある
  • Gyroid = 少し時間はかかるけど、大物・実用品では安定しやすい

断面図

断面イメージは以下のような感じ。

1
2
3
4
5
6
7
8
9
┌────────────────┐
│■■■■■■■■■■■■■■■■│ ← Top shell、上の実体層
│█░░░░░░░░░░░░░░█│
│█░  infill    ░█│ ← 中身の格子/ジャイロイド
│█░░░░░░░░░░░░░░█│
│■■■■■■■■■■■■■■■■│ ← Bottom shell、下の実体層
└────────────────┘
 ↑              ↑
 Wall loops = 外壁の周回数
  • Wall = 横方向の“側面の厚み”
    • ノズル径は0.4で、Wall loops:5
    • 上から見たすべての外壁の厚さは2mmとなる
  • Shell = 上下方向の“フタと底の厚み”
    • 0.2mmレイヤー、shellは5層
    • なので、zの厚みは約1.0mm

サイズcheck

一つのサイズ

プレビュー

スライス結果

これでサポート付きで、片方で500g以下に収まったので、1kgのフィラメント一つでプリント可能。

印刷時の問題

  • サポートがスパゲッティ化した問題が発生した。

最初のpurge lineつBrimが重なってたことが一つの原因だった

モデルを少し奥に移動して、サポートと鑑賞しないようにしたらなおった。

また、Infillを30%から20%にした。

後処理

2つ印刷したあとの後処理は以下になる。

  • 結束バンドで穴を結ぶ
  • 接着剤で2つのパーツを接着する
  • 底にゴム足などをつける

まとめ

  • AIのおかげでCADでマニュアルでポチポチする必要がなくなった
  • しかし、3Dプリンターの最大印刷サイズがちょっと足りなかったので分割した
  • 次は天板としてアクリル板を用意して、足だけ3Dプリントにするだろう
  • いや、普通にモノタロウでスチールのディスプレイスタンド買ったほうがQCDが良いかも
  • 2つ合わせて14時間もかかるし、普通に2k円のフィラメントを全部つかったし、コスパは良くない
  • 失敗も含めると、5回は印刷をやり直している
Built with Hugo
テーマ StackJimmy によって設計されています。