17
17
from easyeda2kicad .easyeda .parameters_easyeda import EeSymbol
18
18
from easyeda2kicad .helpers import (
19
19
add_component_in_symbol_lib_file ,
20
+ get_local_config ,
20
21
id_already_in_symbol_lib ,
21
22
set_logger ,
22
23
update_component_in_symbol_lib_file ,
@@ -66,7 +67,7 @@ def get_parser() -> argparse.ArgumentParser:
66
67
parser .add_argument (
67
68
"--output" ,
68
69
required = False ,
69
- metavar = "file.lib " ,
70
+ metavar = "file.kicad_sym " ,
70
71
help = "Output file" ,
71
72
type = str ,
72
73
)
@@ -88,6 +89,13 @@ def get_parser() -> argparse.ArgumentParser:
88
89
action = "store_true" ,
89
90
)
90
91
92
+ parser .add_argument (
93
+ "--project-relative" ,
94
+ required = False ,
95
+ help = "Sets the 3D file path stored relative to the project" ,
96
+ action = "store_true" ,
97
+ )
98
+
91
99
return parser
92
100
93
101
@@ -111,6 +119,16 @@ def valid_arguments(arguments: dict) -> bool:
111
119
kicad_version = KicadVersion .v5 if arguments .get ("v5" ) else KicadVersion .v6
112
120
arguments ["kicad_version" ] = kicad_version
113
121
122
+ if arguments ["project_relative" ] and not arguments ["output" ]:
123
+ logging .error (
124
+ "A project specific library path should be given with --output option when"
125
+ " using --project-relative option\n For example: easyeda2kicad"
126
+ " --lcsc_id=C2040 --full"
127
+ " --output=C:/Users/your_username/Documents/Kicad/6.0/projects/my_project"
128
+ " --project-relative"
129
+ )
130
+ return False
131
+
114
132
if arguments ["output" ]:
115
133
base_folder = "/" .join (arguments ["output" ].replace ("\\ " , "/" ).split ("/" )[:- 1 ])
116
134
lib_name = (
@@ -122,7 +140,7 @@ def valid_arguments(arguments: dict) -> bool:
122
140
)
123
141
124
142
if not os .path .isdir (base_folder ):
125
- logging .error ("Can't find the folder" )
143
+ logging .error (f "Can't find the folder : { base_folder } " )
126
144
return False
127
145
else :
128
146
default_folder = os .path .join (
@@ -208,6 +226,8 @@ def main(argv: List[str] = sys.argv[1:]) -> int:
208
226
if not valid_arguments (arguments = arguments ):
209
227
return 1
210
228
229
+ # conf = get_local_config()
230
+
211
231
component_id = arguments ["lcsc_id" ]
212
232
kicad_version = arguments ["kicad_version" ]
213
233
sym_lib_ext = "kicad_sym" if kicad_version == KicadVersion .v6 else "lib"
@@ -216,6 +236,11 @@ def main(argv: List[str] = sys.argv[1:]) -> int:
216
236
api = EasyedaApi ()
217
237
cad_data = api .get_cad_data_of_component (lcsc_id = component_id )
218
238
239
+ # API returned no data
240
+ if not cad_data :
241
+ logging .error (f"Failed to fetch data from EasyEDA API for part { component_id } " )
242
+ return 1
243
+
219
244
# ---------------- SYMBOL ----------------
220
245
if arguments ["symbol" ]:
221
246
importer = EasyedaSymbolImporter (easyeda_cp_cad_data = cad_data )
@@ -269,7 +294,8 @@ def main(argv: List[str] = sys.argv[1:]) -> int:
269
294
270
295
logging .info (f"Creating Kicad footprint library for LCSC id : { component_id } " )
271
296
ExporterFootprintKicad (footprint = easyeda_footprint ).export (
272
- output_path = arguments ["output" ]
297
+ output_path = arguments ["output" ],
298
+ is_project_relative = arguments ["project_relative" ],
273
299
)
274
300
275
301
# ---------------- 3D MODEL ----------------
0 commit comments