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