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