This article introduces how to create 3D printer data (STL file) using CadQuery. CadQuery is a python library that allows you to create 3D models.
I bought a 3D printer to expand the range of electronic work. I haven't used the 3D CAD tool itself, so after a lot of research, CadQuery and FreeCad were easy for me to use. (This time, only CadQuery)
The following is the official information. There are extremely few articles in Japanese.
There are multiple installation methods, but this time it's the easiest This is done by downloading CQ-editor.
From CQ-editor "Installation"-Download from "RC1 Windows".
Unzip "CQ-editor-0.1RC1-win64.zip" and execute "CQ-editor.exe" to start it.
Paste the following code into the editor section ①.
test.py
import cadquery as cq
result = cq.Workplane("front").box(2.0, 2.0, 0.5)
show_object(result)
Press the play button to execute the code. A cube is created.
Create the photo hooks listed at the top of the page.
test.py
# This is a CadQuery script
import cadquery as cq
import itertools
#Definition of length and thickness
X1 = 40.0
X2 = 2.0
X3 = 2.0
Y1 = 40.0
Y2 = 2.0
Y3 = 10.0
Z1 = 40.0
#Described in the xy plane
result0 = (cq.Workplane("XY")
.moveTo(0,0)
.lineTo(X1,0)
.lineTo(X1,Y1)
.lineTo(X1-X2,Y1)
.lineTo(X1-X2,Y2)
.lineTo(X3,Y2)
.lineTo(X3,Y3)
.lineTo(0,Y3)
.close())
#Extrude in the z-axis direction
result = result0.extrude(Z1)
#Tacking hole
#Definition of holes in the yz and xz planes
HOLE_Xs = [9*1, 9*3, 9*5, 9*7, 9*9, 9*11]
HOLE_Ys = [9*1, 9*3, 9*5, 9*7, 9*9, 9*11]
HOLE = 5.0
#Drilling
for hole_crd in itertools.product(HOLE_Xs, HOLE_Ys):
result = result.faces(">X").workplane().rect(hole_crd[0], hole_crd[1], forConstruction=True).vertices().hole(HOLE)
result = result.faces(">Y").workplane().rect(hole_crd[0], hole_crd[1], forConstruction=True).vertices().hole(HOLE)
#Displaying objects
show_object(result)
The coordinate relationship between the definition of length and thickness is as follows.
You can run the code to create a model with hooks.
After selecting the object, select "Tools"-"Export as STL".
Specify a file name and save.
After that, print with a 3D printer.
It is very helpful to code the 3D model.
Recommended Posts