· 8 years ago · Jun 25, 2018, 02:40 AM
1from __future__ import division
2import Tkinter as tk
3from tkMessageBox import showerror, showwarning
4import ttk
5import win32api
6import win32con
7import comtypes.client
8from PIL import ImageTk, Image
9import getpass
10import os
11from pyautocad import Autocad, APoint, ACAD
12import csv
13import datetime
14from itertools import count, product, islice
15from string import ascii_uppercase
16import shutil
17from comtypes import COMError
18import time
19from decimal import Decimal
20import sys
21
22def multiletters(seq): #method to create a list of Excel style lettering, i.e. A, B, C... Z, AA, AB, AC... AZ, BA, BB etc.
23 for n in count(1):
24 for s in product(seq, repeat=n):
25 yield ''.join(s)
26
27
28def weigh_grid(parent): #method to split the user interface into equally sized cells
29 i = 0
30 while i != (parent.grid_size())[0]:
31 parent.columnconfigure(i, weight=1)
32 i += 1
33 i = 0
34 while i != (parent.grid_size())[1]:
35 parent.rowconfigure(i, weight=1)
36 i += 1
37
38
39class Shared_variables: #class of shared variables used by the other classes
40 button_y_offset = 60
41 jobDetails = {}
42 user = getpass.getuser()
43 dir_path = os.path.dirname(os.path.realpath(sys.argv[0]))
44 turbodoc_path = "L:\\Division2\\DCC\\1-CAD-FORMS\\BALANCE\\"
45 roto_directory = "L:\\Division2\\DCC\\1-CAD-FORMS\\BALANCE\\RotoWorks Data\\"
46 offline_roto_directory = "C:\\Users\\%s\\Documents\\RotoWorks\\" % user
47 online_roto_directory = "L:\\Division2\\DCC\\1-CAD-FORMS\\BALANCE\\RotoWorks Data\\"
48 offline_turbodoc_path = "C:\\Users\\%s\\Documents\\BALANCE\\" % user
49 online_turbodoc_path = "L:\\Division2\\DCC\\1-CAD-FORMS\\BALANCE\\"
50
51
52class App(object): #class to initialize the TK GUI and set its parameters
53 def __init__(self):
54 # this class will serve as the entry point to this application.
55 # it will connect to polyworks and create the main window upon
56 # instantiation.
57
58 # create window
59 self.root = tk.Tk()
60 self.root.title("RotoWorks - Sulzer RES")
61 self.root.resizable(0, 0)
62 self.root.protocol("WM_DELETE_WINDOW", lambda: self.root.destroy())
63 self.width = 500
64 self.height = 550
65 self.screen_width = self.root.winfo_screenwidth()
66 self.screen_height = self.root.winfo_screenheight()
67 self.x = (self.screen_width / 2) - (self.width / 2)
68 self.y = (self.screen_height / 2) - (self.height / 2)
69 self.root.geometry("%dx%d+%d+%d" %
70 (self.width, self.height, self.x, self.y))
71 self.variables = Shared_variables()
72 self.offline_mode_active = tk.IntVar()
73 #self.create_dir() #class to create directory in user documents. Redundant since Roto directory is now in L:\\
74
75 # create style for ttk widgets
76 s = ttk.Style()
77 s.theme_use('clam')
78 s.configure("white.TCheckbutton", background="white")
79
80 # set application icon
81 self.icon = tk.PhotoImage(file=self.variables.dir_path+"\\Graphics\\Sulzer Logo.gif")
82 self.root.tk.call("wm", "iconphoto", self.root._w, self.icon)
83
84 # place frames on window
85 self.frames = dict()
86 self.add_frames(self, 20)
87
88 # instantiate class objects
89 self.menu = Menu(self.root)
90 self.app_start = Main_face(
91 self.frames["f1"], self.width, self.height, self.variables, self.offline_mode_active)
92 self.centrifugal_compressor = CentrifugalCompressor(
93 self.frames["f2"], self.width, self.height, self.variables)
94 self.steam_turbine = SteamTurbine(
95 self.frames["f3"], self.width, self.height, self.variables)
96 self.expander = Expander(
97 self.frames["f4"], self.width, self.height, self.variables)
98
99 # set application state
100 self.frames["f1"].tkraise()
101
102 def add_frames(self, parent, how_many_frames):
103 # method for creating window frames
104 for i in range(how_many_frames):
105 f = tk.Frame(self.root)
106 self.frames["f" + str(i + 1)] = f
107 f.configure(width=parent.width, height=parent.height, bg="white")
108 f.grid_propagate(0)
109 f.place(x=0, y=0)
110
111 def connect_to_polyworks(self):
112 self.key = win32api.RegOpenKeyEx(
113 win32con.HKEY_CLASSES_ROOT, 'InnovMetric.PolyWorks.IMInspect', 0, win32con.KEY_READ)
114 self.clsid = win32api.RegQueryValue(self.key, 'CLSID')
115 self.path = "C:\\Program Files\\InnovMetric\\PolyWorks 2016 (64-bit)\\bin\\iminspect.exe"
116 self.library = comtypes.client.GetModule(self.path)
117 self.init = comtypes.client.CreateObject(self.clsid)
118 self.interface = self.init.QueryInterface(self.library.IIMInspect)
119 self.get_project = self.interface.ProjectGetCurrent()
120 self.command = self.get_project.CommandCenterCreate()
121
122 def create_dir(self):
123 """ this method will create a RotoWorks folder in the user's my documents. """
124 self.user = getpass.getuser()
125 self.path = "C:\\Users\\%s\\Documents\\RotoWorks" % (self.user)
126 if os.path.exists(self.path):
127 return
128 else:
129 os.makedirs(self.path)
130
131
132class AppDialog(object):
133 # App Dialog Class
134 def __init__(self, parent, title, width, height):
135 self.parent = parent
136 self.width = width
137 self.height = height
138 self.portal = tk.Toplevel(
139 height=height, width=width, takefocus=True, bg="white")
140 self.portal.resizable(0, 0)
141 self.portal.grab_set()
142 self.portal.title(title)
143 self.center_window()
144
145 def center_window(self):
146 self.screen_width = self.portal.winfo_screenwidth()
147 self.screen_height = self.portal.winfo_screenheight()
148 self.x = (self.screen_width / 2) - (self.width / 2)
149 self.y = (self.screen_height / 2) - (self.height / 2)
150 self.portal.geometry("%dx%d+%d+%d" %
151 (self.width, self.height, self.x, self.y))
152
153
154class JobWorkspace:
155
156 def New_Job(self):
157 self.window = AppDialog(self, "New Job", 350, 180)
158
159 tk.Label(self.window.portal, text="Machine Type:", bg="white").place(
160 relx=0.5, rely=0.15, anchor="center")
161 self.mach_var = tk.StringVar()
162 ttk.OptionMenu(self.window.portal, self.mach_var, "Choose a machine type", "Multi-Stage Compressor", "Steam Turbine",
163 "Expander", "Overhung Compressor", "Screw Compressor").place(relx=0.5, rely=0.3, anchor="center")
164 tk.Label(self.window.portal, text="Job Number", bg="white").place(
165 relx=0.5, rely=0.5, anchor="center")
166 self.job_number = tk.StringVar()
167 ttk.Entry(self.window.portal, textvariable=self.job_number).place(
168 relx=0.5, rely=0.65, anchor="center")
169 ttk.Button(self.window.portal, text="Continue", command=lambda: self.Start_New_Job(
170 )).place(relx=0.8, y=self.window.height - 25, anchor="center")
171
172 def Start_New_Job(self):
173 self.var = Shared_variables
174
175 if self.mach_var.get() != "Choose a machine type" and len(self.job_number.get()) == 6 and (self.job_number.get()).isdigit():
176 self.var.jobDetails.clear()
177 self.var.jobDetails["Machine Type"] = self.mach_var.get()
178 self.var.jobDetails["Job Number"] = self.job_number.get()
179 if roto.offline_mode_active.get() == 0:
180 self.var.turbodoc_path = self.var.online_turbodoc_path
181 self.var.roto_directory = self.var.online_roto_directory
182 else:
183 self.var.turbodoc_path = self.var.offline_turbodoc_path
184 self.var.roto_directory = self.var.offline_roto_directory
185 print self.var.roto_directory
186 print self.var.turbodoc_path
187 self.Folder_Check(self)
188 self.window.portal.destroy()
189 elif str(self.mach_var.get()) == "Choose a machine type":
190 showerror(title="Error", message="Choose a machine type!")
191 self.window.portal.lift()
192 else:
193 showerror(title="Error", message="Invalid job number!")
194 self.window.portal.lift()
195
196 def Load_Job(self):
197 self.window = AppDialog(self, "Load Job", 350, 180)
198
199 tk.Label(self.window.portal, text="Job Number", bg="white").place(
200 relx=0.5, rely=0.3, anchor="center")
201 self.job_number = tk.StringVar()
202 ttk.Entry(self.window.portal, textvariable=self.job_number).place(
203 relx=0.5, rely=0.5, anchor="center")
204 ttk.Button(self.window.portal, text="Continue", command=lambda: self.Start_Load_Job(
205 )).place(relx=0.8, y=self.window.height - 25, anchor="center")
206
207 def Start_Load_Job(self):
208 self.var = Shared_variables
209
210 if len(self.job_number.get()) == 6 and (self.job_number.get()).isdigit():
211 self.var.jobDetails["Job Number"] = self.job_number.get()
212 if roto.offline_mode_active.get() == 0:
213 self.var.turbodoc_path = self.var.online_turbodoc_path
214 self.var.roto_directory = self.var.online_roto_directory
215 else:
216 self.var.turbodoc_path = self.var.offline_turbodoc_path
217 self.var.roto_directory = self.var.offline_roto_directory
218 print self.var.roto_directory
219 print self.var.turbodoc_path
220 print self.var.jobDetails["Job Number"]
221 try:
222 self.Populate_Job_Details(open(self.var.roto_directory +
223 self.var.jobDetails["Job Number"] + "\\data.csv"))
224 except IOError:
225 showerror(title="Error", message="Job does not exist! Start a new job!")
226 else:
227 self.FrameToRaise()
228 self.window.portal.destroy()
229 else:
230 showerror(title="Error", message="Invalid job number!")
231 self.window.portal.lift()
232
233 def Folder_Check(self, parent):
234 self.parent = parent
235 self.var = Shared_variables
236 if not os.path.exists(self.var.roto_directory + str(self.var.jobDetails['Job Number']) + "\\data.csv"):
237 try:
238 os.makedirs(self.var.roto_directory +
239 self.var.jobDetails['Job Number'])
240 except WindowsError:
241 pass
242 self.Create_Data_File()
243 self.FrameToRaise()
244 else:
245 showwarning("Job Already Exists",
246 "The job you specified already exists! The existing job will be loaded.")
247 self.Populate_Job_Details(open(self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv"))
248 self.FrameToRaise()
249
250 def FrameToRaise(self):
251 if self.var.jobDetails["Machine Type"] == "Multi-Stage Compressor":
252 roto.frames["f2"].tkraise()
253 self.Populate_Job_Details(open(self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv"))
254 roto.centrifugal_compressor.inspection_completion_check()
255 elif self.var.jobDetails["Machine Type"] == "Steam Turbine":
256 roto.frames["f3"].tkraise()
257 self.Populate_Job_Details(open(self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv"))
258 roto.steam_turbine.inspection_completion_check()
259 elif self.var.jobDetails["Machine Type"] == "Expander":
260 roto.frames["f4"].tkraise()
261 self.Populate_Job_Details(open(self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv"))
262 roto.expander.inspection_completion_check()
263
264 def Create_Data_File(self):
265 self.var = Shared_variables
266 self.data_file = open(
267 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", 'a')
268 self.Populate_Data_File(self.data_file)
269
270 def Populate_Data_File(self, data_file):
271 self.data_file = data_file
272 self.var = Shared_variables
273 with self.data_file as csvfile:
274 self.writer = csv.writer(self.data_file, delimiter=",")
275 for key, value in self.var.jobDetails.items():
276 self.writer.writerow([key, value])
277
278 def Populate_Job_Details(self, data_file):
279 self.data_file = data_file
280 self.var = Shared_variables
281 temp_num = self.var.jobDetails["Job Number"]
282 self.var.jobDetails.clear()
283 try:
284 with self.data_file as csv_file:
285 reader = csv.reader(csv_file)
286 self.var.jobDetails = dict(reader)
287 except ValueError as Error:
288 showerror(title="Error", message="Data File is corrupt and will be deleted. Start a new job.\n\n%s" % Error)
289 os.remove(str(self.var.roto_directory + temp_num + "\\data.csv"))
290
291 def check_for_document(self, method):
292 """ this method will try obtaining the active
293 document and will not move forward until
294 this connection has been established.
295 """
296 self.method = method
297 while True:
298 try:
299 self.acad = Autocad()
300 self.acad = self.acad.doc
301 except:
302 continue
303 else:
304 break
305 self.method()
306
307 def loading_window(self, parent, method, text):
308 self.parent = parent
309 self.text = text
310
311 loading_window = AppDialog(self.parent, "", 350, 150)
312 loading_window.portal.config(bd="10", relief="raised")
313 loading_window.portal.overrideredirect(True)
314
315 tk.Label(loading_window.portal, text=text, font="Helvetica 18 bold", bg="white").place(
316 relx=0.5, rely=0.5, anchor="center")
317 loading_window.portal.update()
318 method()
319 loading_window.portal.destroy()
320
321
322class Menu(object):
323 """ This class will contain all items listed in the application menu bar. """
324
325 def __init__(self, parent):
326 self.parent = parent
327 self.menu_bar = tk.Menu(self.parent)
328 self.file_menu = tk.Menu(self.menu_bar, tearoff=0)
329 self.var = Shared_variables()
330 job = JobWorkspace()
331 self.file_menu.add_command(
332 label="New Job", command=lambda: job.New_Job())
333 self.file_menu.add_command(
334 label="Load Job", command=lambda: job.Load_Job())
335 self.file_menu.add_command(
336 label="Create TurboDoc", state="normal", command=lambda: Create_turbodoc())
337 self.file_menu.add_command(
338 label="Begin Quality Control", state="disabled")
339 self.menu_bar.add_cascade(label="File", menu=self.file_menu)
340 self.file_menu.add_command(
341 label="Exit", command=lambda: parent.destroy())
342 self.parent.config(menu=self.menu_bar)
343
344
345class Main_face(object):
346 def __init__(self, parent, width, height, var, offlinemode):
347 """ this class will serve as the initial interface to this application """
348
349 # Window Dimension Constant
350 self.parent = parent
351 self.width = width
352 self.height = height
353 self.var = var
354 self.button_width = 15
355 self.variables = Shared_variables()
356 self.offline_mode_active = offlinemode
357
358 # place application logo on frame
359 self.img = ImageTk.PhotoImage(Image.open(self.variables.dir_path+"\\Graphics\\App Logo.jpg"))
360 self.img2 = ImageTk.PhotoImage(Image.open(self.variables.dir_path+"\\Graphics\\App Logo 2.png"))
361 self.img_label = tk.Label(self.parent, image=self.img, bd=0)
362 self.img_label.image = self.img
363 self.img_label_2 = tk.Label(self.parent, image=self.img2, bd=0)
364 self.img_label_2.image = self.img2
365 self.img_label.place(relx=0.5, rely=0.16, anchor="center")
366 self.img_label_2.place(relx=0.5, rely=0.6, anchor="center")
367 self.disclaimer = tk.Label(self.parent, text="Developed by Sulzer Employees, Est 2016.\nVersion 1.1",
368 font="Helvetica 10 bold", bg="white", fg="blue")
369 self.disclaimer.place(relx=0.5, rely=0.93, anchor="center")
370 offline_mode_active = tk.IntVar()
371 ttk.Checkbutton(self.parent, variable=self.offline_mode_active,
372 style="white.TCheckbutton", text="offline mode").place(relx=0.5, rely=0.85, anchor="center")
373
374
375class CentrifugalCompressor(object):
376 def __init__(self, parent, width, height, var):
377 """ this class will serve as the interface to centrifugal compressor projects.
378 the data gathered here will be inserted into polyworks to begin inspection.
379 """
380 self.parent = parent
381 self.width = width
382 self.height = height
383 self.var = var
384 self.jobSpace = JobWorkspace()
385 self.number_of_stages = tk.IntVar()
386 self.check_box_dict = {}
387 self.stagetempvar = {}
388 self.completion_check = {}
389 self.completion_color = {}
390 self.create_widgets()
391
392 self.check_box_dict = {}
393 self.num_of_stages = {}
394 self.stagetempvar = {}
395
396 def inspection_completion_check(self):
397 try:
398 self.icc_1.destroy()
399 self.icc_2.destroy()
400 self.icc_3.destroy()
401 self.icc_4.destroy()
402 self.icc_5.destroy()
403 self.icc_6.destroy()
404 except AttributeError:
405 pass
406
407 try:
408 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Visual_Inspection.csv'):
409 self.completion_check["Visual Inspection"] = "Complete"
410 self.completion_color["Visual Inspection"] = "Dark Green"
411 else:
412 self.completion_check["Visual Inspection"] = "Incomplete"
413 self.completion_color["Visual Inspection"] = "Red"
414
415 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Axial_Inspection.csv'):
416 self.completion_check["Axial Inspection"] = "Complete"
417 self.completion_color["Axial Inspection"] = "Dark Green"
418 else:
419 self.completion_check["Axial Inspection"] = "Incomplete"
420 self.completion_color["Axial Inspection"] = "Red"
421
422 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\OD_Inspection.csv'):
423 self.completion_check["OD Inspection"] = "Complete"
424 self.completion_color["OD Inspection"] = "Dark Green"
425 else:
426 self.completion_check["OD Inspection"] = "Incomplete"
427 self.completion_color["OD Inspection"] = "Red"
428
429 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Check_Balance.csv'):
430 self.completion_check["Check Balance"] = "Complete"
431 self.completion_color["Check Balance"] = "Dark Green"
432 else:
433 self.completion_check["Check Balance"] = "Incomplete"
434 self.completion_color["Check Balance"] = "Red"
435 except KeyError:
436 pass
437
438 try:
439 self.icc_1 = tk.Label(self.parent, text=self.completion_check[
440 "Visual Inspection"], bg="white", fg=self.completion_color["Visual Inspection"], font=("Arial 10 bold"))
441 self.icc_1.grid(column=2, row=2)
442 self.icc_2 = tk.Label(self.parent, text=self.completion_check[
443 "Axial Inspection"], bg="white", fg=self.completion_color["Axial Inspection"], font=("Arial 10 bold"))
444 self.icc_2.grid(column=2, row=3)
445 self.icc_3 = tk.Label(self.parent, text=self.completion_check[
446 "OD Inspection"], bg="white", fg=self.completion_color["OD Inspection"], font=("Arial 10 bold"))
447 self.icc_3.grid(column=2, row=4)
448 self.icc_4 = tk.Label(self.parent, text=self.completion_check[
449 "Check Balance"], bg="white", fg=self.completion_color["Check Balance"], font=("Arial 10 bold"))
450 self.icc_4.grid(column=2, row=5)
451 except KeyError:
452 pass
453
454 try:
455 self.icc_5 = tk.Label(self.parent, text=(self.var.jobDetails[
456 "Axial Inspection Start Time"] + "\n" + self.var.jobDetails["Axial Inspector Initials"]), bg="White", font=("Arial 10"))
457 self.icc_5.grid(column=3, row=3, columnspan=2)
458 except KeyError:
459 pass
460
461 try:
462 self.icc_6 = tk.Label(self.parent, text=(self.var.jobDetails[
463 "OD Inspection Start Time"] + "\n" + self.var.jobDetails["OD Inspector Initials"]), bg="White", font=("Arial 10"))
464 self.icc_6.grid(column=3, row=4, columnspan=2)
465 except KeyError:
466 pass
467
468 weigh_grid(self.parent)
469
470 def create_widgets(self):
471 tk.Label(self.parent, text="Multi-Stage Compressor",
472 font=("Arial 18 bold"), bg="white").grid(column=0, row=0, columnspan=5)
473
474 ttk.Button(self.parent, text="Equipment Details", width=20, command=lambda: self.equipment_details(
475 )).grid(column=0, row=1, columnspan=2, sticky="ns")
476 ttk.Button(self.parent, text="Unavailable", width=20).grid(
477 column=0, row=2, columnspan=2, sticky="ns")
478 ttk.Button(self.parent, text="Axial Inspection", width=20, command=lambda: self.axial_inspection_window(
479 )).grid(column=0, row=3, columnspan=2, sticky="ns")
480 ttk.Button(self.parent, text="OD Inspection", width=20, command=lambda: self.OD_inspection_window(
481 )).grid(column=0, row=4, columnspan=2, sticky="ns")
482 ttk.Button(self.parent, text="Unavailable", width=20).grid(
483 column=0, row=5, columnspan=2, sticky="ns")
484
485 ttk.Button(self.parent, text="Check Inspections",
486 command=lambda: self.inspection_completion_check()).grid(column=4, row=1)
487
488 ttk.Button(self.parent, text="Back", command=lambda: self.back_button()).grid(
489 column=0, row=8, columnspan=2, pady=10)
490
491 weigh_grid(self.parent)
492
493 def back_button(self):
494 roto.frames["f1"].tkraise()
495 self.var.jobDetails.clear()
496
497 def equipment_details(self):
498 self.equipment_window = AppDialog(self, "Equipment Details", 350, 400)
499
500 tk.Label(self.equipment_window.portal, text="Job Number", font=(
501 "Arial 10 bold"), bg="white").place(relx=0.5, y=25, anchor="center")
502 self.job_number_entry = tk.StringVar()
503 try:
504 self.job_number_entry.set(self.var.jobDetails["Job Number"])
505 except KeyError:
506 pass
507 ttk.Entry(self.equipment_window.portal, textvariable=self.job_number_entry).place(
508 relx=0.5, y=50, anchor="center")
509
510 tk.Label(self.equipment_window.portal, text="Number of Stages", font=(
511 "Arial 10 bold"), bg="white").place(relx=0.5, y=75, anchor="center")
512 self.number_of_stages_entry = tk.IntVar()
513 try:
514 self.number_of_stages_entry.set(
515 self.var.jobDetails["Number of Stages"])
516 except KeyError:
517 pass
518 ttk.Entry(self.equipment_window.portal, textvariable=self.number_of_stages_entry).place(
519 relx=0.5, y=100, anchor="center")
520
521 tk.Label(self.equipment_window.portal, text="Open Face Stages", font=(
522 "Arial 10 bold"), bg="white").place(relx=0.5, y=125, anchor="center")
523
524 self.on_trace_check_box(varname="PY_VAR7", elementname=None, mode="w")
525 i = 1
526 while i <= int(self.number_of_stages_entry.get()):
527 try:
528 self.stagetempvar[i].set(
529 self.var.jobDetails["Stage %i Face" % i])
530 except KeyError:
531 continue
532 finally:
533 i += 1
534
535 self.number_of_stages_entry.trace("w", self.on_trace_check_box)
536
537 tk.Label(self.equipment_window.portal, text="Balance Drum", font=(
538 "Arial 10 bold"), bg="white").place(relx=0.33, y=175, anchor="center")
539 tk.Label(self.equipment_window.portal, text="Thrust Collar", font=(
540 "Arial 10 bold"), bg="white").place(relx=0.66, y=175, anchor="center")
541
542 self.balance_drum_entry = tk.IntVar()
543 try:
544 self.balance_drum_entry.set(self.var.jobDetails["Balance Drum"])
545 except KeyError:
546 pass
547 ttk.Checkbutton(self.equipment_window.portal, variable=self.balance_drum_entry,
548 style="white.TCheckbutton").place(relx=0.33, y=200, anchor="center")
549
550 self.thrust_collar_entry = tk.IntVar()
551 try:
552 self.thrust_collar_entry.set(self.var.jobDetails["Thrust Collar"])
553 except KeyError:
554 pass
555 ttk.Checkbutton(self.equipment_window.portal, variable=self.thrust_collar_entry,
556 style="white.TCheckbutton").place(relx=0.66, y=200, anchor="center")
557
558 ttk.Button(self.equipment_window.portal, text="OK", command=lambda: self.job_detail_update(
559 )).place(relx=0.5, y=400 - self.var.button_y_offset, anchor="center")
560
561 def on_trace_check_box(self, varname, elementname, mode):
562 for key in self.check_box_dict:
563 self.check_box_dict[key].destroy()
564 try:
565 if self.number_of_stages_entry.get() <= 15:
566 i = 1
567 self.stagetempvar.clear()
568 while i <= self.number_of_stages_entry.get():
569 self.stagetempvar[i] = tk.StringVar()
570 self.stagetempvar[i].set("Closed")
571 self.check_box_dict[i] = ttk.Checkbutton(
572 self.equipment_window.portal, text=i, offvalue="Closed", onvalue="Open", variable=self.stagetempvar[i], style="white.TCheckbutton")
573 self.check_box_dict[i].place(
574 relx=(i * (1 / (self.number_of_stages_entry.get() + 1))), y=150, anchor="center")
575 i += 1
576 except ValueError:
577 pass
578
579 def job_detail_update(self):
580 self.var.jobDetails["Job Number"] = self.job_number_entry.get()
581 self.var.jobDetails["Number of Stages"] = self.number_of_stages_entry.get()
582 self.var.jobDetails["Balance Drum"] = self.balance_drum_entry.get()
583 self.var.jobDetails["Thrust Collar"] = self.thrust_collar_entry.get()
584 for key in self.stagetempvar:
585 self.var.jobDetails[
586 "Stage " + str(key) + " Face"] = self.stagetempvar[key].get()
587
588 print self.var.jobDetails
589
590 self.jobSpace.Populate_Data_File(open(
591 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
592 self.equipment_window.portal.destroy()
593
594 def OD_inspection_window(self):
595 self.OD_window = AppDialog(self, "OD Inspection", 350, 250)
596
597 tk.Label(self.OD_window.portal, text="Inspector Initials", font=(
598 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
599 self.OD_inspector_initials_entry = tk.StringVar()
600 ttk.Entry(self.OD_window.portal, textvariable=self.OD_inspector_initials_entry).place(
601 relx=0.5, y=90, anchor="center")
602
603 tk.Label(self.OD_window.portal, text="Date and Time of Inspection Start", font=(
604 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
605 self.OD_datetime_start_TK = tk.StringVar()
606 now = datetime.datetime.now()
607 self.OD_datetime_start_TK.set(now.strftime("%I:%M %p %m/%d/%Y"))
608 tk.Label(self.OD_window.portal, textvariable=self.OD_datetime_start_TK, font=(
609 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
610
611 ttk.Button(self.OD_window.portal, text="Start Inspection", command=lambda: self.start_OD_inspection(
612 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
613
614 def start_OD_inspection(self):
615 try:
616 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
617 except WindowsError as Error:
618 showerror(
619 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
620 self.OD_window.portal.destroy()
621 else:
622 self.var.jobDetails[
623 "OD Inspection Start Time"] = self.OD_datetime_start_TK.get()
624 self.var.jobDetails[
625 "OD Inspector Initials"] = self.OD_inspector_initials_entry.get()
626 self.jobSpace.Populate_Data_File(open(
627 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
628 try:
629 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
630 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
631 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
632
633 macropath = file("Macros\Multistage Compressor OD Inspection")
634 roto.command.CommandExecute(
635 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
636 except COMError as Error:
637 showerror(title="Error", message=str(
638 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
639 except AttributeError as Error:
640 showerror(title="Error", message="%s\nMake sure PolyWorks and IMInspect are open, then retry." % Error)
641
642 self.OD_window.portal.destroy()
643
644 def axial_inspection_window(self):
645 self.axial_window = AppDialog(self, "Axial Inspection", 350, 250)
646
647 tk.Label(self.axial_window.portal, text="Inspector Initials", font=(
648 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
649 self.axial_inspector_initials_entry = tk.StringVar()
650 ttk.Entry(self.axial_window.portal, textvariable=self.axial_inspector_initials_entry).place(
651 relx=0.5, y=90, anchor="center")
652
653 tk.Label(self.axial_window.portal, text="Date and Time of Inspection Start", font=(
654 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
655 self.axial_datetime_start_TK = tk.StringVar()
656 now = datetime.datetime.now()
657 self.axial_datetime_start_TK.set(
658 now.strftime("%I:%M %p %m/%d/%Y"))
659 tk.Label(self.axial_window.portal, textvariable=self.axial_datetime_start_TK, font=(
660 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
661
662 ttk.Button(self.axial_window.portal, text="Start Inspection", command=lambda: self.start_axial_inspection(
663 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
664
665 ttk.Button(self.axial_window.portal, text="Thermal Gaps and Journal Weights", command=lambda: self.thermal_gap_entry(
666 )).place(relx=0.5, y=285 - self.var.button_y_offset, anchor="center")
667
668 def start_axial_inspection(self):
669 try:
670 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
671 except WindowsError as Error:
672 showerror(
673 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
674 self.axial_window.portal.destroy()
675 else:
676 self.var.jobDetails[
677 "Axial Inspection Start Time"] = self.axial_datetime_start_TK.get()
678 self.var.jobDetails[
679 "Axial Inspector Initials"] = self.axial_inspector_initials_entry.get()
680 self.jobSpace.Populate_Data_File(open(
681 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
682 self.axial_window.portal.destroy()
683 self.thermal_gap_entry()
684 self.create_axial_features()
685
686 def create_axial_features(self):
687 # begin executing features
688 try:
689 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
690 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
691 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
692
693 roto.command.CommandExecute(
694 'FEATURE PLANE CREATE ("Thrust End of Shaft")')
695
696 if str(self.var.jobDetails["Thrust Collar"]) == "1":
697 roto.command.CommandExecute('FEATURE PLANE CREATE ("Inactive Thrust Shoulder")')
698
699 roto.command.CommandExecute(
700 'FEATURE PLANE CREATE ("Active Thrust Shoulder")')
701 roto.command.CommandExecute(
702 'FEATURE CYLINDER CREATE ("TE Bearing Journal")')
703
704 i = 1
705 while i <= int(self.var.jobDetails["Number of Stages"]):
706 if self.var.jobDetails["Stage " + str(i) + " Face"] == "Open":
707 roto.command.CommandExecute(
708 'FEATURE PLANE CREATE ("Stage %d Eye Face")' % i)
709 roto.command.CommandExecute(
710 'FEATURE PLANE CREATE ("Stage %d Trailing Edge")' % i)
711 roto.command.CommandExecute(
712 'FEATURE PLANE CREATE ("Stage %d IBP")' % i)
713 roto.command.CommandExecute(
714 'FEATURE PLANE CREATE ("Stage %d OBP")' % i)
715 else:
716 roto.command.CommandExecute(
717 'FEATURE PLANE CREATE ("Stage %d Eye Face")' % i)
718 roto.command.CommandExecute(
719 'FEATURE PLANE CREATE ("Stage %d IBP")' % i)
720 roto.command.CommandExecute(
721 'FEATURE PLANE CREATE ("Stage %d ICP")' % i)
722 # continue executing end features
723 i += 1
724
725 if str(self.var.jobDetails["Balance Drum"]) == "1":
726 roto.command.CommandExecute('FEATURE PLANE CREATE ("BD Face")')
727
728 roto.command.CommandExecute(
729 'FEATURE PLANE CREATE ("Non-Thrust End of Shaft")')
730
731 macropath = file("Macros\Multistage Compressor Axial Inspection")
732 roto.command.CommandExecute(
733 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
734 except COMError as Error:
735 showerror(title="Error", message=str(
736 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
737 except AttributeError as Error:
738 showerror(title="Error", message=str(
739 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
740
741 def thermal_gap_entry(self):
742 self.thermal_gap_window = AppDialog(self, "Thermal Gaps", 250, 700)
743
744 self.thermal_gap_notebook = ttk.Notebook(
745 self.thermal_gap_window.portal)
746 self.thermal_gap_frame = tk.Frame(
747 self.thermal_gap_notebook, bg="white")
748 self.journal_weights_frame = tk.Frame(
749 self.thermal_gap_notebook, bg="white")
750 self.thermal_gap_notebook.add(
751 self.thermal_gap_frame, text="Thermal Gaps")
752 self.thermal_gap_notebook.add(
753 self.journal_weights_frame, text="Journal Weights")
754 self.thermal_gap_notebook.pack(fill="both", expand=1)
755
756 self.thermal_gap_temp_var = {}
757 thermal_gap_labels = ("A", "B", "C", "D", "E",
758 "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R")
759
760 i = 0
761 while i < len(thermal_gap_labels):
762 tk.Label(self.thermal_gap_frame, text=thermal_gap_labels[i], font=(
763 "Arial 18 bold"), bg="white").grid(column=0, row=(2 * i + 1))
764 self.thermal_gap_temp_var["Thermal Gap " + thermal_gap_labels[i]] = tk.StringVar()
765 try:
766 self.thermal_gap_temp_var[
767 "Thermal Gap " + thermal_gap_labels[i]].set(self.var.jobDetails["Thermal Gap " + thermal_gap_labels[i]])
768 except KeyError:
769 pass
770 ttk.Entry(self.thermal_gap_frame, textvariable=self.thermal_gap_temp_var[
771 "Thermal Gap " + thermal_gap_labels[i]]).grid(column=1, row=(2 * i + 1))
772 i += 1
773
774 tk.Label(self.journal_weights_frame, text="Coupling/Non-Thrust End\nBearing Journal Weight",
775 font=("Arial 10 bold"), bg="white").grid(column=0, row=1, columnspan=2)
776 self.NTE_bearing_journal_weight = tk.StringVar()
777 try:
778 self.NTE_bearing_journal_weight.set(self.var.jobDetails["NTE BJ Weight"])
779 except KeyError:
780 pass
781 ttk.Entry(self.journal_weights_frame, textvariable=self.NTE_bearing_journal_weight).grid(
782 column=0, row=2, columnspan=2)
783
784 tk.Label(self.journal_weights_frame, text="Thrust End\nBearing Journal Weight", font=(
785 "Arial 10 bold"), bg="white").grid(column=0, row=3, columnspan=2)
786 self.TE_bearing_journal_weight = tk.StringVar()
787 try:
788 self.TE_bearing_journal_weight.set(self.var.jobDetails["TE BJ Weight"])
789 except KeyError:
790 pass
791 ttk.Entry(self.journal_weights_frame, textvariable=self.TE_bearing_journal_weight).grid(
792 column=0, row=4, columnspan=2)
793
794 tk.Label(self.journal_weights_frame, text="Total\nBearing Journal Weight", font=(
795 "Arial 10 bold"), bg="white").grid(column=0, row=5, columnspan=2)
796 self.total_bearing_journal_weight = tk.StringVar()
797 try:
798 self.total_bearing_journal_weight.set(self.var.jobDetails["Overall Weight"])
799 except KeyError:
800 pass
801 ttk.Entry(self.journal_weights_frame, textvariable=self.total_bearing_journal_weight).grid(
802 column=0, row=6, columnspan=2)
803
804 ttk.Button(self.thermal_gap_frame, text="Done", command=lambda: self.thermal_gap_update(
805 )).grid(column=0, row=(2 * i + 2), columnspan=2)
806 ttk.Button(self.journal_weights_frame, text="Done", command=lambda: self.thermal_gap_update(
807 )).grid(column=0, row=(2 * i + 2), columnspan=2)
808
809 weigh_grid(self.thermal_gap_frame)
810 weigh_grid(self.journal_weights_frame)
811
812 def thermal_gap_update(self):
813 for key in self.thermal_gap_temp_var:
814 try:
815 del self.var.jobDetails[key]
816 except KeyError:
817 pass
818 print "%s Deleted" % key
819 if self.thermal_gap_temp_var[key].get():
820 self.var.jobDetails[key] = self.thermal_gap_temp_var[key].get()
821 print "%s Replaced" % key
822
823 self.var.jobDetails[
824 "TE BJ Weight"] = self.TE_bearing_journal_weight.get()
825 self.var.jobDetails[
826 "NTE BJ Weight"] = self.NTE_bearing_journal_weight.get()
827 self.var.jobDetails[
828 "Overall Weight"] = self.total_bearing_journal_weight.get()
829
830 for key in self.thermal_gap_temp_var:
831 print "%s:%s" % (key, self.thermal_gap_temp_var[key].get())
832
833 print self.var.jobDetails
834
835 self.jobSpace.Populate_Data_File(open(
836 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w+"))
837 self.thermal_gap_window.portal.destroy()
838
839 #def check_balance(self):
840
841
842class SteamTurbine(object):
843 def __init__(self, parent, width, height, var):
844 """ this class will serve as the interface to centrifugal compressor projects.
845 the data gathered here will be inserted into polyworks to begin inspection.
846 """
847 self.parent = parent
848 self.width = width
849 self.height = height
850 self.var = var
851 self.jobSpace = JobWorkspace()
852 self.number_of_stages = tk.IntVar()
853 self.check_box_dict = {}
854 self.stagetempvar = {}
855 self.completion_check = {}
856 self.completion_color = {}
857 self.create_widgets()
858
859 self.check_box_dict = {}
860 self.num_of_stages = {}
861 self.stagetempvar = {}
862
863 def inspection_completion_check(self):
864 try:
865 self.icc_1.destroy()
866 self.icc_2.destroy()
867 self.icc_3.destroy()
868 self.icc_4.destroy()
869 self.icc_5.destroy()
870 self.icc_6.destroy()
871 except AttributeError:
872 pass
873
874 try:
875 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Visual_Inspection.csv'):
876 self.completion_check["Visual Inspection"] = "Complete"
877 self.completion_color["Visual Inspection"] = "Dark Green"
878 else:
879 self.completion_check["Visual Inspection"] = "Incomplete"
880 self.completion_color["Visual Inspection"] = "Red"
881
882 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Axial_Inspection.csv'):
883 self.completion_check["Axial Inspection"] = "Complete"
884 self.completion_color["Axial Inspection"] = "Dark Green"
885 else:
886 self.completion_check["Axial Inspection"] = "Incomplete"
887 self.completion_color["Axial Inspection"] = "Red"
888
889 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\OD_Inspection.csv'):
890 self.completion_check["OD Inspection"] = "Complete"
891 self.completion_color["OD Inspection"] = "Dark Green"
892 else:
893 self.completion_check["OD Inspection"] = "Incomplete"
894 self.completion_color["OD Inspection"] = "Red"
895
896 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Check_Balance.csv'):
897 self.completion_check["Check Balance"] = "Complete"
898 self.completion_color["Check Balance"] = "Dark Green"
899 else:
900 self.completion_check["Check Balance"] = "Incomplete"
901 self.completion_color["Check Balance"] = "Red"
902 except KeyError:
903 pass
904
905 try:
906 self.icc_1 = tk.Label(self.parent, text=self.completion_check[
907 "Visual Inspection"], bg="white", fg=self.completion_color["Visual Inspection"], font=("Arial 10 bold"))
908 self.icc_1.grid(column=2, row=2)
909 self.icc_2 = tk.Label(self.parent, text=self.completion_check[
910 "Axial Inspection"], bg="white", fg=self.completion_color["Axial Inspection"], font=("Arial 10 bold"))
911 self.icc_2.grid(column=2, row=3)
912 self.icc_3 = tk.Label(self.parent, text=self.completion_check[
913 "OD Inspection"], bg="white", fg=self.completion_color["OD Inspection"], font=("Arial 10 bold"))
914 self.icc_3.grid(column=2, row=4)
915 self.icc_4 = tk.Label(self.parent, text=self.completion_check[
916 "Check Balance"], bg="white", fg=self.completion_color["Check Balance"], font=("Arial 10 bold"))
917 self.icc_4.grid(column=2, row=5)
918 except KeyError:
919 pass
920
921 try:
922 self.icc_5 = tk.Label(self.parent, text=(self.var.jobDetails[
923 "Axial Inspection Start Time"] + "\n" + self.var.jobDetails["Axial Inspector Initials"]), bg="White", font=("Arial 10"))
924 self.icc_5.grid(column=3, row=3, columnspan=2)
925 except KeyError:
926 pass
927
928 try:
929 self.icc_6 = tk.Label(self.parent, text=(self.var.jobDetails[
930 "OD Inspection Start Time"] + "\n" + self.var.jobDetails["OD Inspector Initials"]), bg="White", font=("Arial 10"))
931 self.icc_6.grid(column=3, row=4, columnspan=2)
932 except KeyError:
933 pass
934
935 weigh_grid(self.parent)
936
937 def create_widgets(self):
938 self.title = tk.Label(self.parent, text="Steam Turbine", font=(
939 "Arial 18 bold"), bg="white").grid(column=0, row=0, columnspan=5)
940
941 ttk.Button(self.parent, text="Equipment Details", width=20, command=lambda: self.equipment_details(
942 )).grid(column=0, row=1, columnspan=2, sticky="ns")
943 ttk.Button(self.parent, text="Visual Inspection\nUnavailable", width=20).grid(
944 column=0, row=2, columnspan=2, sticky="ns")
945 ttk.Button(self.parent, text="Axial Inspection", width=20, command=lambda: self.axial_inspection_window(
946 )).grid(column=0, row=3, columnspan=2, sticky="ns")
947 ttk.Button(self.parent, text="OD Inspection", width=20, command=lambda: self.OD_inspection_window(
948 )).grid(column=0, row=4, columnspan=2, sticky="ns")
949 ttk.Button(self.parent, text="Check Balance\nUnavailable", width=20).grid(
950 column=0, row=5, columnspan=2, sticky="ns")
951
952 ttk.Button(self.parent, text="Check Inspections",
953 command=lambda: self.inspection_completion_check()).grid(column=4, row=1)
954
955 ttk.Button(self.parent, text="Back", command=lambda: self.back_button()).grid(
956 column=0, row=8, columnspan=2, pady=10)
957
958 weigh_grid(self.parent)
959
960 def back_button(self):
961 roto.frames["f1"].tkraise()
962 self.var.jobDetails.clear()
963
964 def equipment_details(self):
965 self.equipment_window = AppDialog(self, "Equipment Details", 350, 400)
966
967 tk.Label(self.equipment_window.portal, text="Job Number", font=(
968 "Arial 10 bold"), bg="white").place(relx=0.5, y=25, anchor="center")
969 self.job_number_entry = tk.StringVar()
970 try:
971 self.job_number_entry.set(self.var.jobDetails["Job Number"])
972 except KeyError:
973 pass
974 ttk.Entry(self.equipment_window.portal, textvariable=self.job_number_entry).place(
975 relx=0.5, y=50, anchor="center")
976
977 tk.Label(self.equipment_window.portal, text="Number of Stages (R+C)", font=(
978 "Arial 10 bold"), bg="white").place(relx=0.5, y=75, anchor="center")
979 self.number_of_stages_entry = tk.IntVar()
980 try:
981 self.number_of_stages_entry.set(
982 self.var.jobDetails["Number of Stages"])
983 except KeyError:
984 pass
985 ttk.Entry(self.equipment_window.portal, textvariable=self.number_of_stages_entry).place(
986 relx=0.5, y=100, anchor="center")
987
988 tk.Label(self.equipment_window.portal, text="Turbine Features", font=(
989 "Arial 10 bold"), bg="white").place(relx=0.5, y=125, anchor="center")
990
991 self.on_trace_check_box(varname="PY_VAR7", elementname=None, mode="w")
992 i = 1
993 while i <= int(self.number_of_stages_entry.get()):
994 try:
995 self.stagetempvar[i].set(
996 self.var.jobDetails["Stage %i Shroud" % i])
997 except KeyError:
998 continue
999 finally:
1000 i += 1
1001
1002 self.number_of_stages_entry.trace("w", self.on_trace_check_box)
1003
1004 tk.Label(self.equipment_window.portal, text="Curtis Stages", font=(
1005 "Arial 10 bold"), bg="white").place(relx=0.25, y=200, anchor="center")
1006 tk.Label(self.equipment_window.portal, text="Dual Thrust Collar", font=(
1007 "Arial 10 bold"), bg="white").place(relx=0.75, y=200, anchor="center")
1008
1009 self.curtis_stages_entry = tk.IntVar()
1010 try:
1011 self.curtis_stages_entry.set(self.var.jobDetails["Curtis Stages"])
1012 except KeyError:
1013 pass
1014 ttk.Checkbutton(self.equipment_window.portal, variable=self.curtis_stages_entry,
1015 style="white.TCheckbutton").place(relx=0.25, y=225, anchor="center")
1016
1017 self.thrust_collar_entry = tk.IntVar()
1018 try:
1019 self.thrust_collar_entry.set(self.var.jobDetails["Dual Thrust Collars"])
1020 except KeyError:
1021 pass
1022 ttk.Checkbutton(self.equipment_window.portal, variable=self.thrust_collar_entry,
1023 style="white.TCheckbutton").place(relx=0.75, y=225, anchor="center")
1024
1025 tk.Label(self.equipment_window.portal, text="Other Measurements (from Active Thrust Face)", font=(
1026 "Arial 10 bold"), bg="white").place(relx=0.50, y=250, anchor="center")
1027
1028 self.other_measurements_entry = tk.IntVar()
1029 try:
1030 self.other_measurements_entry.set(
1031 self.var.jobDetails["Other Measurements"])
1032 except KeyError:
1033 pass
1034 ttk.Entry(self.equipment_window.portal, textvariable=self.other_measurements_entry).place(
1035 relx=0.5, y=275, anchor="center")
1036
1037
1038 ttk.Button(self.equipment_window.portal, text="OK", command=lambda: self.job_detail_update(
1039 )).place(relx=0.5, y=400 - self.var.button_y_offset, anchor="center")
1040
1041 def on_trace_check_box(self, varname, elementname, mode):
1042 for key in self.check_box_dict:
1043 self.check_box_dict[key].destroy()
1044 try:
1045 if self.number_of_stages_entry.get() <= 20:
1046 i = 1
1047 self.stagetempvar.clear()
1048 while i <= self.number_of_stages_entry.get():
1049 #self.stagetempvar[i] = tk.StringVar()
1050 #self.stagetempvar[i].set("Shrouded")
1051 self.check_box_dict[i] = ttk.Menubutton(
1052 self.equipment_window.portal, text=i, width=0.1)
1053 self.check_box_dict[i].menu = tk.Menu(self.check_box_dict[i], tearoff=0)
1054 self.check_box_dict[i]['menu'] = self.check_box_dict[i].menu
1055 sb = self.stagetempvar["Shroud Band %s" % i] = tk.IntVar()
1056 be = self.stagetempvar["Blade Edge %s" % i] = tk.IntVar()
1057 br = self.stagetempvar["Blade Root %s" % i] = tk.IntVar()
1058 try:
1059 sb.set(self.var.jobDetails["Shroud Band %s" % i])
1060 be.set(self.var.jobDetails["Blade Edge %s" % i])
1061 br.set(self.var.jobDetails["Blade Root %s" % i])
1062 except KeyError:
1063 pass
1064 self.check_box_dict[i].menu.add_checkbutton(label='Shroud Band', variable=self.stagetempvar["Shroud Band %s" % i])
1065 self.check_box_dict[i].menu.add_checkbutton(label='Blade Edge', variable=self.stagetempvar["Blade Edge %s" % i])
1066 self.check_box_dict[i].menu.add_checkbutton(label='Blade Root', variable=self.stagetempvar["Blade Root %s" % i])
1067 self.check_box_dict[i].place(
1068 relx=(i * (1 / (self.number_of_stages_entry.get() + 1))), y=150, anchor="center")
1069 i += 1
1070 except ValueError:
1071 pass
1072
1073 def job_detail_update(self):
1074 print self.var.jobDetails
1075
1076 self.var.jobDetails["Job Number"] = self.job_number_entry.get()
1077 self.var.jobDetails["Number of Stages"] = self.number_of_stages_entry.get()
1078 self.var.jobDetails["Dual Thrust Collars"] = self.thrust_collar_entry.get()
1079 self.var.jobDetails["Curtis Stages"] = self.curtis_stages_entry.get()
1080 self.var.jobDetails["Other Measurements"] = self.other_measurements_entry.get()
1081
1082 for key in self.stagetempvar:
1083 self.var.jobDetails[key] = self.stagetempvar[key].get()
1084
1085 self.jobSpace.Populate_Data_File(open(
1086 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w+"))
1087 self.equipment_window.portal.destroy()
1088
1089 def OD_inspection_window(self):
1090 self.OD_window = AppDialog(self, "OD Inspection", 350, 250)
1091
1092 tk.Label(self.OD_window.portal, text="Inspector Initials", font=(
1093 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
1094 self.OD_inspector_initials_entry = tk.StringVar()
1095 ttk.Entry(self.OD_window.portal, textvariable=self.OD_inspector_initials_entry).place(
1096 relx=0.5, y=90, anchor="center")
1097
1098 tk.Label(self.OD_window.portal, text="Date and Time of Inspection Start", font=(
1099 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
1100 self.OD_datetime_start_TK = tk.StringVar()
1101 now = datetime.datetime.now()
1102 self.OD_datetime_start_TK.set(now.strftime("%I:%M %p %m/%d/%Y"))
1103 tk.Label(self.OD_window.portal, textvariable=self.OD_datetime_start_TK, font=(
1104 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
1105
1106 ttk.Button(self.OD_window.portal, text="Start Inspection", command=lambda: self.start_OD_inspection(
1107 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
1108
1109 def start_OD_inspection(self):
1110 try:
1111 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
1112 except WindowsError as Error:
1113 showerror(
1114 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
1115 self.OD_window.portal.destroy()
1116 else:
1117 self.var.jobDetails[
1118 "OD Inspection Start Time"] = self.OD_datetime_start_TK.get()
1119 self.var.jobDetails[
1120 "OD Inspector Initials"] = self.OD_inspector_initials_entry.get()
1121 self.jobSpace.Populate_Data_File(open(
1122 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
1123 try:
1124 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
1125 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
1126 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
1127
1128 macropath = file("Macros\Steam Turbine OD Inspection")
1129 roto.command.CommandExecute(
1130 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
1131 except COMError as Error:
1132 showerror(title="Error", message=str(
1133 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1134 except AttributeError as Error:
1135 showerror(title="Error", message="%s\nMake sure PolyWorks and IMInspect are open, then retry." % Error)
1136
1137 self.OD_window.portal.destroy()
1138
1139 def axial_inspection_window(self):
1140 self.axial_window = AppDialog(self, "Axial Inspection", 350, 250)
1141
1142 tk.Label(self.axial_window.portal, text="Inspector Initials", font=(
1143 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
1144 self.axial_inspector_initials_entry = tk.StringVar()
1145 ttk.Entry(self.axial_window.portal, textvariable=self.axial_inspector_initials_entry).place(
1146 relx=0.5, y=90, anchor="center")
1147
1148 tk.Label(self.axial_window.portal, text="Date and Time of Inspection Start", font=(
1149 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
1150 self.axial_datetime_start_TK = tk.StringVar()
1151 now = datetime.datetime.now()
1152 self.axial_datetime_start_TK.set(
1153 now.strftime("%I:%M %p %m/%d/%Y"))
1154 tk.Label(self.axial_window.portal, textvariable=self.axial_datetime_start_TK, font=(
1155 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
1156
1157 ttk.Button(self.axial_window.portal, text="Start Inspection", command=lambda: self.start_axial_inspection(
1158 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
1159
1160 ttk.Button(self.axial_window.portal, text="Thermal Gaps and Journal Weights", command=lambda: self.thermal_gap_entry(
1161 )).place(relx=0.5, y=285 - self.var.button_y_offset, anchor="center")
1162
1163 def start_axial_inspection(self):
1164 try:
1165 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
1166 except WindowsError as Error:
1167 showerror(
1168 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
1169 self.axial_window.portal.destroy()
1170 else:
1171 self.var.jobDetails[
1172 "Axial Inspection Start Time"] = self.axial_datetime_start_TK.get()
1173 self.var.jobDetails[
1174 "Axial Inspector Initials"] = self.axial_inspector_initials_entry.get()
1175 self.jobSpace.Populate_Data_File(open(
1176 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
1177 self.axial_window.portal.destroy()
1178 self.thermal_gap_entry()
1179 self.create_axial_features()
1180
1181 def create_axial_features(self):
1182 # begin executing features
1183 try:
1184 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
1185 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
1186 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
1187
1188 roto.command.CommandExecute(
1189 'FEATURE PLANE CREATE ("Thrust End of Shaft")')
1190
1191 roto.command.CommandExecute(
1192 'FEATURE PLANE CREATE ("Thrust Face")')
1193 roto.command.CommandExecute(
1194 'FEATURE CYLINDER CREATE ("TE Bearing Journal")')
1195
1196 if str(self.var.jobDetails["Dual Thrust Collars"]) == "1":
1197 roto.command.CommandExecute('FEATURE PLANE CREATE ("Outboard Collar Outboard Face")')
1198 roto.command.CommandExecute('FEATURE PLANE CREATE ("Outboard Collar Inboard Face")')
1199 roto.command.CommandExecute('FEATURE PLANE CREATE ("Inboard Collar Outboard Face")')
1200 roto.command.CommandExecute('FEATURE PLANE CREATE ("Inboard Collar Inboard Face")')
1201 else:
1202 roto.command.CommandExecute('FEATURE PLANE CREATE ("Inactive Thrust Face")')
1203
1204 if str(self.var.jobDetails["Curtis Stages"]) == "0":
1205 for i in range (1, int(self.var.jobDetails["Number of Stages"])+1):
1206 roto.command.CommandExecute(
1207 'FEATURE PLANE CREATE ("Stage R%d Disk Face")' % i)
1208 if str(self.var.jobDetails["Blade Root %s" % i]) == "1":
1209 roto.command.CommandExecute(
1210 'FEATURE PLANE CREATE ("Stage R%d Blade Root")' % i)
1211 if str(self.var.jobDetails["Blade Edge %s" % i]) == "1":
1212 roto.command.CommandExecute(
1213 'FEATURE PLANE CREATE ("Stage R%d Blade Edge")' % i)
1214 if str(self.var.jobDetails["Shroud Band %s" % i]) == "1":
1215 roto.command.CommandExecute(
1216 'FEATURE PLANE CREATE ("Stage R%d Shroud Band")' % i)
1217 else:
1218 for i in range (1, 3):
1219 roto.command.CommandExecute(
1220 'FEATURE PLANE CREATE ("Stage C%d Disk Face")' % i)
1221
1222 if str(self.var.jobDetails["Blade Root %s" % i]) == "1":
1223 roto.command.CommandExecute(
1224 'FEATURE PLANE CREATE ("Stage C%d Blade Root")' % i)
1225 if str(self.var.jobDetails["Blade Edge %s" % i]) == "1":
1226 roto.command.CommandExecute(
1227 'FEATURE PLANE CREATE ("Stage C%d Blade Edge")' % i)
1228 if str(self.var.jobDetails["Shroud Band %s" % i]) == "1":
1229 roto.command.CommandExecute(
1230 'FEATURE PLANE CREATE ("Stage C%d Shroud Band")' % i)
1231
1232 for i in range (1, int(self.var.jobDetails["Number of Stages"])-1):
1233 roto.command.CommandExecute(
1234 'FEATURE PLANE CREATE ("Stage R%d Disk Face")' % i)
1235 if str(self.var.jobDetails["Blade Root %s" % (i+2)]) == "1":
1236 roto.command.CommandExecute(
1237 'FEATURE PLANE CREATE ("Stage R%d Blade Root")' % i)
1238 if str(self.var.jobDetails["Blade Edge %s" % (i+2)]) == "1":
1239 roto.command.CommandExecute(
1240 'FEATURE PLANE CREATE ("Stage R%d Blade Edge")' % i)
1241 if str(self.var.jobDetails["Shroud Band %s" % (i+2)]) == "1":
1242 roto.command.CommandExecute(
1243 'FEATURE PLANE CREATE ("Stage R%d Shroud Band")' % i)
1244
1245 aLphabet = list(islice(multiletters(ascii_uppercase), 200))
1246 for i in range(0, int(self.var.jobDetails["Other Measurements"])):
1247 roto.command.CommandExecute(
1248 'FEATURE PLANE CREATE ("Feature ' + aLphabet[i] + '")')
1249
1250 roto.command.CommandExecute(
1251 'FEATURE PLANE CREATE ("Non-Thrust End of Shaft")')
1252
1253 macropath = file("Macros\Steam Turbine Axial Inspection")
1254 roto.command.CommandExecute(
1255 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
1256 except COMError as Error:
1257 showerror(title="Error", message=str(
1258 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1259 except AttributeError as Error:
1260 showerror(title="Error", message=str(
1261 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1262
1263 def thermal_gap_entry(self):
1264 self.thermal_gap_window = AppDialog(self, "Thermal Gaps", 250, 700)
1265
1266 self.thermal_gap_notebook = ttk.Notebook(
1267 self.thermal_gap_window.portal)
1268 self.thermal_gap_frame = tk.Frame(
1269 self.thermal_gap_notebook, bg="white")
1270 self.journal_weights_frame = tk.Frame(
1271 self.thermal_gap_notebook, bg="white")
1272 self.thermal_gap_notebook.add(
1273 self.thermal_gap_frame, text="Thermal Gaps")
1274 self.thermal_gap_notebook.add(
1275 self.journal_weights_frame, text="Journal Weights")
1276 self.thermal_gap_notebook.pack(fill="both", expand=1)
1277
1278 self.thermal_gap_temp_var = {}
1279 thermal_gap_labels = ("A", "B", "C", "D", "E",
1280 "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R")
1281
1282 i = 0
1283 while i < len(thermal_gap_labels):
1284 tk.Label(self.thermal_gap_frame, text=thermal_gap_labels[i], font=(
1285 "Arial 18 bold"), bg="white").grid(column=0, row=(2 * i + 1))
1286 self.thermal_gap_temp_var["Thermal Gap " + thermal_gap_labels[i]] = tk.StringVar()
1287 try:
1288 self.thermal_gap_temp_var[
1289 "Thermal Gap " + thermal_gap_labels[i]].set(self.var.jobDetails["Thermal Gap " + thermal_gap_labels[i]])
1290 except KeyError:
1291 pass
1292 ttk.Entry(self.thermal_gap_frame, textvariable=self.thermal_gap_temp_var[
1293 "Thermal Gap " + thermal_gap_labels[i]]).grid(column=1, row=(2 * i + 1))
1294 i += 1
1295
1296 tk.Label(self.journal_weights_frame, text="Coupling/Non-Thrust End\nBearing Journal Weight",
1297 font=("Arial 10 bold"), bg="white").grid(column=0, row=1, columnspan=2)
1298 self.NTE_bearing_journal_weight = tk.StringVar()
1299 try:
1300 self.NTE_bearing_journal_weight.set(self.var.jobDetails["NTE BJ Weight"])
1301 except KeyError:
1302 pass
1303 ttk.Entry(self.journal_weights_frame, textvariable=self.NTE_bearing_journal_weight).grid(
1304 column=0, row=2, columnspan=2)
1305
1306 tk.Label(self.journal_weights_frame, text="Thrust End\nBearing Journal Weight", font=(
1307 "Arial 10 bold"), bg="white").grid(column=0, row=3, columnspan=2)
1308 self.TE_bearing_journal_weight = tk.StringVar()
1309 try:
1310 self.TE_bearing_journal_weight.set(self.var.jobDetails["TE BJ Weight"])
1311 except KeyError:
1312 pass
1313 ttk.Entry(self.journal_weights_frame, textvariable=self.TE_bearing_journal_weight).grid(
1314 column=0, row=4, columnspan=2)
1315
1316 tk.Label(self.journal_weights_frame, text="Total\nBearing Journal Weight", font=(
1317 "Arial 10 bold"), bg="white").grid(column=0, row=5, columnspan=2)
1318 self.total_bearing_journal_weight = tk.StringVar()
1319 try:
1320 self.total_bearing_journal_weight.set(self.var.jobDetails["Overall Weight"])
1321 except KeyError:
1322 pass
1323 ttk.Entry(self.journal_weights_frame, textvariable=self.total_bearing_journal_weight).grid(
1324 column=0, row=6, columnspan=2)
1325
1326 ttk.Button(self.thermal_gap_frame, text="Done", command=lambda: self.thermal_gap_update(
1327 )).grid(column=0, row=(2 * i + 2), columnspan=2)
1328 ttk.Button(self.journal_weights_frame, text="Done", command=lambda: self.thermal_gap_update(
1329 )).grid(column=0, row=(2 * i + 2), columnspan=2)
1330
1331 weigh_grid(self.thermal_gap_frame)
1332 weigh_grid(self.journal_weights_frame)
1333
1334 def thermal_gap_update(self):
1335 for key in self.thermal_gap_temp_var:
1336 try:
1337 del self.var.jobDetails[key]
1338 except KeyError:
1339 pass
1340 print "%s Deleted" % key
1341 if self.thermal_gap_temp_var[key].get():
1342 self.var.jobDetails[key] = self.thermal_gap_temp_var[key].get()
1343 print "%s Replaced" % key
1344
1345 self.var.jobDetails[
1346 "TE BJ Weight"] = self.TE_bearing_journal_weight.get()
1347 self.var.jobDetails[
1348 "NTE BJ Weight"] = self.NTE_bearing_journal_weight.get()
1349 self.var.jobDetails[
1350 "Overall Weight"] = self.total_bearing_journal_weight.get()
1351
1352 for key in self.thermal_gap_temp_var:
1353 print "%s:%s" % (key, self.thermal_gap_temp_var[key].get())
1354
1355 print self.var.jobDetails
1356
1357 self.jobSpace.Populate_Data_File(open(
1358 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w+"))
1359 self.thermal_gap_window.portal.destroy()
1360
1361
1362class Expander(object):
1363 def __init__(self, parent, width, height, var):
1364 """ this class will serve as the interface to centrifugal compressor projects.
1365 the data gathered here will be inserted into polyworks to begin inspection.
1366 """
1367 self.parent = parent
1368 self.width = width
1369 self.height = height
1370 self.var = var
1371 self.jobSpace = JobWorkspace()
1372 self.number_of_stages = tk.IntVar()
1373 self.check_box_dict = {}
1374 self.stagetempvar = {}
1375 self.completion_check = {}
1376 self.completion_color = {}
1377 self.create_widgets()
1378
1379 self.check_box_dict = {}
1380 self.num_of_stages = {}
1381 self.stagetempvar = {}
1382
1383 def inspection_completion_check(self):
1384 try:
1385 self.icc_1.destroy()
1386 self.icc_2.destroy()
1387 self.icc_3.destroy()
1388 self.icc_4.destroy()
1389 self.icc_5.destroy()
1390 self.icc_6.destroy()
1391 except AttributeError:
1392 pass
1393
1394 try:
1395 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Visual_Inspection.csv'):
1396 self.completion_check["Visual Inspection"] = "Complete"
1397 self.completion_color["Visual Inspection"] = "Dark Green"
1398 else:
1399 self.completion_check["Visual Inspection"] = "Incomplete"
1400 self.completion_color["Visual Inspection"] = "Red"
1401
1402 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Axial_Inspection.csv'):
1403 self.completion_check["Axial Inspection"] = "Complete"
1404 self.completion_color["Axial Inspection"] = "Dark Green"
1405 else:
1406 self.completion_check["Axial Inspection"] = "Incomplete"
1407 self.completion_color["Axial Inspection"] = "Red"
1408
1409 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\OD_Inspection.csv'):
1410 self.completion_check["OD Inspection"] = "Complete"
1411 self.completion_color["OD Inspection"] = "Dark Green"
1412 else:
1413 self.completion_check["OD Inspection"] = "Incomplete"
1414 self.completion_color["OD Inspection"] = "Red"
1415
1416 if os.path.isfile(self.var.roto_directory + self.var.jobDetails['Job Number'] + '\\Check_Balance.csv'):
1417 self.completion_check["Check Balance"] = "Complete"
1418 self.completion_color["Check Balance"] = "Dark Green"
1419 else:
1420 self.completion_check["Check Balance"] = "Incomplete"
1421 self.completion_color["Check Balance"] = "Red"
1422 except KeyError:
1423 pass
1424
1425 try:
1426 self.icc_1 = tk.Label(self.parent, text=self.completion_check[
1427 "Visual Inspection"], bg="white", fg=self.completion_color["Visual Inspection"], font=("Arial 10 bold"))
1428 self.icc_1.grid(column=2, row=2)
1429 self.icc_2 = tk.Label(self.parent, text=self.completion_check[
1430 "Axial Inspection"], bg="white", fg=self.completion_color["Axial Inspection"], font=("Arial 10 bold"))
1431 self.icc_2.grid(column=2, row=3)
1432 self.icc_3 = tk.Label(self.parent, text=self.completion_check[
1433 "OD Inspection"], bg="white", fg=self.completion_color["OD Inspection"], font=("Arial 10 bold"))
1434 self.icc_3.grid(column=2, row=4)
1435 self.icc_4 = tk.Label(self.parent, text=self.completion_check[
1436 "Check Balance"], bg="white", fg=self.completion_color["Check Balance"], font=("Arial 10 bold"))
1437 self.icc_4.grid(column=2, row=5)
1438 except KeyError:
1439 pass
1440
1441 try:
1442 self.icc_5 = tk.Label(self.parent, text=(self.var.jobDetails[
1443 "Axial Inspection Start Time"] + "\n" + self.var.jobDetails["Axial Inspector Initials"]), bg="White", font=("Arial 10"))
1444 self.icc_5.grid(column=3, row=3, columnspan=2)
1445 except KeyError:
1446 pass
1447
1448 try:
1449 self.icc_6 = tk.Label(self.parent, text=(self.var.jobDetails[
1450 "OD Inspection Start Time"] + "\n" + self.var.jobDetails["OD Inspector Initials"]), bg="White", font=("Arial 10"))
1451 self.icc_6.grid(column=3, row=4, columnspan=2)
1452 except KeyError:
1453 pass
1454
1455 weigh_grid(self.parent)
1456
1457 def create_widgets(self):
1458 tk.Label(self.parent, text="Expander", font=(
1459 "Arial 18 bold"), bg="white").grid(column=0, row=0, columnspan=5)
1460
1461 ttk.Button(self.parent, text="Equipment Details", width=20, command=lambda: self.equipment_details(
1462 )).grid(column=0, row=1, columnspan=2, sticky="ns")
1463 ttk.Button(self.parent, text="Visual Inspection", width=20).grid(
1464 column=0, row=2, columnspan=2, sticky="ns")
1465 ttk.Button(self.parent, text="Axial Inspection", width=20, command=lambda: self.axial_inspection_window(
1466 )).grid(column=0, row=3, columnspan=2, sticky="ns")
1467 ttk.Button(self.parent, text="OD Inspection", width=20, command=lambda: self.OD_inspection_window(
1468 )).grid(column=0, row=4, columnspan=2, sticky="ns")
1469 ttk.Button(self.parent, text="Check Balance", width=20).grid(
1470 column=0, row=5, columnspan=2, sticky="ns")
1471
1472 ttk.Button(self.parent, text="Check Inspections",
1473 command=lambda: self.inspection_completion_check()).grid(column=4, row=1)
1474
1475 ttk.Button(self.parent, text="Back", command=lambda: self.back_button()).grid(
1476 column=0, row=8, columnspan=2, pady=10)
1477
1478 weigh_grid(self.parent)
1479
1480 def back_button(self):
1481 roto.frames["f1"].tkraise()
1482 self.var.jobDetails.clear()
1483
1484 def equipment_details(self):
1485 self.equipment_window = AppDialog(self, "Equipment Details", 350, 400)
1486
1487 tk.Label(self.equipment_window.portal, text="Job Number", font=(
1488 "Arial 10 bold"), bg="white").place(relx=0.5, y=25, anchor="center")
1489 self.job_number_entry = tk.StringVar()
1490 try:
1491 self.job_number_entry.set(self.var.jobDetails["Job Number"])
1492 except KeyError:
1493 pass
1494 ttk.Entry(self.equipment_window.portal, textvariable=self.job_number_entry).place(
1495 relx=0.5, y=50, anchor="center")
1496
1497 tk.Label(self.equipment_window.portal, text="Number of Stages", font=(
1498 "Arial 10 bold"), bg="white").place(relx=0.5, y=75, anchor="center")
1499 self.number_of_stages_entry = tk.IntVar()
1500 try:
1501 self.number_of_stages_entry.set(
1502 self.var.jobDetails["Number of Stages"])
1503 except KeyError:
1504 pass
1505 ttk.Entry(self.equipment_window.portal, textvariable=self.number_of_stages_entry).place(
1506 relx=0.5, y=100, anchor="center")
1507
1508 tk.Label(self.equipment_window.portal, text="Expander", font=(
1509 "Arial 10 bold"), bg="white").place(relx=0.5, y=125, anchor="center")
1510
1511 self.on_trace_check_box(varname="PY_VAR7", elementname=None, mode="w")
1512 i = 1
1513 while i <= int(self.number_of_stages_entry.get()):
1514 try:
1515 self.stagetempvar[i].set(
1516 self.var.jobDetails["Stage %i Shroud" % i])
1517 except KeyError:
1518 continue
1519 finally:
1520 i += 1
1521
1522 self.number_of_stages_entry.trace("w", self.on_trace_check_box)
1523
1524 tk.Label(self.equipment_window.portal, text="Thrust Collar", font=(
1525 "Arial 10 bold"), bg="white").place(relx=0.25, y=200, anchor="center")
1526 # tk.Label(self.equipment_window.portal, text="Dual Thrust Collar", font=(
1527 # "Arial 10 bold"), bg="white").place(relx=0.75, y=200, anchor="center")
1528
1529 self.thrust_collar_entry = tk.IntVar()
1530 try:
1531 self.thrust_collar_entry.set(self.var.jobDetails["Thrust Collar"])
1532 except KeyError:
1533 pass
1534 ttk.Checkbutton(self.equipment_window.portal, variable=self.thrust_collar_entry,
1535 style="white.TCheckbutton").place(relx=0.25, y=225, anchor="center")
1536
1537 # self.thrust_collar_entry = tk.IntVar()
1538 # try:
1539 # self.thrust_collar_entry.set(self.var.jobDetails["Dual Thrust Collars"])
1540 # except KeyError:
1541 # pass
1542 # ttk.Checkbutton(self.equipment_window.portal, variable=self.thrust_collar_entry,
1543 # style="white.TCheckbutton").place(relx=0.75, y=225, anchor="center")
1544
1545 tk.Label(self.equipment_window.portal, text="Other Measurements (from Active Thrust Face)", font=(
1546 "Arial 10 bold"), bg="white").place(relx=0.50, y=250, anchor="center")
1547
1548 self.other_measurements_entry = tk.IntVar()
1549 try:
1550 self.other_measurements_entry.set(
1551 self.var.jobDetails["Other Measurements"])
1552 except KeyError:
1553 pass
1554 ttk.Entry(self.equipment_window.portal, textvariable=self.other_measurements_entry).place(
1555 relx=0.5, y=275, anchor="center")
1556
1557
1558 ttk.Button(self.equipment_window.portal, text="OK", command=lambda: self.job_detail_update(
1559 )).place(relx=0.5, y=400 - self.var.button_y_offset, anchor="center")
1560
1561 def on_trace_check_box(self, varname, elementname, mode):
1562 for key in self.check_box_dict:
1563 self.check_box_dict[key].destroy()
1564 try:
1565 if self.number_of_stages_entry.get() <= 15:
1566 i = 1
1567 self.stagetempvar.clear()
1568 while i <= self.number_of_stages_entry.get():
1569 #self.stagetempvar[i] = tk.StringVar()
1570 #self.stagetempvar[i].set("Shrouded")
1571 self.check_box_dict[i] = ttk.Menubutton(
1572 self.equipment_window.portal, text=i, width=0.1)
1573 self.check_box_dict[i].menu = tk.Menu(self.check_box_dict[i], tearoff=0)
1574 self.check_box_dict[i]['menu'] = self.check_box_dict[i].menu
1575 sb = self.stagetempvar["Seal Eye Face %s" % i] = tk.IntVar()
1576 be = self.stagetempvar["Leading Blade Edge %s" % i] = tk.IntVar()
1577 br = self.stagetempvar["Blade Root %s" % i] = tk.IntVar()
1578 try:
1579 sb.set(self.var.jobDetails["Seal Eye Face %s" % i])
1580 be.set(self.var.jobDetails["Leading Blade Edge %s" % i])
1581 br.set(self.var.jobDetails["Blade Root %s" % i])
1582 except KeyError:
1583 pass
1584 self.check_box_dict[i].menu.add_checkbutton(label='Seal Eye Face', variable=self.stagetempvar["Seal Eye Face %s" % i])
1585 self.check_box_dict[i].menu.add_checkbutton(label='Leading Blade Edge', variable=self.stagetempvar["Leading Blade Edge %s" % i])
1586 self.check_box_dict[i].menu.add_checkbutton(label='Blade Root', variable=self.stagetempvar["Blade Root %s" % i])
1587 self.check_box_dict[i].place(
1588 relx=(i * (1 / (self.number_of_stages_entry.get() + 1))), y=150, anchor="center")
1589 i += 1
1590 except ValueError:
1591 pass
1592
1593 def job_detail_update(self):
1594 print self.var.jobDetails
1595
1596 self.var.jobDetails["Job Number"] = self.job_number_entry.get()
1597 self.var.jobDetails["Number of Stages"] = self.number_of_stages_entry.get()
1598 # self.var.jobDetails["Dual Thrust Collars"] = self.thrust_collar_entry.get()
1599 # self.var.jobDetails["Curtis Stages"] = self.curtis_stages_entry.get()
1600 self.var.jobDetails["Other Measurements"] = self.other_measurements_entry.get()
1601
1602 for key in self.stagetempvar:
1603 self.var.jobDetails[key] = self.stagetempvar[key].get()
1604
1605 self.jobSpace.Populate_Data_File(open(
1606 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w+"))
1607 self.equipment_window.portal.destroy()
1608
1609 def OD_inspection_window(self):
1610 self.OD_window = AppDialog(self, "OD Inspection", 350, 250)
1611
1612 tk.Label(self.OD_window.portal, text="Inspector Initials", font=(
1613 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
1614 self.OD_inspector_initials_entry = tk.StringVar()
1615 ttk.Entry(self.OD_window.portal, textvariable=self.OD_inspector_initials_entry).place(
1616 relx=0.5, y=90, anchor="center")
1617
1618 tk.Label(self.OD_window.portal, text="Date and Time of Inspection Start", font=(
1619 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
1620 self.OD_datetime_start_TK = tk.StringVar()
1621 now = datetime.datetime.now()
1622 self.OD_datetime_start_TK.set(now.strftime("%I:%M %p %m/%d/%Y"))
1623 tk.Label(self.OD_window.portal, textvariable=self.OD_datetime_start_TK, font=(
1624 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
1625
1626 ttk.Button(self.OD_window.portal, text="Start Inspection", command=lambda: self.start_OD_inspection(
1627 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
1628
1629 def start_OD_inspection(self):
1630 try:
1631 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
1632 except WindowsError as Error:
1633 showerror(
1634 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
1635 self.OD_window.portal.destroy()
1636 else:
1637 self.var.jobDetails[
1638 "OD Inspection Start Time"] = self.OD_datetime_start_TK.get()
1639 self.var.jobDetails[
1640 "OD Inspector Initials"] = self.OD_inspector_initials_entry.get()
1641 self.jobSpace.Populate_Data_File(open(
1642 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
1643 try:
1644 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
1645 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
1646 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
1647
1648 macropath = file("Macros\Expander OD Inspection")
1649 roto.command.CommandExecute(
1650 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
1651 except COMError as Error:
1652 showerror(title="Error", message=str(
1653 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1654 except AttributeError as Error:
1655 showerror(title="Error", message="%s\nMake sure PolyWorks and IMInspect are open, then retry." % Error)
1656
1657 self.OD_window.portal.destroy()
1658
1659 def axial_inspection_window(self):
1660 self.axial_window = AppDialog(self, "Axial Inspection", 350, 250)
1661
1662 tk.Label(self.axial_window.portal, text="Inspector Initials", font=(
1663 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=60, anchor="center")
1664 self.axial_inspector_initials_entry = tk.StringVar()
1665 ttk.Entry(self.axial_window.portal, textvariable=self.axial_inspector_initials_entry).place(
1666 relx=0.5, y=90, anchor="center")
1667
1668 tk.Label(self.axial_window.portal, text="Date and Time of Inspection Start", font=(
1669 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=120, anchor="center")
1670 self.axial_datetime_start_TK = tk.StringVar()
1671 now = datetime.datetime.now()
1672 self.axial_datetime_start_TK.set(
1673 now.strftime("%I:%M %p %m/%d/%Y"))
1674 tk.Label(self.axial_window.portal, textvariable=self.axial_datetime_start_TK, font=(
1675 "Arial 10"), bg="white", borderwidth=1).place(relx=0.5, y=150, anchor="center")
1676
1677 ttk.Button(self.axial_window.portal, text="Start Inspection", command=lambda: self.start_axial_inspection(
1678 )).place(relx=0.5, y=250 - self.var.button_y_offset, anchor="center")
1679
1680 ttk.Button(self.axial_window.portal, text="Thermal Gaps and Journal Weights", command=lambda: self.thermal_gap_entry(
1681 )).place(relx=0.5, y=285 - self.var.button_y_offset, anchor="center")
1682
1683 def start_axial_inspection(self):
1684 try:
1685 self.jobSpace.loading_window(self, roto.connect_to_polyworks, "Loading Polyworks")
1686 except WindowsError as Error:
1687 showerror(
1688 title="Error", message="Ensure that Polyworks license dongle is present and inserted!\n%s" % Error)
1689 self.axial_window.portal.destroy()
1690 else:
1691 self.var.jobDetails[
1692 "Axial Inspection Start Time"] = self.axial_datetime_start_TK.get()
1693 self.var.jobDetails[
1694 "Axial Inspector Initials"] = self.axial_inspector_initials_entry.get()
1695 self.jobSpace.Populate_Data_File(open(
1696 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w"))
1697 self.axial_window.portal.destroy()
1698 self.thermal_gap_entry()
1699 self.create_axial_features()
1700
1701 def create_axial_features(self):
1702 # begin executing features
1703 try:
1704 roto.command.CommandExecute('TREEVIEW OBJECT SELECT ALL')
1705 roto.command.CommandExecute('ALIGN COORDINATE_SYSTEM ACTIVE ( "world" )')
1706 roto.command.CommandExecute('EDIT OBJECT DELETE ()')
1707
1708 roto.command.CommandExecute(
1709 'FEATURE PLANE CREATE ("Thrust End of Shaft")')
1710
1711 roto.command.CommandExecute(
1712 'FEATURE PLANE CREATE ("Thrust Face")')
1713 if self.var.jobDetails["Thrust Face"].get() == 1:
1714 roto.command.CommandExecute(
1715 'FEATURE PLANE CREATE ("Inactive Thrust Face")')
1716
1717 roto.command.CommandExecute(
1718 'FEATURE CYLINDER CREATE ("TE Bearing Journal")')
1719
1720 for i in range (1, int(self.var.jobDetails["Number of Stages"])+1):
1721 roto.command.CommandExecute(
1722 'FEATURE PLANE CREATE ("Stage %d Disk Face")' % i)
1723 if str(self.var.jobDetails["Blade Root %s" % i]) == "1":
1724 roto.command.CommandExecute(
1725 'FEATURE PLANE CREATE ("Stage %d Blade Root")' % i)
1726 if str(self.var.jobDetails["Leading Blade Edge %s" % i]) == "1":
1727 roto.command.CommandExecute(
1728 'FEATURE PLANE CREATE ("Stage %d Leading Blade Edge")' % i)
1729 if str(self.var.jobDetails["Seal Eye Face %s" % i]) == "1":
1730 roto.command.CommandExecute(
1731 'FEATURE PLANE CREATE ("Stage %d Seal Eye Face")' % i)
1732
1733 aLphabet = list(islice(multiletters(ascii_uppercase), 200))
1734 for i in range(0, int(self.var.jobDetails["Other Measurements"])):
1735 roto.command.CommandExecute(
1736 'FEATURE PLANE CREATE ("Feature ' + aLphabet[i]+aLphabet[i] + '")')
1737
1738 roto.command.CommandExecute(
1739 'FEATURE PLANE CREATE ("Non-Thrust End of Shaft")')
1740
1741 macropath = file("Macros\Steam Turbine Axial Inspection")
1742 roto.command.CommandExecute(
1743 'MACRO EXEC ("' + os.path.abspath(macropath.name) + '")')
1744 except COMError as Error:
1745 showerror(title="Error", message=str(
1746 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1747 except AttributeError as Error:
1748 showerror(title="Error", message=str(
1749 Error) + "\nMake sure PolyWorks and IMInspect are open, then retry.")
1750
1751 def thermal_gap_entry(self):
1752 self.thermal_gap_window = AppDialog(self, "Thermal Gaps", 250, 700)
1753
1754 self.thermal_gap_notebook = ttk.Notebook(
1755 self.thermal_gap_window.portal)
1756 self.thermal_gap_frame = tk.Frame(
1757 self.thermal_gap_notebook, bg="white")
1758 self.journal_weights_frame = tk.Frame(
1759 self.thermal_gap_notebook, bg="white")
1760 self.thermal_gap_notebook.add(
1761 self.thermal_gap_frame, text="Thermal Gaps")
1762 self.thermal_gap_notebook.add(
1763 self.journal_weights_frame, text="Journal Weights")
1764 self.thermal_gap_notebook.pack(fill="both", expand=1)
1765
1766 self.thermal_gap_temp_var = {}
1767 thermal_gap_labels = ("A", "B", "C", "D", "E",
1768 "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R")
1769
1770 i = 0
1771 while i < len(thermal_gap_labels):
1772 tk.Label(self.thermal_gap_frame, text=thermal_gap_labels[i], font=(
1773 "Arial 18 bold"), bg="white").grid(column=0, row=(2 * i + 1))
1774 self.thermal_gap_temp_var["Thermal Gap " + thermal_gap_labels[i]] = tk.StringVar()
1775 try:
1776 self.thermal_gap_temp_var[
1777 "Thermal Gap " + thermal_gap_labels[i]].set(self.var.jobDetails["Thermal Gap " + thermal_gap_labels[i]])
1778 except KeyError:
1779 pass
1780 ttk.Entry(self.thermal_gap_frame, textvariable=self.thermal_gap_temp_var[
1781 "Thermal Gap " + thermal_gap_labels[i]]).grid(column=1, row=(2 * i + 1))
1782 i += 1
1783
1784 tk.Label(self.journal_weights_frame, text="Coupling/Non-Thrust End\nBearing Journal Weight",
1785 font=("Arial 10 bold"), bg="white").grid(column=0, row=1, columnspan=2)
1786 self.NTE_bearing_journal_weight = tk.StringVar()
1787 try:
1788 self.NTE_bearing_journal_weight.set(self.var.jobDetails["NTE BJ Weight"])
1789 except KeyError:
1790 pass
1791 ttk.Entry(self.journal_weights_frame, textvariable=self.NTE_bearing_journal_weight).grid(
1792 column=0, row=2, columnspan=2)
1793
1794 tk.Label(self.journal_weights_frame, text="Thrust End\nBearing Journal Weight", font=(
1795 "Arial 10 bold"), bg="white").grid(column=0, row=3, columnspan=2)
1796 self.TE_bearing_journal_weight = tk.StringVar()
1797 try:
1798 self.TE_bearing_journal_weight.set(self.var.jobDetails["TE BJ Weight"])
1799 except KeyError:
1800 pass
1801 ttk.Entry(self.journal_weights_frame, textvariable=self.TE_bearing_journal_weight).grid(
1802 column=0, row=4, columnspan=2)
1803
1804 tk.Label(self.journal_weights_frame, text="Total\nBearing Journal Weight", font=(
1805 "Arial 10 bold"), bg="white").grid(column=0, row=5, columnspan=2)
1806 self.total_bearing_journal_weight = tk.StringVar()
1807 try:
1808 self.total_bearing_journal_weight.set(self.var.jobDetails["Overall Weight"])
1809 except KeyError:
1810 pass
1811 ttk.Entry(self.journal_weights_frame, textvariable=self.total_bearing_journal_weight).grid(
1812 column=0, row=6, columnspan=2)
1813
1814 ttk.Button(self.thermal_gap_frame, text="Done", command=lambda: self.thermal_gap_update(
1815 )).grid(column=0, row=(2 * i + 2), columnspan=2)
1816 ttk.Button(self.journal_weights_frame, text="Done", command=lambda: self.thermal_gap_update(
1817 )).grid(column=0, row=(2 * i + 2), columnspan=2)
1818
1819 weigh_grid(self.thermal_gap_frame)
1820 weigh_grid(self.journal_weights_frame)
1821
1822 def thermal_gap_update(self):
1823 for key in self.thermal_gap_temp_var:
1824 try:
1825 del self.var.jobDetails[key]
1826 except KeyError:
1827 pass
1828 print "%s Deleted" % key
1829 if self.thermal_gap_temp_var[key].get():
1830 self.var.jobDetails[key] = self.thermal_gap_temp_var[key].get()
1831 print "%s Replaced" % key
1832
1833 self.var.jobDetails[
1834 "TE BJ Weight"] = self.TE_bearing_journal_weight.get()
1835 self.var.jobDetails[
1836 "NTE BJ Weight"] = self.NTE_bearing_journal_weight.get()
1837 self.var.jobDetails[
1838 "Overall Weight"] = self.total_bearing_journal_weight.get()
1839
1840 for key in self.thermal_gap_temp_var:
1841 print "%s:%s" % (key, self.thermal_gap_temp_var[key].get())
1842
1843 print self.var.jobDetails
1844
1845 self.jobSpace.Populate_Data_File(open(
1846 self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv", "w+"))
1847 self.thermal_gap_window.portal.destroy()
1848
1849
1850class Create_turbodoc(object):
1851 """ this class will be called upon selecting "create turbodoc"
1852 from the file menu.
1853 """
1854
1855 def __init__(self):
1856 self.inspection_list = ["Select All", "Axial_Inspection", "Check_Balance_Inspection",
1857 "OD_Inspection", "Runout_Inspection", "Visual_Inspection"]
1858 # pass variable class object
1859 self.var = Shared_variables()
1860 self.jobSpace = JobWorkspace()
1861 # prompt user at instantiation
1862 self.job_number_dialog_window()
1863
1864 def job_number_dialog_window(self):
1865 """ this method prompts the user to specify turbodoc job number.
1866 """
1867 self.job_dialog = AppDialog(self, "Create TurboDoc", 250, 140)
1868 self.job_dialog.center_window()
1869
1870 tk.Label(self.job_dialog.portal, text="Job Number:", font=(
1871 "Arial 10 bold"), bg="white", borderwidth=1).place(relx=0.5, y=30, anchor="center")
1872 self.job_number_var = tk.StringVar()
1873 ttk.Entry(self.job_dialog.portal, textvariable=self.job_number_var).place(
1874 relx=0.5, y=60, anchor="center")
1875 ttk.Button(self.job_dialog.portal, text="OK", command=self.validate_job_number).place(
1876 relx=0.5, y=110, anchor="center")
1877
1878 def validate_job_number(self):
1879 """ this method will validate the provided job number and
1880 and determine what inspections have been completed.
1881 """
1882 self.var.jobDetails["Job Number"] = self.job_number_var.get()
1883 print self.var.jobDetails
1884 self.absolute_path = self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\"
1885
1886 if len(self.var.jobDetails["Job Number"]) == 6 and self.var.jobDetails["Job Number"].isdigit() and os.path.exists(self.absolute_path):
1887 self.job_dialog.portal.destroy()
1888 self.show_inspection_list()
1889 self.jobSpace.Populate_Job_Details(
1890 open(self.var.roto_directory + self.var.jobDetails["Job Number"] + "\\data.csv"))
1891 else:
1892 showerror(title="Error",
1893 message="There are no inspections for this job number.")
1894
1895 def show_inspection_list(self):
1896 """ this method will display inspections and
1897 allow the user to specify desired turbodocs.
1898 """
1899 self.inspect_dialog = AppDialog(self, "Inspection List", 280, 250)
1900 self.inspect_dialog.center_window()
1901 # initialize dicts to hold checkbuttons and associated variables
1902 self.inspection_checkbuttons = dict()
1903 self.inspection_vars = dict()
1904
1905 for i in range(len(self.inspection_list)):
1906 self.name_mod = self.inspection_list[i].replace("_", " ")
1907
1908 if self.name_mod == "Select All":
1909 self.inspection_vars[self.inspection_list[i]] = tk.IntVar()
1910 self.inspection_checkbuttons[self.inspection_list[i]] = ttk.Checkbutton(
1911 self.inspect_dialog.portal, text=self.name_mod, variable=self.inspection_vars[self.inspection_list[i]], style="white.TCheckbutton")
1912 self.inspection_checkbuttons[self.inspection_list[i]].grid(
1913 row=i, column=1, sticky="ew", padx=10, pady=10)
1914 self.inspection_vars[self.inspection_list[i]].trace(
1915 "w", self.select_all_checkbuttons)
1916 else:
1917 self.inspection_vars[self.inspection_list[i]] = tk.IntVar()
1918 self.inspection_checkbuttons[self.inspection_list[i]] = ttk.Checkbutton(
1919 self.inspect_dialog.portal, text=self.name_mod, variable=self.inspection_vars[self.inspection_list[i]], style="white.TCheckbutton")
1920 self.inspection_checkbuttons[self.inspection_list[i]].grid(
1921 row=i, column=1, sticky="ew", padx=10, pady=5)
1922
1923 ttk.Button(self.inspect_dialog.portal, text="Launch", command=lambda: self.turbodoc_launch()).grid(
1924 row=len(self.inspection_list), column=2, padx=10, pady=10)
1925
1926 self.check_for_inspections()
1927
1928 def check_for_inspections(self):
1929 """ this method will check for inspections
1930 in the associated file path.
1931 checkbuttons will be disabled for inspections
1932 that are not found.
1933 """
1934 for item in self.inspection_list[1:]:
1935 if os.path.exists(self.absolute_path + "\\" + item + ".csv"):
1936 pass
1937 else:
1938 for i in range(len(self.inspection_list)):
1939 if self.inspection_list[i] == item:
1940 self.index = i
1941 self.inspection_checkbuttons[self.inspection_list[
1942 self.index]].config(state="disabled")
1943 else:
1944 pass
1945
1946 def select_all_checkbuttons(self, args, *kwargs):
1947 """ this method will implement the select all feature
1948 of the inspection window.
1949 """
1950 if self.inspection_vars[self.inspection_list[0]].get() == 1:
1951 for i in range(1, len(self.inspection_list)):
1952
1953 if not self.inspection_checkbuttons[self.inspection_list[i]].instate(['disabled']):
1954 self.inspection_vars[self.inspection_list[i]].set(1)
1955 else:
1956 for i in range(1, len(self.inspection_list)):
1957 if not self.inspection_checkbuttons[self.inspection_list[i]].instate(['disabled']):
1958 self.inspection_vars[self.inspection_list[i]].set(0)
1959
1960 def turbodoc_launch(self):
1961 self.inspect_dialog.portal.destroy()
1962 self.jobSpace.loading_window(self, self.find_cad_file, "Creating Turbodocs")
1963
1964 def find_cad_file(self):
1965 """ search for cad file in network path.
1966 if path is found, open in AutoCAD.
1967 otherwise, raise error.
1968 """
1969 try:
1970 for root, dirs, files in os.walk(self.var.turbodoc_path):
1971 for d in dirs: # d = folder
1972 # filter applicable subdirectories
1973 if self.var.jobDetails["Job Number"][:3] in d:
1974 # split job number ranges from subdirectories to test
1975 # for boolean
1976 ranges = d.split("-")
1977 if ranges[0] <= self.var.jobDetails["Job Number"] <= ranges[1]:
1978 # open CAD template path
1979 try:
1980 self.template_path = self.var.turbodoc_path + d + "\\" + \
1981 self.var.jobDetails[
1982 "Job Number"] + "\\" + "Template\\"
1983 # if path not found
1984 except OSError as Error:
1985 showerror(
1986 title="Error", message="No template directory found for this job number.\n%s" % str(Error))
1987 else:
1988 self.copy_and_open_cad_file()
1989 except IndexError:
1990 pass
1991
1992 def copy_and_open_cad_file(self):
1993 """ this method will copy, paste, rename and open
1994 CAD template for turbodoc implementation.
1995 """
1996 self.temp_name = self.var.jobDetails["Job Number"] + " Probe Template.dwg"
1997 self.p1_name = self.var.jobDetails["Job Number"] + " Phase 1.dwg"
1998 self.p1_path = self.template_path.replace("Template\\", "Phase 1\\")
1999 try:
2000 shutil.copy(self.template_path + self.temp_name,
2001 self.p1_path + self.p1_name)
2002 os.startfile(self.p1_path + self.p1_name)
2003 except IOError as error:
2004 showerror(
2005 title="Error", message="%s\n\nEnsure the AutoCAD template file is closed and the path exists" % error)
2006 print "BROKEN"
2007 else:
2008 self.run_inspections()
2009
2010 def run_inspections(self):
2011 if self.inspection_vars["Axial_Inspection"].get() == 1:
2012 print self.var.jobDetails["Machine Type"]
2013 if self.var.jobDetails["Machine Type"] == "Multi-Stage Compressor":
2014 CompressorAxials(self.var.roto_directory,
2015 self.inspection_vars, self.var.jobDetails)
2016 elif self.var.jobDetails["Machine Type"] == "Steam Turbine":
2017 SteamTurbineAxials(self.var.roto_directory,
2018 self.inspection_vars, self.var.jobDetails)
2019 if self.inspection_vars["OD_Inspection"].get() == 1:
2020 a = GenericOD()
2021 a.populate_drawing()
2022
2023
2024class GenericOD(object):
2025
2026 def __init__(self):
2027 self.acad = Autocad()
2028 self.job_space = JobWorkspace()
2029
2030 def determine_OD_dims(self, file_path):
2031 self.file_path = file_path
2032 nMeasurements = {}
2033 nStdDev = {}
2034 with open(file_path, "rb") as doc:
2035 self.reader = csv.reader(doc)
2036 # Creates a list of 200 letter and letter combos, using
2037 # 'multiletters()'
2038 aLphabet = list(islice(multiletters(ascii_uppercase), 200))
2039 for row in self.reader:
2040 if row:
2041 # If the first row of the OD_Inspection.csv file is in the list
2042 # of letters,
2043 if row[0] in aLphabet:
2044 # then it assigns that letter the measurement value in the
2045 # same row of the csv.
2046 nMeasurements[row[0]] = row[1]
2047 nStdDev[row[0]] = row[2]
2048
2049 return (nMeasurements, nStdDev)
2050
2051 def populate_drawing(self):
2052 self.var = Shared_variables()
2053
2054 while True:
2055 try:
2056 for nObject in self.acad.iter_layouts(doc=self.acad.doc, skip_model=True):
2057 if nObject.Name == "OD1":
2058 self.acad.doc.ActiveLayout = nObject
2059 except (COMError, AttributeError) as error:
2060 continue
2061 else:
2062 break
2063
2064 nMeasurementsFinal = self.determine_OD_dims(
2065 "%s%s\\OD_Inspection.csv" % (self.var.roto_directory, self.var.jobDetails["Job Number"]))
2066
2067 while True:
2068 try:
2069 # iterates through all objects in AutoCAD
2070 for nObject in self.acad.iter_objects(None, None, None, False):
2071 if hasattr(nObject, 'TextString'):
2072 print "if hasattr"
2073 try:
2074 # Replaces letter with matching value in the
2075 # measurements dictionary
2076 if Decimal(nMeasurementsFinal[1][nObject.Textstring]) <= 0.001:
2077 nObject.TextString = (nMeasurementsFinal[0])[nObject.TextString]# + "+-" + (nMeasurementsFinal[1])[nObject.Textstring]
2078 else:
2079 nObject.TextString = (nMeasurementsFinal[0])[nObject.TextString] + "*"
2080 print "replaced"
2081 except KeyError:
2082 continue
2083 except IOError as e:
2084 print e
2085 continue
2086 self.acad.doc.Regen(ACAD.acAllViewports)
2087 except COMError:
2088 continue
2089 break
2090 self.acad.doc.Regen(ACAD.acAllViewports)
2091
2092
2093class CompressorAxials(object):
2094 """ this class contains all methods used
2095 for implementing automated AutoCAD tables.
2096 """
2097
2098 def __init__(self, data_path, inspection_var_dict, job_dict):
2099 self.data_path = data_path
2100 self.inspection_var_dict = inspection_var_dict
2101 self.job_dict = job_dict
2102 self.num = self.job_dict["Job Number"]
2103 self.var = Shared_variables()
2104 self.job_space = JobWorkspace()
2105 self.define_scope_from_csv()
2106
2107 def define_scope_from_csv(self):
2108 """ iterate through file to determine
2109 which axials were taken during inspection.
2110 a value of 1 represents a captured dimension.
2111 """
2112
2113 print "Defining Scope"
2114
2115 self.oal = 0
2116 self.tc = 0
2117 self.bd = 0
2118
2119 print "Defining Scope 2"
2120
2121 with open(self.data_path + self.num + "\\" + "Axial_Inspection.csv", "rb") as doc:
2122
2123 self.reader = csv.reader(doc)
2124
2125 print self.data_path + self.num + "\\" + "Axial_Inspection.csv"
2126
2127 for row in self.reader:
2128 if row:
2129 print row[0]
2130 if row[0] == "Overall Length":
2131 self.oal = 1
2132 elif row[0] == "Thrust Collar Width":
2133 self.tc = 1
2134 elif "BD" in row[0]:
2135 self.bd = 1
2136
2137 print "Defining Scope 3"
2138
2139 self.total_stage_count = int(self.var.jobDetails["Number of Stages"])
2140 i = 1
2141 self.open_count = 0
2142 while i <= self.total_stage_count:
2143 if self.var.jobDetails["Stage %i Face" % i] == "Open":
2144 self.open_count += 1
2145 i += 1
2146
2147 print "Defining Scope 4"
2148
2149 self.closed_count = self.total_stage_count - self.open_count
2150 self.define_table_attributes()
2151
2152 def define_table_attributes(self):
2153 """ determine size and placement of table. """
2154
2155 print "Defining table attributes"
2156
2157 self.table_columns = self.total_stage_count + \
2158 self.bd + 1 # add extra column for feature type
2159 self.table_length = 10.375 # forms default
2160
2161 self.header_height = .2133
2162 self.title_height = .2533
2163 self.data_height = .156
2164
2165 self.row_count = 2 # title and feature rows, will populate more as method continues
2166 self.open_features = ["Features", "Eye Face",
2167 "I.B.P.", "G.P. Width", "B.P. Thickness"]
2168 self.closed_features = ["Features", "Eye Face", "I.B.P.", "G.P. Width"]
2169
2170 if self.bd == 1:
2171 self.open_features.append("B.D. Face")
2172 self.closed_features.append("B.D. Face")
2173 # set number of rows by impeller type
2174 if self.open_count > 0:
2175 self.axial_table_features = self.open_features
2176 self.row_count = self.row_count + \
2177 (len(self.axial_table_features) - 1)
2178 else:
2179 self.axial_table_features = self.closed_features
2180 self.row_count = self.row_count + \
2181 (len(self.axial_table_features) - 1)
2182
2183 self.table_x = .061 # will be changed
2184 self.table_y = .061 + self.title_height + self.header_height + \
2185 ((self.row_count - 2) * self.data_height)
2186 print "checking for document"
2187 self.job_space.check_for_document(self.create_axial_table)
2188
2189 def create_axial_table(self):
2190
2191 self.acad = Autocad()
2192
2193 while True:
2194 try:
2195 for nObject in self.acad.iter_layouts(doc=self.acad.doc, skip_model=True):
2196 if nObject.Name == "Axials - Compressor":
2197 self.acad.doc.ActiveLayout = nObject
2198 except (COMError, AttributeError) as error:
2199 continue
2200 else:
2201 break
2202
2203 while True:
2204 try:
2205
2206 self.acad.doc.Regen(ACAD.acAllViewports)
2207 # get bold text style and set font to arial
2208 self.text_style = self.acad.Application.ActiveDocument.TextStyles.Item(
2209 "Bold")
2210 self.text_style.SetFont("Arial", True, False, 1, 1)
2211
2212 # create table
2213 self.axial_table = self.acad.doc.paperspace.AddTable(APoint(
2214 self.table_x, self.table_y), self.row_count, self.table_columns, self.data_height, (self.table_length / float(self.table_columns)))
2215
2216 # define title attributes
2217 self.axial_table.SetText(0, 0, "Axial Measurements")
2218 self.axial_table.SetCellTextHeight(0, 0, .1)
2219 self.axial_table.SetRowHeight(0, self.title_height)
2220 self.axial_table.SetTextStyle(ACAD.acTitleRow, "Bold")
2221
2222 # define header attributes
2223 self.axial_table.SetCellTextHeight(1, 0, .07)
2224 self.axial_table.SetRowHeight(1, self.header_height)
2225 self.axial_table.SetTextStyle(ACAD.acHeaderRow, "Bold")
2226
2227 # write features
2228 self.row_target = 1
2229 for f in self.axial_table_features:
2230 self.axial_table.SetText(self.row_target, 0, f)
2231 self.row_target += 1
2232
2233 # write stages
2234 self.column_target = 1
2235 for s in range(self.table_columns - 1):
2236 # check for balance drum
2237 if s == range(self.table_columns - 1)[-1] and self.bd == 1:
2238 self.axial_table.SetText(1, self.column_target, "B.D.")
2239 self.column_target += 1
2240 else:
2241 self.axial_table.SetText(1, self.column_target, "Stage %d" % (self.column_target))
2242 self.column_target += 1
2243 self.populate_axial_table()
2244 except (COMError, AttributeError):
2245 while True:
2246 try:
2247 self.axial_table.SetCellTextHeight(1, 0, .07)
2248 self.axial_table.Delete()
2249 except (COMError, AttributeError):
2250 continue
2251 else:
2252 break
2253 continue
2254 else:
2255 break
2256
2257
2258 def populate_axial_table(self):
2259 print "populating axial table"
2260 """ this method will populate the table
2261 with data extracted from csv file.
2262 """
2263 with open(self.var.roto_directory + self.num + "\\Axial_Inspection.csv", "rb") as doc:
2264 reader = csv.reader(doc)
2265
2266 self.eye_row = 2
2267 self.ibp_row = 3
2268 self.gp_row = 4
2269 #self.bp_thickness_row = 5
2270 self.bd_row = 5
2271 print "up to here"
2272 for row in reader:
2273 #if row:
2274 try:
2275 print row[0]
2276 if "To BD Face" in row[0]:
2277 self.axial_table.SetText(self.bd_row, self.total_stage_count+1, row[3])
2278 print "success 5"
2279 for i in range(1, self.total_stage_count + 1):
2280 print i
2281 if "To Stg " + str(i) + " Eye Face" in row[0]:
2282 print "success 1"
2283 self.axial_table.SetText(self.eye_row, int(i), row[3])
2284 elif "To Stg " + str(i) + " IBP" in row[0]:
2285 self.axial_table.SetText(self.ibp_row, int(i), row[3])
2286 print "success 2"
2287 elif "Stg " + str(i) + " GPW" in row[0]:
2288 self.axial_table.SetText(self.gp_row, int(i), row[3])
2289 print "success 3"
2290 elif "Stg " + str(i) + " BP Thickness" in row[0]:
2291 self.axial_table.SetText(self.bp_row, int(i), row[3])
2292 print "success 4"
2293 except:
2294 print "error right here buddy"
2295 print "row 1222"
2296 # set header row/text height
2297 for r in range(1, self.axial_table.rows):
2298 for c in range(1, self.axial_table.columns):
2299 self.axial_table.SetCellTextHeight(int(r), int(c), .07)
2300 self.axial_table.SetRowHeight(int(r), .156)
2301
2302 # make all cell grids visible and adjust lineweights
2303 self.adjust_table_lineweights(self.axial_table)
2304 print "row 1231"
2305 with open(self.var.roto_directory + self.num + "\\Axial_Inspection.csv", "rb") as doc:
2306 reader = csv.reader(doc)
2307
2308 while True:
2309 try:
2310 # iterates through all objects in AutoCAD
2311 for nObject in self.acad.iter_objects(None, None, None, False):
2312 if hasattr(nObject, 'TextString'):
2313 try:
2314 if nObject.TextString == "tc_thickness":
2315 i = 0
2316 for row in reader:
2317 print "FOUND TC THICKNESS"
2318 if row:
2319 print "ITERATING FOR TC THICKNESS"
2320 if "Thrust Collar Thickness" in row[0]:
2321 nObject.TextString = row[3]
2322 i = 1
2323 if i == 0:
2324 nObject.TextString = "N/A"
2325 except KeyError:
2326 continue
2327
2328 try:
2329 if nObject.TextString == "oa_length":
2330 print "oalength found"
2331 i = 0
2332 doc.seek(0)
2333 for row in reader:
2334 print row[0]
2335 if row:
2336 if "Overall Length" in row[0]:
2337 nObject.TextString = row[3]
2338 i = 1
2339 if i == 0:
2340 nObject.TextString = "N/A"
2341 except KeyError:
2342 continue
2343
2344 try:
2345 if nObject.TextString == "ce_bj":
2346 nObject.TextString = self.var.jobDetails.get("NTE BJ Weight") or "N/A"
2347 if nObject.TextString == "te_bj":
2348 nObject.TextString = self.var.jobDetails.get("TE BJ Weight") or "N/A"
2349 if nObject.TextString == "oa_weight":
2350 nObject.TextString = self.var.jobDetails.get("Overall Weight") or "N/A"
2351 except KeyError:
2352 continue
2353
2354 except COMError:
2355 continue
2356 except IOError:
2357 continue
2358 else:
2359 break
2360 print "DONE WITH THIS SHOIT"
2361 # refresh CAD template to show table
2362 self.check_for_gaps()
2363 self.acad.doc.Regen(ACAD.acAllViewports)
2364
2365 def check_for_gaps(self):
2366 self.gap_dict = {}
2367 for item in self.job_dict:
2368 if "Thermal Gap" in item:
2369 self.gap_dict[item] = self.job_dict[item]
2370
2371 if len(self.gap_dict) > 0:
2372 self.create_thermal_gap_table(False)
2373 else:
2374 self.create_thermal_gap_table(True)
2375
2376 def create_thermal_gap_table(self, empty):
2377 self.empty = empty
2378
2379 if self.empty:
2380 self.gap_row_count = 2
2381 self.gap_column_count = 1
2382 else:
2383 self.gap_row_count = 3
2384 self.gap_column_count = len(self.gap_dict)
2385
2386 while True:
2387 try:
2388 self.gap_table_height = self.header_height + \
2389 self.title_height + self.data_height
2390 self.gap_table_y = self.gap_table_height + .061 + self.table_y
2391 self.gap_table = self.acad.doc.paperspace.AddTable(APoint(
2392 self.table_x, self.gap_table_y), self.gap_row_count, self.gap_column_count, self.data_height, (self.table_length / float(self.gap_column_count)))
2393
2394 # define title attributes
2395 self.gap_table.SetText(0, 0, "Thermal Gaps")
2396 self.gap_table.SetCellTextHeight(0, 0, .1)
2397 self.gap_table.SetRowHeight(0, self.title_height)
2398 self.gap_table.SetTextStyle(ACAD.acTitleRow, "Bold")
2399
2400 if self.empty:
2401 self.gap_table.SetCellTextHeight(1, 0, .07)
2402 self.gap_table.SetCellTextHeight(1, 0, .07)
2403 self.gap_table.SetRowHeight(
2404 1, self.header_height + self.data_height)
2405 self.gap_table.SetText(1, 0, "No thermal gaps found")
2406
2407 else:
2408 self.index = 0
2409 for item in self.gap_dict:
2410 self.gap_table.SetCellTextHeight(1, self.index, .07)
2411 self.index += 1
2412
2413 self.gap_table.SetCellTextHeight(1, 0, .07)
2414 self.gap_table.SetRowHeight(1, self.header_height)
2415 self.gap_table.SetTextStyle(ACAD.acHeaderRow, "Bold")
2416
2417 self.index = 0
2418 self.sorted_dict = sorted(self.gap_dict.items())
2419 for item in self.sorted_dict:
2420 self.gap_table.SetText(1, self.index, item[0][-1])
2421 self.gap_table.SetText(2, self.index, item[1])
2422 self.index += 1
2423
2424 # make all cell grids visible and adjust lineweights
2425 self.adjust_table_lineweights(self.gap_table)
2426 except (COMError, AttributeError) as Error:
2427 while True:
2428 try:
2429 self.gap_table.SetCellTextHeight(1, 0, .07)
2430 self.gap_table.Delete()
2431 except COMError as Error:
2432 continue
2433 except AttributeError as Error:
2434 break
2435 break
2436 continue
2437 else:
2438 break
2439
2440 def adjust_table_lineweights(self, table):
2441 self.table = table
2442
2443 for r in range(self.table.rows):
2444 for c in range(self.table.columns):
2445 self.table.SetCellGridVisibility(r, c, ACAD.acBottomMask, True)
2446 self.table.SetCellGridVisibility(r, c, ACAD.acLeftMask, True)
2447 self.table.SetCellGridVisibility(r, c, ACAD.acRightMask, True)
2448 self.table.SetCellGridVisibility(r, c, ACAD.acTopMask, True)
2449 self.table.SetCellGridLineWeight(
2450 r, c, ACAD.acTopMask, ACAD.acLnWt013)
2451 self.table.SetCellGridLineWeight(
2452 r, c, ACAD.acRightMask, ACAD.acLnWt013)
2453 self.table.SetCellGridLineWeight(
2454 r, c, ACAD.acLeftMask, ACAD.acLnWt013)
2455 self.table.SetCellGridLineWeight(
2456 r, c, ACAD.acBottomMask, ACAD.acLnWt013)
2457 if c == 0:
2458 self.table.SetCellGridLineWeight(
2459 r, c, ACAD.acLeftMask, ACAD.acLnWt050)
2460 if c == (self.table.columns - 1):
2461 self.table.SetCellGridLineWeight(
2462 r, c, ACAD.acRightMask, ACAD.acLnWt050)
2463 if r == 0:
2464 self.table.SetCellGridLineWeight(
2465 r, c, ACAD.acTopMask, ACAD.acLnWt050)
2466 if r == (self.table.rows - 1):
2467 self.table.SetCellGridLineWeight(
2468 r, c, ACAD.acBottomMask, ACAD.acLnWt050)
2469
2470
2471class SteamTurbineAxials(object):
2472 """ this class contains all methods used
2473 for implementing automated AutoCAD tables.
2474 """
2475
2476 def __init__(self, data_path, inspection_var_dict, job_dict):
2477 self.data_path = data_path
2478 self.inspection_var_dict = inspection_var_dict
2479 self.job_dict = job_dict
2480 self.num = self.job_dict["Job Number"]
2481 self.var = Shared_variables()
2482 self.job_space = JobWorkspace()
2483 self.define_scope_from_csv()
2484
2485 def define_scope_from_csv(self):
2486 """ iterate through file to determine
2487 which axials were taken during inspection.
2488 a value of 1 represents a captured dimension.
2489 """
2490
2491 with open(self.data_path + self.num + "\\" + "Axial_Inspection.csv", "rb") as doc:
2492
2493 self.reader = csv.reader(doc)
2494
2495 print self.data_path + self.num + "\\" + "Axial_Inspection.csv"
2496
2497 # check csv for "other dimensions" and add values to self.job_dict so this quantity can be referenced later with the thermal gaps.
2498 # these other dimensions are represented by a single letter in row[0] of csv
2499
2500 self.alphadict = list(islice(multiletters(ascii_uppercase), 100))
2501 print self.alphadict
2502
2503 for row in self.reader:
2504 if row:
2505 print row[0]
2506 if row[0] in self.alphadict:
2507 print "match!"
2508 self.job_dict["Xtra Measurement "+row[0]] = row[3]
2509 else:
2510 pass
2511
2512 print self.job_dict
2513 self.total_stage_count = int(self.var.jobDetails["Number of Stages"])
2514
2515 self.define_table_attributes()
2516
2517 def define_table_attributes(self):
2518 """ determine size and placement of table. """
2519
2520 print "Defining table attributes"
2521
2522 self.table_columns = 1 + self.total_stage_count # add extra column for feature type
2523 self.table_length = 10.375 # forms default
2524
2525 self.header_height = .2133
2526 self.title_height = .2533
2527 self.data_height = .156
2528
2529 self.row_count = 6 # title and feature rows, will populate more as method continues
2530
2531 self.table_x = .061 # will be changed
2532 self.table_y = .061 + self.title_height + self.header_height + ((self.row_count - 2) * self.data_height)
2533 print "checking for document"
2534 self.job_space.check_for_document(self.create_axial_table)
2535
2536 def create_axial_table(self):
2537
2538 self.acad = Autocad()
2539
2540 while True:
2541 try:
2542 for nObject in self.acad.iter_layouts(doc=self.acad.doc, skip_model=True):
2543 if nObject.Name == "Axials - Steam":
2544 self.acad.doc.ActiveLayout = nObject
2545 except (COMError, AttributeError) as error:
2546 continue
2547 else:
2548 break
2549
2550 while True:
2551 try:
2552
2553 self.acad.doc.Regen(ACAD.acAllViewports)
2554 # get bold text style and set font to arial
2555 self.text_style = self.acad.Application.ActiveDocument.TextStyles.Item(
2556 "Bold")
2557 self.text_style.SetFont("Arial", True, False, 1, 1)
2558
2559 # create table
2560 self.axial_table = self.acad.doc.paperspace.AddTable(APoint(
2561 self.table_x, self.table_y), self.row_count, self.table_columns, self.data_height, (self.table_length / float(self.table_columns)))
2562
2563 # define title attributes
2564 self.axial_table.SetText(0, 0, "Axial Measurements")
2565 self.axial_table.SetCellTextHeight(0, 0, .1)
2566 self.axial_table.SetRowHeight(0, self.title_height)
2567 self.axial_table.SetTextStyle(ACAD.acTitleRow, "Bold")
2568
2569 # define header attributes
2570 self.axial_table.SetCellTextHeight(1, 0, .07)
2571 self.axial_table.SetRowHeight(1, self.header_height)
2572 self.axial_table.SetTextStyle(ACAD.acHeaderRow, "Bold")
2573
2574 # write features
2575 self.axial_table_features = ['Disk Face', 'Shroud Band', 'Blade Edge', 'Blade Root']
2576 self.row_target = 2
2577 for f in self.axial_table_features:
2578 self.axial_table.SetText(self.row_target, 0, f)
2579 self.row_target += 1
2580
2581 # write stages
2582 print self.table_columns
2583 self.column_target = 1
2584 for s in range(1, self.table_columns):
2585 print self.column_target
2586 if str(self.var.jobDetails["Curtis Stages"]) == "1" and self.column_target <= 2:
2587 self.axial_table.SetText(1, self.column_target, "Stage C%d" % (self.column_target))
2588 if str(self.var.jobDetails["Curtis Stages"]) == "1" and self.column_target > 2:
2589 self.axial_table.SetText(1, self.column_target, "Stage R%d" % (self.column_target-2))
2590 if str(self.var.jobDetails["Curtis Stages"]) == "0":
2591 self.axial_table.SetText(1, self.column_target, "Stage R%d" % (self.column_target))
2592 self.column_target += 1
2593
2594 self.populate_axial_table()
2595 except (COMError, AttributeError) as error:
2596 print error
2597 while True:
2598 try:
2599 self.axial_table.SetCellTextHeight(1, 0, .07)
2600 self.axial_table.Delete()
2601 except (COMError, AttributeError):
2602 continue
2603 else:
2604 break
2605 continue
2606 else:
2607 break
2608
2609 def populate_axial_table(self):
2610 print "populating axial table steam turbine"
2611 """ this method will populate the table
2612 with data extracted from csv file.
2613 """
2614 with open(self.var.roto_directory + self.num + "\\Axial_Inspection.csv", "rb") as doc:
2615 reader = csv.reader(doc)
2616 for row in reader:
2617 print row
2618 if row:
2619 try:
2620 for i in range(1, self.total_stage_count + 1):
2621 if self.var.jobDetails["Curtis Stages"] == "1":
2622 if "To Stg C" + str(i) + " Disk Face" in row[0]:
2623 self.axial_table.SetText(2, int(i), row[3])
2624 elif "To Stg C" + str(i) + " Shroud Band" in row[0]:
2625 self.axial_table.SetText(3, int(i), row[3])
2626 elif "To Stg C" + str(i) + " Blade Edge" in row[0]:
2627 self.axial_table.SetText(4, int(i), row[3])
2628 elif "To Stg C" + str(i) + " Blade Root" in row[0]:
2629 self.axial_table.SetText(5, int(i), row[3])
2630 elif "To Stg R" + str(i) + " Disk Face" in row[0]:
2631 self.axial_table.SetText(2, int(i+2), row[3])
2632 elif "To Stg R" + str(i) + " Shroud Band" in row[0]:
2633 self.axial_table.SetText(3, int(i+2), row[3])
2634 elif "To Stg R" + str(i) + " Blade Edge" in row[0]:
2635 self.axial_table.SetText(4, int(i+2), row[3])
2636 elif "To Stg R" + str(i) + " Blade Root" in row[0]:
2637 self.axial_table.SetText(5, int(i+2), row[3])
2638 else:
2639 if "To Stg R" + str(i) + " Disk Face" in row[0]:
2640 self.axial_table.SetText(2, int(i), row[3])
2641 elif "To Stg R" + str(i) + " Shroud Band" in row[0]:
2642 self.axial_table.SetText(3, int(i), row[3])
2643 elif "To Stg R" + str(i) + " Blade Edge" in row[0]:
2644 self.axial_table.SetText(4, int(i), row[3])
2645 elif "To Stg R" + str(i) + " Blade Root" in row[0]:
2646 self.axial_table.SetText(5, int(i), row[3])
2647 except KeyError as e:
2648 print "error\n%s" % e
2649
2650 print "what next"
2651
2652 # set header row/text height
2653 for r in range(1, self.axial_table.rows):
2654 for c in range(1, self.axial_table.columns):
2655 self.axial_table.SetCellTextHeight(int(r), int(c), .07)
2656 self.axial_table.SetRowHeight(int(r), .156)
2657 print "done with %s %s" % (r,c)
2658
2659 # make all cell grids visible and adjust lineweights
2660 self.adjust_table_lineweights(self.axial_table)
2661 with open(self.var.roto_directory + self.num + "\\Axial_Inspection.csv", "rb") as doc:
2662 reader = csv.reader(doc)
2663 while True:
2664 try:
2665 # iterates through all objects in AutoCAD
2666 for nObject in self.acad.iter_objects(None, None, None, False):
2667 if hasattr(nObject, 'TextString'):
2668 try:
2669 if nObject.TextString == "out_tc_thickness":
2670 i = 0
2671 for row in reader:
2672 if row:
2673 if "Outboard Thrust Collar Thickness" in row[0]:
2674 nObject.TextString = row[3]
2675 i = 1
2676 if i == 0:
2677 nObject.TextString = "N/A"
2678 if nObject.TextString == "in_tc_thickness":
2679 i = 0
2680 doc.seek(0)
2681 for row in reader:
2682 if row:
2683 if "Inboard Thrust Collar Thickness" in row[0]:
2684 nObject.TextString = row[3]
2685 i = 1
2686 if i == 0:
2687 nObject.TextString = "N/A"
2688 if nObject.TextString == "tc_thickness":
2689 i = 0
2690 doc.seek(0)
2691 for row in reader:
2692 if row:
2693 if "Thrust Collar Thickness" in row[0]:
2694 nObject.TextString = row[3]
2695 i = 1
2696 if i == 0:
2697 nObject.TextString = "N/A"
2698 if nObject.TextString == "oa_length":
2699 i = 0
2700 doc.seek(0)
2701 for row in reader:
2702 if row:
2703 if "Overall Length" in row[0]:
2704 nObject.TextString = row[3]
2705 i = 1
2706 if i == 0:
2707 nObject.TextString = "N/A"
2708
2709 if nObject.TextString == "ce_bj":
2710 nObject.TextString = self.var.jobDetails.get("NTE BJ Weight") or "N/A"
2711 if nObject.TextString == "te_bj":
2712 nObject.TextString = self.var.jobDetails.get("TE BJ Weight") or "N/A"
2713 if nObject.TextString == "oa_weight":
2714 nObject.TextString = self.var.jobDetails.get("Overall Weight") or "N/A"
2715 except KeyError:
2716 continue
2717 except COMError:
2718 continue
2719 except IOError:
2720 continue
2721 else:
2722 break
2723 # refresh CAD template to show table
2724 self.check_for_gaps()
2725 self.acad.doc.Regen(ACAD.acAllViewports)
2726
2727 def check_for_gaps(self):
2728 self.gap_dict = {}
2729
2730 # fill self.gap_dict with thermal gaps and other dimensions extracted from csv file
2731 for item in self.job_dict:
2732 if "Thermal Gap" in item:
2733 self.gap_dict[item] = self.job_dict[item]
2734
2735 elif "Xtra Measurement" in item:
2736 self.gap_dict[item] = self.job_dict[item]
2737
2738 print self.gap_dict
2739
2740 if len(self.gap_dict) > 0:
2741 self.create_thermal_gap_table(False)
2742 else:
2743 self.create_thermal_gap_table(True)
2744
2745 def create_thermal_gap_table(self, empty):
2746 self.empty = empty
2747 self.gap_quantity = 0
2748 self.other_quantity = 0
2749
2750 if self.empty:
2751 self.gap_row_count = 2
2752 self.gap_column_count = 1
2753 else:
2754 self.gap_row_count = 3
2755 self.gap_column_count = len(self.gap_dict)
2756
2757 while True:
2758 try:
2759 self.gap_table_height = self.header_height + self.title_height + self.data_height
2760 self.gap_table_y = self.gap_table_height + .061 + self.table_y
2761 self.gap_table = self.acad.doc.paperspace.AddTable(APoint(self.table_x, self.gap_table_y), self.gap_row_count, self.gap_column_count, self.data_height, (self.table_length / float(self.gap_column_count)))
2762
2763 # define title attributes
2764 self.other_quantity = 0
2765 self.gap_quantity = 0
2766
2767 for item in self.gap_dict: # determine type of measurements and corresponding quantities
2768 if "Xtra Measurement" in item:
2769 self.other_quantity += 1
2770 elif "Thermal Gap" in item:
2771 self.gap_quantity += 1
2772
2773 print self.other_quantity
2774 print self.gap_quantity
2775
2776 if self.other_quantity > 0 and self.gap_quantity > 0: # if both types of measurements exist
2777 print "BOTH"
2778 self.gap_table.UnmergeCells(0,0, 0, self.gap_column_count) # unmerge title cells to allow for multiple columns (thermal gaps and other dimensions)
2779 self.gap_table.MergeCells(0,0,0,(self.gap_quantity-1))
2780 self.gap_table.MergeCells(0,0,self.gap_quantity, (self.gap_quantity+self.other_quantity-1))
2781 self.gap_table.SetText(0, 0, "Thermal Gaps")
2782 self.gap_table.SetText(0, self.gap_quantity, "Other Dimensions")
2783 self.gap_table.SetCellTextHeight(0, 0, .1)
2784 self.gap_table.SetCellTextHeight(0, self.gap_quantity, .1)
2785 self.gap_table.SetCellGridLineWeight(0, 1, ACAD.acLeftMask, ACAD.acLnWt050)
2786 self.gap_table.SetCellGridLineWeight(1, self.gap_quantity, ACAD.acLeftMask, ACAD.acLnWt050)
2787 self.gap_table.SetCellGridLineWeight(2, self.gap_quantity, ACAD.acLeftMask, ACAD.acLnWt050)
2788 elif self.other_quantity > 0 and self.gap_quantity == 0:
2789 self.gap_table.SetText(0, 0, "Other Dimensions")
2790 self.gap_table.SetCellTextHeight(0, 0, .1)
2791
2792 else:
2793 self.gap_table.SetText(0, 0, "Thermal Gaps")
2794 self.gap_table.SetCellTextHeight(0, 0, .1)
2795
2796
2797
2798 self.gap_table.SetRowHeight(0, self.title_height)
2799 self.gap_table.SetTextStyle(ACAD.acTitleRow, "Bold")
2800
2801 if self.empty:
2802 self.gap_table.SetCellTextHeight(1, 0, .07)
2803 self.gap_table.SetCellTextHeight(1, 0, .07)
2804 self.gap_table.SetRowHeight(1, self.header_height + self.data_height)
2805 self.gap_table.SetText(1, 0, "No thermal gaps found")
2806
2807 else:
2808 self.index = 0
2809 for item in self.gap_dict:
2810 self.gap_table.SetCellTextHeight(1, self.index, .07)
2811 self.index += 1
2812
2813 self.gap_table.SetCellTextHeight(1, 0, .07)
2814 self.gap_table.SetRowHeight(1, self.header_height)
2815 self.gap_table.SetTextStyle(ACAD.acHeaderRow, "Bold")
2816
2817 self.index = 0
2818 self.sorted_dict = sorted(self.gap_dict.items())
2819 print self.sorted_dict
2820 for item in self.sorted_dict:
2821 self.gap_table.SetText(1, self.index, item[0][-1])
2822 self.gap_table.SetText(2, self.index, item[1])
2823 self.index += 1
2824
2825 # make all cell grids visible and adjust lineweights
2826 self.adjust_table_lineweights(self.gap_table)
2827 if self.other_quantity > 0 and self.gap_quantity > 0:
2828 self.gap_table.SetCellGridLineWeight(0, self.gap_quantity, ACAD.acLeftMask, ACAD.acLnWt050)
2829 self.gap_table.SetCellGridLineWeight(1, self.gap_quantity, ACAD.acLeftMask, ACAD.acLnWt050)
2830 self.gap_table.SetCellGridLineWeight(2, self.gap_quantity, ACAD.acLeftMask, ACAD.acLnWt050)
2831
2832
2833 except (COMError, AttributeError) as Error:
2834 while True:
2835 try:
2836 self.gap_table.SetCellTextHeight(1, 0, .07)
2837 self.gap_table.Delete()
2838 except COMError as Error:
2839 continue
2840 except AttributeError as Error:
2841 break
2842 break
2843 continue
2844 else:
2845 break
2846
2847 def adjust_table_lineweights(self, table):
2848 self.table = table
2849
2850 for r in range(self.table.rows):
2851 for c in range(self.table.columns):
2852 self.table.SetCellGridVisibility(r, c, ACAD.acBottomMask, True)
2853 self.table.SetCellGridVisibility(r, c, ACAD.acLeftMask, True)
2854 self.table.SetCellGridVisibility(r, c, ACAD.acRightMask, True)
2855 self.table.SetCellGridVisibility(r, c, ACAD.acTopMask, True)
2856 self.table.SetCellGridLineWeight(
2857 r, c, ACAD.acTopMask, ACAD.acLnWt013)
2858 self.table.SetCellGridLineWeight(
2859 r, c, ACAD.acRightMask, ACAD.acLnWt013)
2860 self.table.SetCellGridLineWeight(
2861 r, c, ACAD.acLeftMask, ACAD.acLnWt013)
2862 self.table.SetCellGridLineWeight(
2863 r, c, ACAD.acBottomMask, ACAD.acLnWt013)
2864 if c == 0:
2865 self.table.SetCellGridLineWeight(
2866 r, c, ACAD.acLeftMask, ACAD.acLnWt050)
2867 if c == (self.table.columns - 1):
2868 self.table.SetCellGridLineWeight(
2869 r, c, ACAD.acRightMask, ACAD.acLnWt050)
2870 if r == 0:
2871 self.table.SetCellGridLineWeight(
2872 r, c, ACAD.acTopMask, ACAD.acLnWt050)
2873 if r == (self.table.rows - 1):
2874 self.table.SetCellGridLineWeight(
2875 r, c, ACAD.acBottomMask, ACAD.acLnWt050)
2876
2877
2878roto = App()
2879roto.root.mainloop()