forked from URJCMakerGroup/MakerWorkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_export_fun.py
174 lines (152 loc) · 6.88 KB
/
print_export_fun.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
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
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# -- Function Print and Export Object
# ----------------------------------------------------------------------------
# -- (c) David Muñoz Bernal
# ----------------------------------------------------------------------------
# -- This function set the object to the print position and export the object.
import os
import sys
import FreeCAD
import FreeCADGui
import Mesh
import MeshPart
import PySide2
from PySide2 import QtCore, QtGui, QtWidgets
import kparts
def print_export(obj_select):
show_message = True
place_old = obj_select.Placement
# _________Motor_Holder_________
if 'motorholder' in obj_select.Name or 'nema_holder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 1, 0), 180)
centre = FreeCAD.Vector(0, 0, 0)
# _________Idler_Tensioner_________
elif 'idler_tensioner' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 1, 0), 90)
centre = FreeCAD.Vector(0, 0, 0)
# _________Tensioner_Holder_________
elif 'tensioner_holder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), -90)
centre = FreeCAD.Vector(0, 0, 0)
# _________Filter_Holder_________
elif 'filter_holder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Nema_Holder_________
# elif 'nema_holder' in obj_select.Name:
# pos = obj_select.Placement.Base
# rot = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180)
# centre = FreeCAD.Vector(0,0,0)
# _________Linbearhouse_________
elif 'linbear' in obj_select.Name:
if 'top' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 1, 0), 180)
centre = FreeCAD.Vector(0, 0, 0)
elif 'bot' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
else:
message = QtWidgets.QMessageBox()
message.Critical()
message.setWindowTitle('Critial error')
message.setText('Not position set for this model')
message.setStandardButtons(QtWidgets.QMessageBox.Ok)
message.setDefaultButton(QtWidgets.QMessageBox.Ok)
message.exec_()
# _________Bracket_________
elif 'bracket' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Bracket_3_________
# elif bracket3 in obj_select.Name:
# pos = obj_select.Placement.Base
# rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,0),0)
# centre = FreeCAD.Vector(0,0,0)
# _________Bracket_Twin_________
# elif bracket_twin in obj_select.Name:
# pos = obj_select.Placement.Base
# rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,0),0)
# centre = FreeCAD.Vector(0,0,0)
# _________Shaft_________
elif 'shaft' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________IdlepulleyHold_________
elif 'idlepulleyhold' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Simple_End_Stop_Holder_________
elif 'simple_endstop_holder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Stop_Holder_________
elif 'stop_holder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Belt_Clamp_________
elif 'belt_clamp' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 0), 0)
centre = FreeCAD.Vector(0, 0, 0)
# _________Sensor_Holder_________
elif 'sensorholder' in obj_select.Name:
pos = obj_select.Placement.Base
rot = FreeCAD.Rotation(FreeCAD.Vector(0, 1, 0), 90)
centre = FreeCAD.Vector(0, 0, 0)
# _________Not_Name_________
else:
message = QtWidgets.QMessageBox()
message.setIcon(QtWidgets.QMessageBox.Icon.Warning)
message.setWindowTitle('Sorry')
message.setText('This object is not a workbench object.\n')
message.setStandardButtons(QtWidgets.QMessageBox.Ok)
message.setDefaultButton(QtWidgets.QMessageBox.Ok)
message.exec_()
show_message = False
#######################################################
# _________Message_And_Change_________
if show_message is True:
obj_select.Placement = FreeCAD.Placement(pos, rot, centre)
FreeCADGui.activeDocument().activeView().viewAxonometric()
FreeCADGui.SendMsgToActiveView("ViewFit")
# _________EXPORT_________
# Open the file explorer to set the folder
folder_name = QtWidgets.QFileDialog.getExistingDirectory(QtWidgets.QFileDialog(), "Select directory", "c:/",
QtWidgets.QFileDialog.ShowDirsOnly)
if folder_name is not "":
# take the path and export the object
stl_file_name = str(folder_name) + "/" + obj_select.Name + ".stl"
mesh_shp = MeshPart.meshFromShape(obj_select.Shape,
LinearDeflection=kparts.LIN_DEFL,
AngularDeflection=kparts.ANG_DEFL)
mesh_shp.write(stl_file_name)
del mesh_shp
obj_select.Placement = place_old
message = QtWidgets.QMessageBox()
message.setIcon(QtWidgets.QMessageBox.Icon.Information)
message.setWindowTitle('Congratulations')
message.setText("You export " + obj_select.Name + " in " + folder_name)
message.setStandardButtons(QtWidgets.QMessageBox.Ok)
message.setDefaultButton(QtWidgets.QMessageBox.Ok)
message.exec_()
else:
obj_select.Placement = place_old
message = QtWidgets.QMessageBox()
message.setIcon(QtWidgets.QMessageBox.Icon.Warning)
message.setWindowTitle('Error')
message.setText("Please, select a correct folder to export " + obj_select.Name)
message.setStandardButtons(QtWidgets.QMessageBox.Ok)
message.setDefaultButton(QtWidgets.QMessageBox.Ok)
message.exec_()