chiark / gitweb /
e0c98ed8dd21ca91ff07619ea1147f4e89a87577
[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 update profiles, 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     'TAZ6_single_tilapia': ('lulzbot_TAZ_6_Single_Tilapia',),
41 }
42
43 material_map = {
44     # Beginner
45     "HIPS_eSUN": "HIPS",
46     "PLA_eSUN": "PLA",
47     "PLA_VP": "PLA",
48     # Intermediate
49     "ABS_VP": "ABS",
50     "Laybrick" : "laybrick",
51     "PP-Iron": "protopasta-magnetic-iron",
52     "PP-Steel": "protopasta-stainless-steel",
53     "Bamboofill": "bamboofill",
54     "Woodfill": "woodfill",
55     # Advanced
56     "Alloy910": "alloy910",
57     "Bridge": "bridge",
58     "Laywood": "laywood",
59     "n-vent": "n-vent",
60     "XT": "XT",
61     "INOVA-1800": "CS-INOVA-1800",
62     "PCTPE": "PCTPE",
63     "PC-ABS": "PC-ABS",
64     "T-Glase": "t-glase",
65     "Bronzefill": "bronzefill",
66     "Copperfill": "copperfill",
67     # Expert
68     "PP-Conductive": "protopasta-conductive-PLA",
69     "HIPS_VP" : "HIPS",
70     "PC_VP": "polycarbonate",
71     "618-Nylon": "618-645-nylon",
72     "645-Nylon": "618-645-nylon",
73     # Dual extruder (Expert)
74     'PLA_PVA': 'PLA-PVA-support',
75     'ABS_ABS': 'ABS-ABS',
76     'PLA_PLA': 'PLA-PLA',
77     # Flexystruder (Expert)
78     "ninjaflex" : "ninjaflex",
79     "semiflex" : "semiflex",
80     # Flexy Dually (Expert)
81     "ABS_ninjaflex" : "ABS-ninjaflex",
82     "ABS_semiflex" : "ABS-semiflex",
83
84     # Others
85     # b-pet
86     # tritan
87     # PLA-protopasta-conductive-PLA
88 }
89
90 material_order = {
91     # Beginner
92     "HIPS_eSUN": 0,
93     "PLA_eSUN": 1,
94     "PLA_VP": 2,
95     # Intermediate
96     "ABS_VP": 10,
97     "Laybrick" : 11,
98     "PP-Iron": 12,
99     "PP-Steel": 13,
100     "Bamboofill":14,
101     "Woodfill":15,
102     # Advanced
103     "Alloy910": 50,
104     "Bridge": 51,
105     "Laywood": 52,
106     "n-vent": 53,
107     "XT": 54,
108     "INOVA-1800": 55,
109     "PCTPE": 56,
110     "PC-ABS": 57,
111     "T-Glase": 58,
112     "Bronzefill":59,
113     "Copperfill":60,
114     # Expert
115     "PP-Conductive": 500,
116     "HIPS_VP" : 501,
117     "PC_VP": 502,
118     "618-Nylon": 503,
119     "645-Nylon": 504,
120     # Dual extruder (Expert)
121     'PLA_PVA': 2,
122     'ABS_ABS': 1,
123     'PLA_PLA': 0,
124     # Flexystruder (Expert)
125     "ninjaflex" : 0,
126     "semiflex" : 1,
127     # Flexy Dually (Expert)
128     "ABS_ninjaflex" : 0,
129     "ABS_semiflex" : 1,
130 }
131
132 material_types = {
133     # Beginner
134     "HIPS_eSUN": "Beginner",
135     "PLA_eSUN": "Beginner",
136     "PLA_VP": "Beginner",
137     # Intermediate
138     "ABS_VP": "Intermediate",
139     "Laybrick" : "Intermediate",
140     "PP-Iron": "Intermediate",
141     "PP-Steel": "Intermediate",
142     "Bamboofill": "Intermediate",
143     "Woodfill": "Intermediate",
144     # Advanced
145     "Alloy910": "Advanced",
146     "Bridge": "Advanced",
147     "Laywood": "Advanced",
148     "n-vent": "Advanced",
149     "XT": "Advanced",
150     "INOVA-1800": "Advanced",
151     "PCTPE": "Advanced",
152     "PC-ABS": "Advanced",
153     "T-Glase": "Advanced",
154     "Bronzefill": "Advanced",
155     "Copperfill": "Advanced",
156     # Expert
157     "PP-Conductive": "Expert",
158     "HIPS_VP" : "Expert",
159     "PC_VP": "Expert",
160     "618-Nylon": "Expert",
161     "645-Nylon": "Expert",
162     # Dual extruder (Expert)
163     'PLA_PVA': "Expert",
164     'ABS_ABS': "Expert",
165     'PLA_PLA': "Expert",
166     # Flexystruder (Expert)
167     "ninjaflex" : "Expert",
168     "semiflex" : "Expert",
169     # Flexy Dually (Expert)
170     "ABS_ninjaflex" : "Expert",
171     "ABS_semiflex" : "Expert",
172 }
173
174 material_names = {
175     # Beginner
176     "HIPS_eSUN": "HIPS (eSUN)",
177     "PLA_eSUN": "PLA (eSUN)",
178     "PLA_VP": "PLA (Village Plastics)",
179     # Intermediate
180     "ABS_VP": "ABS (Village Plastics)",
181     "Laybrick" : "Laybrick (CC-Products)",
182     "PP-Iron": "Magnetic (Proto-pasta)",
183     "PP-Steel": "Steel PLA (Proto-pasta)",
184     "Bamboofill": "Bamboofill (colorFabb)",
185     "Woodfill": "Woodfill (colorFabb)",
186     # Advanced
187     "Alloy910": "Alloy 910 (Taulman)",
188     "Bridge": "Bridge Nylon (Taulman)",
189     "Laywood": "Laywoo-D3 (CC-Products)",
190     "n-vent": "n-vent (Taulman)",
191     "XT": "XT (colorFabb)",
192     "INOVA-1800": "INOVA-1800 (ChromaStrand)",
193     "PCTPE": "PCTPE (Taulman)",
194     "PC-ABS": "PC-ABS (Proto-pasta)",
195     "T-Glase": "t-glase (Taulman)",
196     "Bronzefill": "Bronzefill (colorFabb)",
197     "Copperfill": "Copperfill (colorFabb)",
198     # Expert
199     "PP-Conductive": "Conductive (Proto-pasta)",
200     "HIPS_VP" : "HIPS (Village Plastics)",
201     "PC_VP": "PC (Village Plastics)",
202     "618-Nylon": "618 Nylon (Taulman)",
203     "645-Nylon": "645 Nylon (Taulman)",
204     # Dual extruder (Expert)
205     'PLA_PVA': "PLA & PVA",
206     'ABS_ABS': "ABS & ABS",
207     'PLA_PLA': "PLA & PLA",
208     # Flexystruder (Expert)
209     "ninjaflex" : "NinjaFlex (Fenner Drives)",
210     "semiflex" : "SemiFlex (Fenner Drives)",
211     # Flexy Dually (Expert)
212     "ABS_ninjaflex" : "ABS & NinjaFlex",
213     "ABS_semiflex" : "ABS & SemiFlex",
214 }
215
216 bed_prep_materials = {
217     "ninjaflex",
218     "semiflex",
219     "Alloy910",
220     "Bridge",
221     "n-vent",
222     "XT",
223     "INOVA-1800",
224         "PCTPE",
225         "T-Glase",
226         "618-Nylon",
227         "645-Nylon",
228         "PC-ABS"
229 }
230
231 material_url = {
232     # Beginner
233     "HIPS_eSUN": "lulzbot.com/store/filament/hips-esun",
234     "PLA_eSUN": "lulzbot.com/store/filament/pla-esun",
235     "PLA_VP": "lulzbot.com/store/filament/pla-village",
236     # Intermediate
237     "ABS_VP": "lulzbot.com/store/filament/abs",
238     "Laybrick" : "lulzbot.com/store/filament/laybrick",
239     "PP-Iron": "lulzbot.com/store/filament/magnetic-iron-pla",
240     "PP-Steel": "lulzbot.com/store/filament/stainless-steel-pla",
241 #    "Bamboofill": "",
242 #    "Woodfill": "",
243     # Advanced
244     "Alloy910": "lulzbot.com/store/filament/alloy-910",
245     "Bridge": "lulzbot.com/store/filament/bridge-nylon",
246     "Laywood": "lulzbot.com/store/filament/laywoo-d3-laywood",
247     "n-vent": "lulzbot.com/store/filament/n-vent",
248 #    "XT": "",
249     "PCTPE": "lulzbot.com/store/filament/pctpe",
250     "PC-ABS": "lulzbot.com/store/filament/pc-abs-alloy",
251     "T-Glase": "lulzbot.com/store/filament/t-glase",
252 #    "Bronzefill": "",
253 #    "Copperfill": "",
254     # Expert
255     "PP-Conductive": "lulzbot.com/store/filament/conductive-pla",
256     "HIPS_VP" : "lulzbot.com/store/filament/hips",
257     "PC_VP": "lulzbot.com/store/filament/polycarbonate",
258     "618-Nylon": "lulzbot.com/store/filament/nylon-618",
259     "645-Nylon": "lulzbot.com/store/filament/nylon-645",
260     # Dual extruder (Expert)
261     'ABS_ABS': "lulzbot.com/store/filament/abs",
262     'PLA_PLA': "lulzbot.com/store/filament/pla-esun",
263     'PLA_PVA': "lulzbot.com/store/filament/natural-pva",
264     # Flexystruder (Expert)
265     "ninjaflex" : "lulzbot.com/store/filament/ninjaflex",
266     "semiflex" : "lulzbot.com/store/filament/semiflex",
267     # Flexy Dually (Expert)
268     "ABS_ninjaflex" : "lulzbot.com/store/filament/ninjaflex",
269     "ABS_semiflex" : "lulzbot.com/store/filament/semiflex",
270 }
271
272 profile_map = {
273     'medium-quality': 'Standard',
274     'high-speed': 'High speed',
275     'high-quality': 'High detail',
276     'high-clarity': 'High clarity',
277     'high-strength': 'High strength'
278 }
279
280 profile_order = {
281     'medium-quality': 0,
282     'high-speed': 1,
283     'high-quality': 2,
284     'high-clarity': 3,
285     'high-strength': 4
286 }
287
288 disable_materials = {
289     'PET': ('High', 'Low', 'Normal', 'Ulti'),
290     'PLA': ('High', 'Low', 'Normal', 'Ulti'),
291     'ABS': ('High', 'Low', 'Normal', 'Ulti')
292 }
293
294 def find_files_for_material(files, material):
295     result = []
296     for file in files:
297         filename = os.path.basename(file)
298         if filename.startswith(material):
299             for p in profile_map.keys():
300                 if filename.startswith(material + "_" + p):
301                     profile = p
302                     result.append((file, material, profile))
303     return result
304     
305 def create_machine_type(machine_type, path, dir):
306     files = glob.glob(os.path.join(path, "*.ini"))
307     path = os.path.join(CURA_QUICKPRINT_DIR, machine_type)
308     for m in material_map.keys():
309         result = find_files_for_material(files, material_map[m])
310         for (file, material, profile) in result:
311             material = m
312             if file is None or material is None or profile is None:
313                 continue
314             filename = os.path.basename(file)
315             profile_file = os.path.join("..", "..", "..", PROFILES_DIR, dir, filename)
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, 'material.ini'), 'w') as f:
319                 f.write("[info]\n")
320                 f.write("name = %s\n" % material_names[material])
321                 order = material_order[material]
322                 if material_types.has_key(material):
323                     types = material_types[material]
324                     if (material == "HIPS_eSUN" and machine_type.startswith("lulzbot_mini")) or \
325                        (material == "ABS_VP" and machine_type.startswith("lulzbot_TAZ")):
326                         types = types + "|First Run"
327                         order = 0
328                     f.write("material_types = %s\n" % types)
329                 f.write("order = %d\n" % order)
330                 if material in bed_prep_materials:
331                     f.write("description = \
332                     Bed preparation required: \n\
333                     Apply a PVA-based glue stick \n\
334                     to bed surface before printing.\n")
335                 if material_url.has_key(material):
336                     referer = "?pk_campaign=software-cura"
337                     f.write("url = %s%s\n" %(material_url[material], referer) )
338             with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
339                 f.write("[info]\n")
340                 f.write("name = %s\n" % profile_map[profile])
341                 f.write("order = %d\n" % profile_order[profile])
342                 f.write("profile_file = %s\n" % profile_file)
343     for material in disable_materials.keys():
344         if os.path.exists(os.path.join(path, material)):
345             for profile in disable_materials[material]:
346                 if not os.path.exists(os.path.join(path, material, profile)):
347                     os.makedirs(os.path.join(path, material, profile))
348                     with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
349                         f.write("[info]\n")
350                         f.write("disabled = true\n")
351         else:
352             os.makedirs(os.path.join(path, material))
353             with open(os.path.join(path, material, 'material.ini'), 'w') as f:
354                 f.write("[info]\n")
355                 f.write("disabled = true\n")
356
357 def clear_quickprint_folders():
358     here = os.getcwd()
359     quickprint_path = os.path.join(here,CURA_QUICKPRINT_DIR)
360     candidates = os.listdir(quickprint_path)
361     
362     folder_paths = []
363     for candidate in candidates:
364         if "lulzbot_mini" in candidate or \
365            "lulzbot_TAZ" in candidate:
366             candidate_path = os.path.join(quickprint_path, candidate)
367             if os.path.isdir(candidate_path):
368                 folder_paths.append(candidate_path)
369     for path in folder_paths:
370         shutil.rmtree(path)
371     if not folder_paths:
372         print("No Quickprint folders to delete")
373     else:
374         print("Quickprint folders deleted")
375
376 def main():
377     if not os.path.exists(CURA_QUICKPRINT_DIR):
378         print "Cura path is wrong"
379         return -1
380
381     clear_quickprint_folders()
382
383     dirs = glob.glob(os.path.join(CURA_QUICKPRINT_DIR, PROFILES_DIR, "*"))
384  
385     for d in dirs:
386         dir = os.path.basename(d)
387         if dir_map.has_key(dir):
388             for machine_type in dir_map[dir]:
389                 create_machine_type(machine_type, d, dir)
390
391     print "Quickprint profiles regenerated"
392
393
394 if __name__ == '__main__':
395     main()