> Is this a good approach or is there a better way to do this ?
The following Perl script may help. It will array the modules and
tracks of a .brd file and, by default, increment the reference
designators for the components.
Try placing the amp section as sub-pages and create corresponding brd
file for the section. Then use the schematic editor's annotation tool
to renumber, which seems to stack the numbering in such a way that
the resulting netlist will match the module numbering in the output,
duplicated brd file.
---8<--- KDupe.pl ---8<------8<---
#!/usr/bin/perl
# KDupe
#
# Given a KiCad .brd file that contains a collection of components,
# produce a new .brd file with that collection duplicated to a
rectangular
# array with the reference designators incremented appropriately for
# each collection.
#
# Arguments: [input filename] [columns] [rows] [x-offset] [y-offset]
# Output is the input filename with a -blk appended to the base name.
#
# Example: perl dupe.pl test.brd 8 1 1 0
# duplicates the contents of test.brd 8 times in the x direction,
# each offset by 1 unit in the new file test-blk.brd.
#
# Example: perl dupe.pl test.brd 4 2 1 2
# places the contents of test.brd into a 4 column, 2 row array
# offset by 1 unit in the x direction, 2 in the y.
#
# Note: the "units" are based on the internal units found in the
# .brd file's $SETUP section.
#
# Note: The netlist section is passed through unchanged. Be sure to
# re-read the netlist upon opening the modified board file.
#
# Reference designators may start at an arbitrary value. Offset values
# in the duplicated components start at one greater than the highest
# value of that type in the base component.
# U1, U2, U3 -> U4, U5, U6 and U7, U8, U9 and so on ...
#
# Reference designators are assumed to be a single alpha character
# followed by a number consisting of one or more digits.
#
# A trailing "r" or "R" after the offset arguments indicates that
# the refrence designators should NOT be adjusted.
#
#
# KDupe is Copyright (C) 2007 Richard Webb
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
use warnings;
# For those who never read comments or who <ahem> forget the syntax
# after a while:
if ($#ARGV != 4 && $#ARGV != 5) {
print("Given a KiCad .brd file that contains a collection of
components,n");
print("produce a new .brd file with that collection duplicated to
a rectangularn");
print("array with the reference designators incremented
appropriately forn");
print("each collection.n");
print("nArguments: [input filename] [columns] [rows] [x-
offset] [y-offset] n");
print("Output is the input filename with a -blk appended to the
base name.n");
print("nExample: perl dupe.pl test.brd 8 1 1 0n");
print("duplicates the contents of test.brd 8 times in the x
direction,n");
print("each offset by 1 unit in the new file test-blk.brd.n");
print("nExample: perl dupe.pl test.brd 4 2 1 2n");
print("places the contents of test.brd into a 4 column, 2 row
arrayn");
print("offset by 1 unit in the x direction, 2 in the y.n");
print("nNote: the "units" are based on the internal units
found in then");
print(".brd file's $SETUP section.n");
print("n");
print("Note: The netlist section is passed through unchanged. Be
sure ton");
print("re-read the netlist upon opening the modified board
file.n");
print("nReference designators may start at an arbitrary value.
Offset valuesn");
print("in the duplicated components start at one greater than the
highestn");
print("value of that type in the base component.n");
print("U1, U2, U3 -> U4, U5, U6 and U7, U8, U9 and so on ...n");
print("nReference designators are assumed to be a single alpha
charactern");
print("followed by a number consisting of one or more
digits.nn");
print("A trailing "r" or "R" after the offset arguments
indicates thatn");
print("the refrence designators should NOT be adjusted.n");
exit;
}
open (IFILE, $ARGV[0]) or die "$ARGV[0]: $!";
$extpos = rindex($ARGV[0], ".brd");
if ($extpos == -1) {
printf("%s: not a .brd filen", $ARGV[0]);
exit();
}
$oname = substr($ARGV[0], 0, $extpos) . "-blk.brd";
open (OFILE, "> " . $oname) or die "$oname: $!";
$mod_count = 0;
$state = 0;
$cols = $ARGV[1];
$rows = $ARGV[2];
$xoff = $ARGV[3];
$yoff = $ARGV[4];
if ($#ARGV == 5 && ($ARGV[5] eq 'r' || $ARGV[5] eq 'R')) {
$adjust = 0;
} else {
$adjust = 1;
}
if ($cols <= 0 || $rows <= 0) {
printf("rows and cols must each be >= 1n");
exit;
}
while (<IFILE>) {
if (/^InternalUnit/) {
args = split(/ /);
$scale = $args[1];
}
if ($state == 0) {
# pre-module, so just copy input to output
if (/^$MODULE/) {
$state = 1;
} else {
printf(OFILE "%s", $_);
}
}
if ($state == 1) {
# handle the module section
if (/^$MODULE/) {
# save each module, keep track of the ref desigs
push
mods, ( $_ );
} elsif (/^$EndMODULE/) {
push
mods, ( $_ );
++$mod_count;
} elsif (/^$TRACK/) {
# Here is where the duplicate modules are created and
written
# to the output file.
# When we're done here, we'll do the tracks.
$modcount = 0;
for $r (0 .. $rows - 1) {
for $c (0 .. $cols - 1) {
$x_offset = $c * $xoff / $scale;
$y_offset = $r * $yoff / $scale;
$inmodule = 0;
foreach $m (
mods) {
if ($m =~ /^Po/) {
if ($inmodule == 0) {
$inmodule = 1;
args = split(/ /, $m);
$x = $args[1] + $x_offset;
$y = $args[2] + $y_offset;
printf(OFILE "%s %d %d %s %s %s %s
%s",
$args[0], $x, $y, $args[3],
$args[4],
$args[5], $args[6], $args[7]);
} else {
printf(OFILE "%s", $m);
}
} elsif ($m =~ /^T0/) {
if ($adjust) {
args = split(/"/, $m);
$aref = substr($args[1], 0, 1);
$adesig = substr($args[1], 1);
$adesig +=