Last active
August 8, 2021 16:50
-
-
Save idt12312/ab038dd71863a20302c0b5a5366fbf7b to your computer and use it in GitHub Desktop.
This script is for KiCad. This renames leading reference number of selected components.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pcbnew | |
import re | |
def _get_selected_modules(): | |
modules = pcbnew.GetBoard().GetModules() | |
return filter(lambda m: m.IsSelected(), modules) | |
def _replace_leading_number(target, new): | |
match = re.search(r'[0-9]', target) | |
idx = match.start() | |
return target[:idx] + '{}'.format(new) + target[idx+1:] | |
def rename_leading_number_selected(new_number): | |
selected = _get_selected_modules() | |
for module in selected: | |
refdes = module.GetReference() | |
new_refdes = _replace_leading_number(refdes, new_number) | |
print('rename: ' + refdes + ' -> ' + new_refdes) | |
module.SetReference(new_refdes) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
In the above command, the leading reference number of selected components will be changed to 4.