Skip to content

Commit 0e06aaa

Browse files
authored
Schematic import multiline value support (#390)
Hacked in by concatenating Value2, Value3, ... fields if they exist. Fields must start at Value2 and be contiguous. This should allow better-looking schematic-defined blocks with more complex logic.
1 parent 2fa08c8 commit 0e06aaa

File tree

5 files changed

+1251
-220
lines changed

5 files changed

+1251
-220
lines changed

edg/electronics_model/KiCadSchematicBlock.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ def import_kicad(self, filepath: str, locals: Mapping[str, Any] = {},
197197
assert isinstance(block, KiCadImportableBlock), f"{symbol.refdes} not a KiCadImportableBlock"
198198
elif symbol.properties['Value'].startswith('#'): # sub-block with inline Python in the value
199199
inline_code = symbol.properties['Value'][1:]
200+
201+
value_suffixes = [int(name[5:]) for name in symbol.properties.keys()
202+
if name.startswith('Value') and len(name) > 5]
203+
if len(value_suffixes): # support fake-multiline values with Value2, Value3, ...
204+
assert min(value_suffixes) == 2, "additional Values must start at 2"
205+
max_value = max(value_suffixes)
206+
for suffix in range(2, max_value + 1): # starts at Value2
207+
assert f'Value{suffix}' in symbol.properties, f"missing Value{suffix} of Value{max_value}"
208+
inline_code += '\n' + symbol.properties[f'Value{suffix}']
209+
200210
# use the caller's globals, since this needs to reflect the caller's imports
201211
block_model = eval(inline_code, inspect.stack()[1][0].f_globals, locals)
202212
assert isinstance(block_model, KiCadImportableBlock),\

0 commit comments

Comments
 (0)