-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.py
72 lines (62 loc) · 1.68 KB
/
build.py
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
import os
import FreeCAD
import Part
import Mesh
def ConvertToStepAndStl(path,name,tess=0.0):
input = path + "/src/" + name + ".FCStd"
stl = path + "/stl/" + name + ".stl"
step = path + "/step/" + name + ".step"
print("Input = " + input)
doc = FreeCAD.openDocument(input);
s = doc.ActiveObject.Shape
s.exportStep(step)
print("tess = " + str(tess))
if tess == 0.0:
s.exportStl(stl)
else:
m=Mesh.Mesh()
m.addFacets(s.tessellate(tess))
m.write(stl)
FreeCAD.closeDocument(doc.Name)
def MirrorPart(path, name):
input = path + "/step/" + name + ".step"
step = path + "/step/" + name + "-mirrored.step"
stl = path + "/stl/" + name + "-mirrored.stl"
print "Reading: " + input
s1 = Part.read(input)
s2 = s1.mirror(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,0,1))
s2.rotate(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,1,0),180)
s2.exportStep(step)
s2.exportStl(stl)
path=os.path.realpath(__file__)
path=os.path.dirname(path)
#
# find all FreeCAD source files
#
files = []
for f in os.listdir(path + "/src"):
if f.lower().endswith(".fcstd"):
if not f.startswith("RepRap-XY"):
files.append(f[:-6])
#
# Convert all FreeCAD files to STEP and STL files
#
for f in files:
print "ConvertToStepAndStl(" + path + "," + f + ")"
if not f.startswith("washer-M4"):
ConvertToStepAndStl(path,f)
#
# A few parts needs a mirrored variant
# These files are not drawn in FreeCAD but generated here
# STEP files and STL files are generated
#
PartNames = [ "belt-clamp",
"idler-block",
"idler-block-top",
"motor-block",
"motor-block-top",
"Z-motor-mount",
"Z-block-1" ]
for name in PartNames:
print "MirrorPart(" + path + "," + name + ")"
MirrorPart(path,name)