chiark / gitweb /
45f3b2840f190577f0930bf6f3285725178106d9
[cura.git] / scripts / create_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, make sure there are no existing profiles
7 # by doing a rm -rf resources/quickprint/lulzbot_mini* resources/quickprint/lulzbot_TAZ*
8 # then run the script from the root Cura directory with ./scripts/create_lulzbot_profiles.py
9 #
10
11
12 import glob
13 import os
14 import sys
15
16
17 CURA_QUICKPRINT_DIR="resources/quickprint/"
18 PROFILES_DIR="lulzbot_profiles"
19
20 dir_map = {
21     'Mini_single_extruder_v2': ('lulzbot_mini',),
22     'Mini_flexystruder_v2': ('lulzbot_mini_flexystruder',),
23     'TAZ_single_extruder_0.35nozzle': ('lulzbot_TAZ_4_SingleV1',
24                                        'lulzbot_TAZ_5_SingleV1',
25                                        'lulzbot_TAZ_4_035nozzle',
26                                        'lulzbot_TAZ_5_035nozzle'),
27     'TAZ_single_extruder_0.5nozzle': ('lulzbot_TAZ_4_05nozzle',
28                                       'lulzbot_TAZ_5_05nozzle'),
29     'TAZ_dual_extruder_v1': ('lulzbot_TAZ_4_DualV1',
30                              'lulzbot_TAZ_5_DualV1'),
31     'TAZ_dual_extruder_v2': ('lulzbot_TAZ_4_DualV2',
32                              'lulzbot_TAZ_5_DualV2'),
33     'TAZ_flexystruder_v1': ('lulzbot_TAZ_4_FlexystruderV1',
34                             'lulzbot_TAZ_5_FlexystruderV1'),
35     'TAZ_flexystruder_v2': ('lulzbot_TAZ_4_FlexystruderV2',
36                             'lulzbot_TAZ_5_FlexystruderV2'),
37     'TAZ_flexy_dually_v1': ('lulzbot_TAZ_4_FlexyDuallyV1',
38                             'lulzbot_TAZ_5_FlexyDuallyV1'),
39     'TAZ_flexy_dually_v2': ('lulzbot_TAZ_4_FlexyDuallyV2',
40                             'lulzbot_TAZ_5_FlexyDuallyV2'),
41 }
42
43 material_map = {
44     'ABS': 'ABS',
45     'PLA': 'PLA',
46     'HIPS': 'HIPS',
47     'ninjaflex': 'NinjaFlex',
48     'semiflex': 'SemiFlex',
49     'ABS_ninjaflex': 'ABS & NinjaFlex',
50     'ABS_semiflex': 'ABS & SemiFlex',
51     'PLA_PVA': 'PLA & PVA',
52     'ABS_dual_color': 'ABS & ABS',
53     'PLA_dual_color': 'PLA & PLA',
54     'PLA_PVA_support': 'PLA & PVA',
55 }
56
57 material_order = {
58     'ABS': 2,
59     'PLA': 1,
60     'HIPS': 0,
61     'ninjaflex': 0,
62     'semiflex': 1,
63     'ABS_ninjaflex': 0,
64     'ABS_semiflex': 1,
65     'PLA_PVA': 2,
66     'ABS_dual_color': 0, 
67     'PLA_dual_color': 1,
68     'PLA_PVA_support': 2,
69 }
70
71 profile_map = {
72     'medium-quality': 'Standard',
73     'high-speed': 'High Speed',
74     'high-quality': 'High Detail',
75     #High Clarity
76     #High Strength
77 }
78
79 profile_order = {
80     'medium-quality': 0,
81     'high-quality': 2,
82     'high-speed': 1,
83 }
84
85 disable_materials = {
86     'PET': ('High', 'Low', 'Normal', 'Ulti'),
87     'PLA': ('High', 'Low', 'Normal', 'Ulti'),
88     'ABS': ('High', 'Low', 'Normal', 'Ulti')
89 }
90
91 def split_profile(filename):
92     material = None
93     profile = None
94     for m in material_map.keys():
95         if filename.startswith(m):
96             material = m
97             for p in profile_map.keys():
98                 if filename.startswith(m + "_" + p):
99                     profile = p
100                     return (material, profile)
101                     
102     return (material, profile)
103
104 def create_machine_type(machine_type, path, dir):
105     files = glob.glob(os.path.join(path, "*.ini"))
106     path = os.path.join(CURA_QUICKPRINT_DIR, machine_type)
107     for file in files:
108         filename = os.path.basename(file)
109         (material, profile) = split_profile(filename)
110         if material is None or profile is None:
111             continue
112         profile_file = os.path.join("..", "..", "..", PROFILES_DIR, dir, filename)
113         if not os.path.exists(os.path.join(path, material, profile)):
114             os.makedirs(os.path.join(path, material, profile))
115         with open(os.path.join(path, material, 'material.ini'), 'w') as f:
116             f.write("[info]\n")
117             f.write("name = %s\n" % material_map[material])
118             f.write("order = %d\n" % material_order[material])
119         with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
120             f.write("[info]\n")
121             f.write("name = %s\n" % profile_map[profile])
122             f.write("order = %d\n" % profile_order[profile])
123             f.write("profile_file = %s\n" % profile_file)
124     for material in disable_materials.keys():
125         if os.path.exists(os.path.join(path, material)):
126             for profile in disable_materials[material]:
127                 if not os.path.exists(os.path.join(path, material, profile)):
128                     os.makedirs(os.path.join(path, material, profile))
129                     with open(os.path.join(path, material, profile, 'profile.ini'), 'w') as f:
130                         f.write("[info]\n")
131                         f.write("disabled = true\n")
132         else:
133             os.makedirs(os.path.join(path, material))
134             with open(os.path.join(path, material, 'material.ini'), 'w') as f:
135                 f.write("[info]\n")
136                 f.write("disabled = true\n")
137                 
138
139 def main():
140     if not os.path.exists(CURA_QUICKPRINT_DIR):
141         print "Cura path is wrong"
142         return -1
143
144     dirs = glob.glob(os.path.join(CURA_QUICKPRINT_DIR, PROFILES_DIR, "*"))
145
146     for d in dirs:
147         dir = os.path.basename(d)
148         if dir_map.has_key(dir):
149             for machine_type in dir_map[dir]:
150                 create_machine_type(machine_type, d, dir)
151
152
153 if __name__ == '__main__':
154     main()