A handy batch file for Altium (Or other pcb design programs) users.

May 11, 2008
19,306
1,131
126
I made this handy dandy batch file with the help of a lot of googling.
It automates a lot of tasks that need to be done manually.
It asks for a filename for the zip file and how many layers.
Currently i has obly 2 ,4 or 6 layers options but that can be easily expanded.
It renames the gerber files to a format more easy readable.
It renames the files according to how we at work have our naming convetion for the layer stack.
After that, it copies the NC drill files to the gerber directory.
It then calls 7z.exe to archive everything into a zip file which has the name given by the user.

Code:
:: Things to do when 7z.exe is not found by batchfile.
:: install 7zip compression /decompression utility 7zip.
:: copy 7z.exe to system32 folder of windows.
:: Done.

@ECHO OFF

:: Turn the below echo on to enable debug messages.
:: @ECHO ON

CLS
ECHO gerber rename and package utility by William.  V1.00
set /p gerbername=Typ the desired output zipfile name and press Enter:
ECHO Select the amount of copper layers of the board and press Enter.
ECHO 2. 2 layer board.
ECHO 4. 4 layer board.
ECHO 6. 6 layer board.
ECHO.


set /p a=Type option:

IF %a%==6 GOTO 6layer_setup
IF %a%==4 GOTO 4layer_setup
IF %a%==2 GOTO 2layer_setup
GOTO End


:2layer_setup
ECHO 2 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "2_BOT2_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..
GOTO End



:4layer_setup
ECHO 4 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.G1) DO REN "%%~fA" "2_IN2_%%~nA.*"
FOR %%A IN (*.G2) DO REN "%%~fA" "3_IN3_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "4_BOT4_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..
GOTO End



:6layer_setup
ECHO 6 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.G1) DO REN "%%~fA" "2_IN2_%%~nA.*"
FOR %%A IN (*.G2) DO REN "%%~fA" "3_IN3_%%~nA.*"
FOR %%A IN (*.G3) DO REN "%%~fA" "4_IN4_%%~nA.*"
FOR %%A IN (*.G4) DO REN "%%~fA" "5_IN5_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "6_BOT6_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..


:End
@ECHO ...
:: Display path
:: ECHO %0
set filepath=%~dp0
:: ECHO %filepath%
set sourcepath=%filepath%NC Drill
set destinationpath=%filepath%Gerber
ECHO sourcepath=%sourcepath%
ECHO destinationpath=%destinationpath%
@ECHO ...
xcopy "%sourcepath%" "%destinationpath%"  /f /y

set zippath=%filepath%Gerber\*.*
set gerberzipfilename=%gerbername%.zip
::ECHO %gerbername%
@ECHO ...
ECHO filename=%gerberzipfilename%
ECHO source files path=%zippath%
@ECHO ...
7z a %gerberzipfilename% "%zippath%"

CHOICE /C Q /M "Press Q to quit"
 
May 11, 2008
19,306
1,131
126
As always, there is room for further improvement. So here is V2.00
This version also provides the option to delete the old files from the Gerber and NC Drill directory after zipping to prevent keeping old files.

Code:
:: Things to do when 7z.exe is not found by batchfile.
:: install 7zip compression /decompression utility.
:: copy 7z.exe to system32 folder of windows.
:: Done.

@ECHO OFF

:: Turn the below echo on to enable debug messages.
:: @ECHO ON

CLS
ECHO gerber rename and package utility by William. V2.00.
set /p gerbername=Typ the desired output zipfile name and press Enter:
ECHO Select the amount of copper layers of the board and press Enter.
ECHO 2. 2 layer board.
ECHO 4. 4 layer board.
ECHO 6. 6 layer board.
ECHO.


set /p a=Type option:

IF %a%==6 GOTO 6layer_setup
IF %a%==4 GOTO 4layer_setup
IF %a%==2 GOTO 2layer_setup
GOTO End


:2layer_setup
ECHO 2 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "2_BOT2_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..
GOTO Zipfile



:4layer_setup
ECHO 4 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.G1) DO REN "%%~fA" "2_IN2_%%~nA.*"
FOR %%A IN (*.G2) DO REN "%%~fA" "3_IN3_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "4_BOT4_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..
GOTO Zipfile



:6layer_setup
ECHO 6 layer stack selected.
cd Gerber
FOR %%A IN (*.GTL) DO REN "%%~fA" "1_TOP1_%%~nA.*"
FOR %%A IN (*.G1) DO REN "%%~fA" "2_IN2_%%~nA.*"
FOR %%A IN (*.G2) DO REN "%%~fA" "3_IN3_%%~nA.*"
FOR %%A IN (*.G3) DO REN "%%~fA" "4_IN4_%%~nA.*"
FOR %%A IN (*.G4) DO REN "%%~fA" "5_IN5_%%~nA.*"
FOR %%A IN (*.GBL) DO REN "%%~fA" "6_BOT6_%%~nA.*"
FOR %%A IN (*.GBO) DO REN "%%~fA" "BOTTOM_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTO) DO REN "%%~fA" "TOP_SILKSCREEN_LEGEND_%%~nA.*"
FOR %%A IN (*.GTS) DO REN "%%~fA" "TOP_SOLDERMASK_%%~nA.*"
FOR %%A IN (*.GBS) DO REN "%%~fA" "BOTTOM_SOLDERMASK_%%~nA.*"
cd..


:Zipfile
@ECHO ...
:: Display path
:: ECHO %0
set filepath=%~dp0
:: ECHO %filepath%
set sourcepath=%filepath%NC Drill
set destinationpath=%filepath%Gerber
ECHO sourcepath=%sourcepath%
ECHO destinationpath=%destinationpath%
@ECHO ...
xcopy "%sourcepath%" "%destinationpath%"  /f /y

set zippath=%filepath%Gerber\*.*
set gerberzipfilename=%gerbername%.zip
::ECHO %gerbername%
@ECHO ...
ECHO filename=%gerberzipfilename%
ECHO source files path=%zippath%
@ECHO ...
7z a %gerberzipfilename% "%zippath%"


ECHO ...
CHOICE /M "Do you wish to delete the files ? [Y/N]"
IF ERRORLEVEL 2 GOTO End

ECHO ...
ECHO Deleting files from directory "NC Drill" ...
cd NC Drill
del *.*
cd..
ECHO Deleting files from directory "Gerber" ...
cd Gerber
del *.*
cd..

:End
CHOICE /C Q /M "Press Q to quit"