chiark / gitweb /
Clear existing quickprint folders before recreating them
[cura.git] / scripts / recreate_lulzbot_profiles.py
1 #!/usr/bin/python
2 #
3 # This script is used to generate print profiles for lulzbot printers
4 # based off of the lulzbot_profiles directory which contains common
5 # profiles for multiple toolheads.
6 # To generate profiles or update them, run the script from the root Cura
7 # directory with ./scripts/recreate_lulzbot_profiles.py
8 #
9
10
11 import glob
12 import os
13 import shutil
14
15
16 CURA_QUICKPRINT_DIR="resources/quickprint/"
17 PROFILES_DIR="lulzbot_profiles"
18
19 dir_map = {
20     'Mini_single_extruder_v2': ('lulzbot_mini',),
21     'Mini_flexystruder_v2': ('lulzbot_mini_flexystruder',),
22     'TAZ_single_extruder_0.35nozzle': ('lulzbot_TAZ_4_SingleV1',
23                                        'lulzbot_TAZ_5_SingleV1',
24                                        'lulzbot_TAZ_4_035nozzle',
25                                        'lulzbot_TAZ_5_035nozzle'),
26     'TAZ_single_extruder_0.5nozzle': ('lulzbot_TAZ_4_05nozzle',
27                                       'lulzbot_TAZ_5_05nozzle'),
28     'TAZ_dual_extruder_v1': ('lulzbot_TAZ_4_DualV1',
29                              'lulzbot_TAZ_5_DualV1'),
30     'TAZ_dual_extruder_v2': ('lulzbot_TAZ_4_DualV2',
31                              'lulzbot_TAZ_5_DualV2'),
32     'TAZ_flexystruder_v1': ('lulzbot_TAZ_4_FlexystruderV1',
33                             'lulzbot_TAZ_5_FlexystruderV1'),
34     'TAZ_flexystruder_v2': ('lulzbot_TAZ_4_FlexystruderV2',
35                             'lulzbot_TAZ_5_FlexystruderV2'),
36     'TAZ_flexy_dually_v1': ('lulzbot_TAZ_4_FlexyDuallyV1',
37                             'lulzbot_TAZ_5_FlexyDuallyV1'),
38     'TAZ_flexy_dually_v2': ('lulzbot_TAZ_4_FlexyDuallyV2',
39                             'lulzbot_TAZ_5_FlexyDuallyV2'),
40 }
41
42 material_map = {
43     # Beginner
44     "HIPS_eSUN": "HIPS",
45     "PLA_eSUN": "PLA",
46     "PLA_VP": "PLA",
47     # Intermediate
48     "ABS_VP": "ABS",
49     "Laybrick" : "laybrick",
50     "PP-Iron": "protopasta-magnetic-iron",
51     "PP-Steel": "protopasta-stainless-steel",
52     # Advanced
53     "Alloy910": "alloy910",
54     "Bridge": "bridge",
55     "Laywood": "laywood",
56     "n-vent": "n-vent",
57     "PCTPE": "PCTPE",
58     "PC-ABS": "PC-ABS",
59     "T-Glase": "t-glase",
60     # Expert
61     "PP-Conductive": "protopasta-conductive-PLA",
62     "HIPS_VP" : "HIPS",
63     "PC_VP": "polycarbonate",
64     "618-Nylon": "618-645-nylon",
65     "645-Nylon": "618-645-nylon",
66     # Dual extruder (Expert)
67     'PLA_PVA': 'PLA-PVA-support',
68     'ABS_ABS': 'ABS-ABS',
69     'PLA_PLA': 'PLA-PLA',
70     # Flexystruder (Expert)
71     "ninjaflex" : "ninjaflex",
72     "semiflex" : "semiflex",
73     # Flexy Dually (Expert)
74     "ABS_ninjaflex" : "ABS-ninjaflex",
75     "ABS_semiflex" : "ABS-semiflex",
76
77     # Others
78     # bamboofill
79     # b-pet
80     # bronzefill
81     # copperfill
82     # tritan
83     # PLA-protopasta-conductive-PLA
84 }
85
86 material_order = {
87     # Beginner
88     "HIPS_eSUN": 0,
89     "PLA_eSUN": 1,
90     "PLA_VP": 2,
91     # Intermediate
92     "ABS_VP": 10,
93     "Laybrick" : 11,
94     "PP-Iron": 12,
95     "PP-Steel": 13,
96     # Advanced
97     "Alloy910": 50,
98     "Bridge": 51,
99     "Laywood": 52,
100     "n-vent": 53,
101     "PCTPE": 54,
102     "PC-ABS": 55,
103     "T-Glase": 56,
104     # Expert
105     "PP-Conductive": 500,
106     "HIPS_VP" : 501,
107     "PC_VP": 502,
108     "618-Nylon": 503,
109     "645-Nylon": 504,
110     # Dual extruder (Expert)
111     'PLA_PVA': 2,
112     'ABS_ABS': 1,
113     'PLA_PLA': 0,
114     # Flexystruder (Expert)
115     "ninjaflex" : 0,
116     "semiflex" : 1,
117     # Flexy Dually (Expert)
118     "ABS_ninjaflex" : 0,
119     "ABS_semiflex" : 1,
120 }
121
122 material_types = {
123     # Beginner
124     "HIPS_eSUN": "Beginner",
125     "PLA_eSUN": "Beginner",
126     "PLA_VP": "Beginner",
127     # Intermediate
128     "ABS_VP": "Intermediate",
129     "Laybrick" : "Intermediate",
130     "PP-Iron": "Intermediate",
131     "PP-Steel": "Intermediate",
132     # Advanced
133     "Alloy910": "Advanced",
134     "Bridge": "Advanced",
135     "Laywood": "Advanced",
136     "n-vent": "Advanced",
137     "PCTPE": "Advanced",
138     "PC-ABS": "Advanced",
139     "T-Glase": "Advanced",
140     # Expert
141     "PP-Conductive": "Expert",
142     "HIPS_VP" : "Expert",
143     "PC_VP": "Expert",
144     "618-Nylon": "Expert",
145     "645-Nylon": "Expert",
146     # Dual extruder (Expert)
147     'PLA_PVA': "Expert",
148     'ABS_ABS': "Expert",
149     'PLA_PLA': "Expert",
150     # Flexystruder (Expert)
151     "ninjaflex" : "Expert",
152     "semiflex" : "Expert",
153     # Flexy Dually (Expert)
154     "ABS_ninjaflex" : "Expert",
155     "ABS_semiflex" : "Expert",
156 }
157
158 material_names = {
159     # Beginner
160     "HIPS_eSUN": "HIPS (eSUN)",
161     "PLA_eSUN": "PLA (eSUN)",
162     "PLA_VP": "PLA (Village Plastics)",
163     # Intermediate
164     "ABS_VP": "ABS (Village Plastics)",
165     "Laybrick" : "Laybrick (CC-Products)",
166     "PP-Iron": "Magnetic (Proto-pasta)",
167     "PP-Steel": "Steel PLA (Proto-pasta)",
168     # Advanced
169     "Alloy910": "Alloy 910 (Taulman)",
170     "Bridge": "Bridge Nylon (Taulman)",
171     "Laywood": "Laywoo-D3 (CC-Products)",
172     "n-vent": "n-vent (Taulman)",
173     "PCTPE": "PCTPE (Taulman)",
174     "PC-ABS": "PC-ABS (Proto-pasta)",
175     "T-Glase": "t-glase (Taulman)",
176     # Expert
177     "PP-Conductive": "Conductive (Proto-pasta)",
178     "HIPS_VP" : "HIPS (Village Plastics)",
179     "PC_VP": "PC (Village Plastics)",
180     "618-Nylon": "618 Nylon (Taulman)",
181     "645-Nylon": "645 Nylon (Taulman)",
182     # Dual extruder (Expert)
183     'PLA_PVA': "PLA & PVA",
184     'ABS_ABS': "ABS & ABS",
185     'PLA_PLA': "PLA & PLA",
186     # Flexystruder (Expert)
187     "ninjaflex" : "NinjaFlex (Fenner Drives)",
188     "semiflex" : "SemiFlex (Fenner Drives)",
189     # Flexy Dually (Expert)
190     "ABS_ninjaflex" : "ABS & NinjaFlex",
191     "ABS_semiflex" : "ABS & SemiFlex",
192 }
193
194 bed_prep_materials = {
195     "ninjaflex",
196     "semiflex",
197     "Alloy910",
198     "Bridge",
199     "n-vent",
200         "PCTPE",
201         "T-Glase",
202         "618-Nylon",
203         "645-Nylon",
204         "PC-ABS"
205 }
206
207 material_url = {
208     # Beginner
209     "HIPS_eSUN": "www.lulzbot.com/products/hips-3mm-filament-1kg-reel-esun",
210     "PLA_eSUN": "www.lulzbot.com/products/pla-3mm-filament-1kg-or-500g-reel-esun",
211     "PLA_VP": "www.lulzbot.com/products/pla-3mm-filament-1kg-reel-village-plastics",
212     # Intermediate
213     "ABS_VP": "www.lulzbot.com/products/abs-3mm-filament-1kg-reel",
214     "Laybrick" : "www.lulzbot.com/products/laybrick-filament-3mm",
215     "PP-Iron": "www.lulzbot.com/products/magnetic-iron-pla-3mm-filament-500g-reel-proto-pasta",
216     "PP-Steel": "www.lulzbot.com/products/stainless-steel-pla-3mm-filament-500g-reel-proto-pasta",
217     # Advanced
218     "Alloy910": "www.lulzbot.com/products/alloy-910-3mm-filament-1lb-reel-taulman",
219     "Bridge": "www.lulzbot.com/products/taulman-bridge-nylon-3mm-filament-1-pound",
220     "Laywood": "www.lulzbot.com/products/laywoo-d3-cherry-laywood-3mm-250g-coil-cc-products",
221     "n-vent": "www.lulzbot.com/products/n-vent-3mm-filament-1lb-taulman",
222     "PCTPE": "www.lulzbot.com/products/taulman-pctpe-3mm-filament-1-pound",
223     "PC-ABS": "www.lulzbot.com/products/pc-abs-alloy-3mm-filament-500g-reel-proto-pasta",
224     "T-Glase": "www.lulzbot.com/products/t-glase-3mm-filament-1lb-reel",
225     # Expert
226     "PP-Conductive": "www.lulzbot.com/products/conductive-pla-3mm-filament-500g-reel-proto-pasta",
227     "HIPS_VP" : "www.lulzbot.com/products/hips-3mm-filament-1kg-or-5lb-reel-village-plastics",
228     "PC_VP": "www.lulzbot.com/products/polycarbonate-3mm-filament-1kg-reel",
229     "618-Nylon": "www.lulzbot.com/products/taulman-618-nylon-3mm-filament-1-pound",
230     "645-Nylon": "www.lulzbot.com/products/taulman-645-nylon-3mm-filament-1-pound",
231     # Dual extruder (Expert)
232     'ABS_ABS': "www.lulzbot.com/products/abs-3mm-filament-1kg-reel",
233     'PLA_PLA': "www.lulzbot.com/products/pla-3mm-filament-1kg-or-500g-reel-esun",
234     'PLA_PVA': "www.lulzbot.com/products/natural-pva-3mm-filament-05kg-reel-esun",
235     # Flexystruder (Expert)
236     "ninjaflex" : "www.lulzbot.com/ninjaflex",
237     "semiflex" : "www.lulzbot.com/products/semiflex-tpe-thermoplastic-elastomer-3mm-075kg",
238     # Flexy Dually (Expert)
239     "ABS_ninjaflex" : "www.lulzbot.com/ninjaflex",
240     "ABS_semiflex" : "www.lulzbot.com/products/semiflex-tpe-thermoplastic-elastomer-3mm-075kg",
241 }
242
243 profile_map = {
244     'medium-quality': 'Standard',
245     'high-speed': 'High speed',
246     'high-quality': 'High detail',
247     'high-clarity': 'High clarity',
248     'high-strength': 'High strength'
249 }
250
251 profile_order = {
252     'medium-quality': 0,
253     'high-speed': 1,
254     'high-quality': 2,
255     'high-clarity': 3,
256     'high-strength': 4
257 }
258
259 disable_materials = {
260     'PET': ('High', 'Low', 'Normal', 'Ulti'),
261     'PLA': ('High', 'Low', 'Normal', 'Ulti'),
262     'ABS': ('High', 'Low', 'Normal', 'Ulti')
263 }
264
265 def find_files_for_material(files, material):
266     result = []
267     for file in files:
268         filename = os.path.basename(file)
269         if filename.startswith(material):
270             for p in profile_map.keys():
271                 if filename.startswith(material + "_" + p):
272                     profile = p
273                     result.append((file, material, profile))
274     return result
275     
276 def create_machine_type(machine_type, path, dir):
277     files = glob.glob(os.path.join(path, "*.ini"))
278     path = os.path.join(CURA_QUICKPRINT_DIR, machine_type)
279     for m in material_map.keys():
280         result = find_files_for_material(files, material_map[m])
281         for (file, material, profile) in result:
282             material = m
283             if file is None or material is None or profile is None:
284                 continue
285             filename = os.path.basename(file)
286             profile_file = os.path.join("..", "..", "..", PROFILES_DIR, dir, filename)
287             if not os.path.exists(os.path.join(path, material, profile)):
288                 os.makedirs(os.path.join(path, material, profile))
289             with open(os.path.join(path, material, 'material.ini'), 'w') as f:
290                 f.write("[info]\n")
291                 f.write("name = %s\n" % material_names[material])
292                 order = material_order[material]
293                 if material_types.has_key(material):
294                     types = material_types[material]
295                     if (material == "HIPS_eSUN" and machine_type.startswith("lulzbot_mini")) or \
296                        (material == "ABS_VP" and machine_type.startswith("lulzbot_TAZ")):
297                         types = types + "|First Run"
298                         order = 0
299                     f.write("material_types = %s\n" % types)
300                 f.write("order = %d\n" % order)
301                 if material in bed_prep_materials:
302                     f.write("description = \
303                     Bed preparation required: \n\
304                     Apply a PVA-based glue stick \n\
305                     to bed surface before printing.\n")
306                 if material_url.has_key(material):
307                     f.write("url = %s\n" % material_url[material])
308             with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
309                 f.write("[info]\n")
310                 f.write("name = %s\n" % profile_map[profile])
311                 f.write("order = %d\n" % profile_order[profile])
312                 f.write("profile_file = %s\n" % profile_file)
313     for material in disable_materials.keys():
314         if os.path.exists(os.path.join(path, material)):
315             for profile in disable_materials[material]:
316                 if not os.path.exists(os.path.join(path, material, profile)):
317                     os.makedirs(os.path.join(path, material, profile))
318                     with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
319                         f.write("[info]\n")
320                         f.write("disabled = true\n")
321         else:
322             os.makedirs(os.path.join(path, material))
323             with open(os.path.join(path, material, 'material.ini'), 'w') as f:
324                 f.write("[info]\n")
325                 f.write("disabled = true\n")
326
327 def clear_quickprint_folders():
328     here = os.getcwd()
329     quickprint_path = os.path.join(here,CURA_QUICKPRINT_DIR)
330     candidates = os.listdir(quickprint_path)
331     
332     folder_paths = []
333     for candidate in candidates:
334         if "lulzbot_mini" in candidate or \
335            "lulzbot_TAZ" in candidate:
336             candidate_path = os.path.join(quickprint_path, candidate)
337             if os.path.isdir(candidate_path):
338                 folder_paths.append(candidate_path)
339     for path in folder_paths:
340         shutil.rmtree(path)
341     if not folder_paths:
342         print("No Quickprint folders to delete")
343     else:
344         print("Quickprint folders deleted")
345
346 def main():
347     if not os.path.exists(CURA_QUICKPRINT_DIR):
348         print "Cura path is wrong"
349         return -1
350
351     clear_quickprint_folders()
352
353     dirs = glob.glob(os.path.join(CURA_QUICKPRINT_DIR, PROFILES_DIR, "*"))
354  
355     for d in dirs:
356         dir = os.path.basename(d)
357         if dir_map.has_key(dir):
358             for machine_type in dir_map[dir]:
359                 create_machine_type(machine_type, d, dir)
360
361     print "Quickprint profiles regenerated"
362
363
364 if __name__ == '__main__':
365     main()