-
Notifications
You must be signed in to change notification settings - Fork 0
/
Autohybrid_create_openjob_V3.py
170 lines (126 loc) · 5.11 KB
/
Autohybrid_create_openjob_V3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 8 11:37:41 2021
last change on Mai 04 2022
@author: aumuemic,Lichu
"""
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
from xml.etree import cElementTree as ET
class App(tk.Tk):
def __init__(self):
super().__init__()
# configure the root window
self.title('My Autohybrid-App - Create a new job')
self.geometry('380x280')
# label
self.label = ttk.Label(self, text='Autohybrid-app for updating positions')
self.label.pack()
# button
self.button = tk.Button(self, text='About')
self.button['command'] = self.button_clicked
self.button.pack()
# label
self.label = ttk.Label(self, text='1. Select result-file for new xy-coordinates')
self.label.pack()
self.open_button = tk.Button(self, text='Open a File', command=self.select_file)
self.open_button.pack(side="top")
# label
self.label = ttk.Label(self, text='2. Load the reference openjob-file')
self.label.pack()
# Referencejob-button
self.xy_button = tk.Button(self)
self.xy_button["text"] = "Open Reference \n openjob-file"
self.xy_button["command"] = self.select_openjob
self.xy_button.pack(side="top")
# label
self.label = ttk.Label(self, text='3. Save file as new.openjob with new coordinates')
self.label.pack()
# xy-button
self.xy_button = tk.Button(self)
self.xy_button["text"] = "Export \n openjob-file"
self.xy_button["command"] = self.save_openjob
self.xy_button.pack(side="top")
# label
self.label = ttk.Label(self, text='')
self.label.pack()
#quit-button
self.quit = tk.Button(self, text="Quit", fg="red", command=self.destroy)
self.quit.pack(side="top")
def button_clicked(self):
showinfo(title='Information',
message='Autohybrid-App for updating new Positions for Parts on a buildung-plattfom for an EOS-machine.')
def select_file(self):
filetypes = (
('text files', '*.txt'),
('All files', '*.*')
)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=filetypes)
showinfo(title='Selected File', message=filename)
self.result_file = open(filename, "rt")
def select_openjob(self):
filetypes = (
('text files', '*.openjob'),
('All files', '*.*')
)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=filetypes)
showinfo(title='Selected File', message=filename)
self.job_file = filename
print(self.job_file)
def save_openjob(self):
self.tree = ET.parse(self.job_file)
self.root = self.tree.getroot()
content = self.result_file.readlines()
### finding tags ###
partNumber = 0
xPos = list();
yPos = list();
for parts in self.root.findall('parts'):
for part in parts.findall('part'):
parameter = part.find('./parameter').text
for translation in part.findall('translation'):
for x in translation.findall('x'):
x = translation.find('x').text
partNumber = partNumber + 1
### count parts in job ###
print('Anzahl der Teile: '+str(partNumber))
self.xPos =list(range(partNumber))
self.yPos =list(range(partNumber))
for i in range(partNumber):
self.xPos[i] = content[i*7+3].rstrip('\n')
self.yPos[i] = content[i*7+5].rstrip('\n')
print('The coordinates will be replaced with:\n')
print(self.xPos)
print(self.yPos)
print('\n')
# print(str(content[3].rstrip('\n'))) # rstrip() cut charakters from right side
for i in range(partNumber):
a = 1
for x in self.root.iter('x'):
# print(x)
# print(x.text)
if a==(4.*i+1):
x.text = str(self.xPos[i])
a = a + 1
a = 1
for y in self.root.iter('y'):
# print(y)
# print(y.text)
if a==(4.*i+1):
y.text = str(self.yPos[i])
a = a + 1
path = 'C:/Users/wanglich/Desktop/new.openjob'
self.tree.write(path) # set path and filename
print('Neues dokument ist speichert unter',path)
self.result_file.close()
if __name__ == "__main__":
app = App()
app.mainloop()