-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
237 lines (201 loc) · 9.3 KB
/
main.py
File metadata and controls
237 lines (201 loc) · 9.3 KB
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
# -*- coding: utf-8 -*-
import os.path
import creopyson
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
class MainWindow:
def __init__(self, win):
win.title('Kamil Madej Projekt 1')
win.geometry("800x600")
self.c = creopyson.Client()
self.c.connect()
self.c.creo_set_creo_version(7)
self.create_widgets(win)
self.get_current_values()
win.mainloop()
def validate_input(self, inp):
"""
Sprawdzanie czy wejście jest liczbą
:param inp:
:return:
"""
try:
if inp == "":
return True
elif float(inp):
return True
except:
return False
def create_widgets(self, win):
"""
Stwórz rozkład przycisków wejść i etykiet
:param win:
:return:
"""
# Etykiety
self.titleLabel = Label(win, text="Programowanie API", font=("Arial", 25))
self.currentWorkFolderPathLabel = Label(win, text="Katalog Roboczy", font=("Arial", 11))
self.materialChooseLabel = Label(win, text="Materiał z grupy Ferrous_metals", font=("Arial", 11))
self.boxHeightLabel = Label(win, text="Wysokość pudełka", font=("Arial", 11))
self.boxLengthLabel = Label(win, text="Długość pudełka", font=("Arial", 11))
self.boxDepthLabel = Label(win, text="Głebokość pudełka", font=("Arial", 11))
self.textHeightLabel = Label(win, text="Wysokość tekstu", font=("Arial", 11))
self.textDistFromBoxEdgeLabel = Label(win, text="Odległość tekstu od krawędzi pudełka", font=("Arial", 11))
self.textDepthLabel = Label(win, text="Głębokość tekstu", font=("Arial", 11))
self.textValueLabel = Label(win, text="Napis", font=("Arial", 11))
# Wejścia
self.currentWorkFolderPathInputField = Entry()
self.boxHeightInputField = Entry()
self.boxLengthInputField = Entry()
self.boxDepthInputField = Entry()
self.textHeightInputField = Entry()
self.textDistFromBoxEdgeInputField = Entry()
self.textDepthInputField = Entry()
self.textValueInputField = Entry()
# Przyciski
self.currentWorkFolderPathButton = Button(win, text="Zmień katalog")
self.currentFileButton = Button(win, text="Wybierz plik")
self.submitButton = Button(win, text="Zapisz wymiary")
# Menu wybieralne
materialsList = ["Steel_cast", "Stainless_steel_ferritic", "Steel_HSLA", "Tool_steel_high_speed",
"Steel_low_carbon", "Steel_medium_carbon", "Steel_high_carbon", "Cast_iron_ductile",
"Stainless_steel_austenitic", "Steel_galvanized"]
self.optionVar = StringVar(win)
self.optionVar.set(materialsList[0])
self.materialChooseMenu = OptionMenu(win, self.optionVar, *materialsList)
# Walidacja wejść
req = win.register(self.validate_input)
self.boxHeightInputField.config(validate="key", validatecommand=(req, "%P"))
self.boxLengthInputField.config(validate="key", validatecommand=(req, "%P"))
self.boxDepthInputField.config(validate="key", validatecommand=(req, "%P"))
self.textHeightInputField.config(validate="key", validatecommand=(req, "%P"))
self.textDistFromBoxEdgeInputField.config(validate="key", validatecommand=(req, "%P"))
self.textDepthInputField.config(validate="key", validatecommand=(req, "%P"))
# Układ elementów
btnInternalPaddingX = 10
btnInternalPaddingY = 5
btnOuterPaddingY = 10
self.titleLabel.pack()
self.currentFileButton.pack(ipadx=btnInternalPaddingX, ipady=btnInternalPaddingY, pady=btnOuterPaddingY)
self.currentWorkFolderPathLabel.pack()
self.currentWorkFolderPathInputField.pack(fill="both", padx=10)
self.currentWorkFolderPathButton.pack(ipadx=btnInternalPaddingX, ipady=btnInternalPaddingY,
pady=btnOuterPaddingY)
self.materialChooseLabel.pack()
self.materialChooseMenu.pack()
self.boxHeightLabel.pack()
self.boxHeightInputField.pack()
self.boxLengthLabel.pack()
self.boxLengthInputField.pack()
self.boxDepthLabel.pack()
self.boxDepthInputField.pack()
self.textHeightLabel.pack()
self.textHeightInputField.pack()
self.textDistFromBoxEdgeLabel.pack()
self.textDistFromBoxEdgeInputField.pack()
self.textDepthLabel.pack()
self.textDepthInputField.pack()
self.textValueLabel.pack()
self.textValueInputField.pack()
self.submitButton.pack(ipadx=btnInternalPaddingX, ipady=btnInternalPaddingY, pady=btnOuterPaddingY)
# Event listeners
self.currentWorkFolderPathButton.bind("<Button-1>", self.choose_working_dir)
self.currentFileButton.bind("<Button-1>", self.choose_file)
self.submitButton.bind("<Button-1>", self.save_values)
win.bind("<Return>", self.save_values)
def choose_working_dir(self, event):
"""
Wybieranie katalogu roboczego
:param event:
:return:
"""
path = filedialog.askdirectory(title='Wybierz katalog roboczy')
self.currentWorkFolderPathInputField.delete(0, END)
self.currentWorkFolderPathInputField.insert(0, path)
self.c.creo_cd(path)
def choose_file(self, event):
"""
Wybieranie pliku
:param event:
:return:
"""
filePathObj = filedialog.askopenfile(title="Wybierz plik", filetypes=[("Part", "*.prt")])
filePath = os.path.split(filePathObj.name)[0]
fileName = os.path.split(filePathObj.name)[1]
self.currentWorkFolderPathInputField.delete(0, END)
self.currentWorkFolderPathInputField.insert(0, filePath)
self.c.creo_cd(filePath)
self.c.file_open(fileName)
self.get_current_values()
def save_values(self, event):
"""
Zapisz wartości parametrów i zregeneruj model
:param event:
:return:
"""
# Ścieżka do materiału
creoMatPath = "D:/Creo/Creo 7.0.1.0/Common Files/text/materials-library/Standard-Materials_Granta-Design/Ferrous_metals"
try:
material = self.optionVar.get()
self.c.file_load_material_file(material, creoMatPath)
self.c.file_set_cur_material(material)
except RuntimeError:
messagebox.showerror("Błąd", "Zła ścieżka do folderu z materiałami. Prosze zmienić w kodzie na poprawną")
return
boxLength = float(self.boxLengthInputField.get())
boxHeight = float(self.boxHeightInputField.get())
boxDepth = float(self.boxDepthInputField.get())
textDepth = float(self.textDepthInputField.get())
textHeight = float(self.textHeightInputField.get())
textDistanceFromEdge = float(self.textDistFromBoxEdgeInputField.get())
textValue = self.textValueInputField.get()
workingDirectory = self.currentWorkFolderPathInputField.get()
self.c.parameter_set("W", boxDepth)
self.c.parameter_set("L", boxLength)
self.c.parameter_set("H", boxHeight)
self.c.parameter_set("T_H", textHeight)
self.c.parameter_set("T_L", textDistanceFromEdge)
self.c.parameter_set("T_W", textDepth)
self.c.parameter_set("TEXT", textValue)
self.c.creo_cd(workingDirectory)
self.c.file_regenerate()
self.get_current_values()
self.c.file_save()
messagebox.showinfo("Zapisano", "Poprawnie zapisano")
def get_current_values(self):
"""
Pobierz aktualne wartości parametrów dla modelu
:return:
"""
self.currentWorkFolderPathInputField.delete(0, END)
self.currentWorkFolderPathInputField.insert(0, self.c.creo_pwd())
a = self.c.parameter_list()
for param in a:
if param.get("name") == "H":
self.boxHeightInputField.delete(0, END)
self.boxHeightInputField.insert(0, param.get("value"))
elif param.get("name") == "W":
self.boxDepthInputField.delete(0, END)
self.boxDepthInputField.insert(0, param.get("value"))
elif param.get("name") == "L":
self.boxLengthInputField.delete(0, END)
self.boxLengthInputField.insert(0, param.get("value"))
elif param.get("name") == "T_L":
self.textDistFromBoxEdgeInputField.delete(0, END)
self.textDistFromBoxEdgeInputField.insert(0, param.get("value"))
elif param.get("name") == "T_W":
self.textDepthInputField.delete(0, END)
self.textDepthInputField.insert(0, param.get("value"))
elif param.get("name") == "T_H":
self.textHeightInputField.delete(0, END)
self.textHeightInputField.insert(0, param.get("value"))
elif param.get("name") == "TEXT":
self.textValueInputField.delete(0, END)
self.textValueInputField.insert(0, param.get("value"))
try:
MainWindow(Tk())
except ConnectionError:
messagebox.showerror("Błąd", "Creopyson nie jest włączony")
except RuntimeError:
messagebox.showerror("Błąd", "Creo parametric nie jest włączone")