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