Spouštěcí skript pro prohlížeč ZofzPCB

ZofzPCB

Používám nějaký roky na prohlížení vygenerovaných gerber dat z návrhového sytému PCB  prohlížeč ZofzPCB: FREE 3D Gerber Viewer. Je to perfektní nástroj na optickou kontrolu a vizualizaci PCB ještě před samotnou výrobou. Mnohokrát mě zachránil od drobných estetických vad, třeba na potisku, které jsem v projektu návrhového systému neviděl. Návrhová pravidla již v gerber prohlížeči nekontroluji, neboť v samotném návrhovém systému Altium Designer jsou dost pokročilá a nikdy mě nezklamali.

Pro usnadnění práce s programem, hlavně opakované otevírání gerber dat jsem napsal skript v AutoHotkey. Program totiž nemá žádné klávesové zkratky na práci se soubory. Ve skriptu je uživatelsky definovaná cesta k gerber (CAM) souborům a další předvolby včetně barevného schématu aby se program nemusel již po každé instalaci znovu nastavovat. Stačí pouze kliknout na skript, který sám spustí prohlížeč, otevře přes klikací menu gerber (CAM) soubory a zobrazí ve 3D samotný plošný spoj. Potom po stisku klávesy Esc prohlížeč zavře. Jednoduché jako při kliknutí na asociovaný soubor obrázku.

 

 

/**
;  ****************************************************************************
;  * @file     ZofzPCB_AutoLoad.ahk
;  * @author   René Široký
;  * @company  WIDE SERVIS
;  * @version  V1.0.0
;  * @date     16.08.2018
;  * @compiler Auto Hot Key
;  * @brief    Script for automatic load of CAM files, custom color settings
;  *           and configuration for 3D Gerber Viewer ZofzPCB 
;  *
;  ****************************************************************************
;  */ 

;-------------- FUNCTIONS -----------------------------------------------------
/*****************************************************************************/
/**
  * @brief  set default color
  * @param  None
  * @retval None
  */
SetDefaultColor()
{
  RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_ColorPresetName, Net Color Haven
  RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_ColorPresetNum, 0
  RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, VolumeOpacity, 188
 }

;-------------- DIRECTIVES ----------------------------------------------------
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoTrayIcon ; Disable tray icon
; #Warn  ; Enable warnings to assist with detecting common errors.

;-------------- MAIN SCRIPT ENTRY ---------------------------------------------
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;==============================================================================
;** USER DEFINE - Uživatelské nastavení skriptu
; > Cesta k datovým CAM souborům <
UserDataCAMFolder = P:\PCB_designs\_GERBER-PRODUCTION

; > Název uživatelského barevného schématu, při nepoužití řádek zakomentovat <
UserColorPresetName = wiser-green
;==============================================================================

;** rename CAM file extension GM1 to GML
FileMove, %UserDataCAMFolder%\*.GM1, %UserDataCAMFolder%\*.GML

;** get the program directory path
RegRead, AppProgramFilesDir, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion, ProgramFilesDir (x86)
if (!AppProgramFilesDir)
{
  RegRead, AppProgramFilesDir, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion, ProgramFilesDir
}
  
;** check if the program is installed 
ZofzPCB_InstallFolder = \ZofzPCB\ZofzPCB\
ZofzPCB_EXEFile = Gerber3D.exe
FileGetAttrib, fileEXEAtt, %AppProgramFilesDir%%ZofzPCB_InstallFolder%%ZofzPCB_EXEFile%
if (!fileEXEAtt)
{
  MsgBox, 16, Error, ZofzPCB is not installed.
  return
}

;** store mouse cursor position
MouseGetPos, MousePosX, MousePosY

;** if exist variable "UserColorPresetName" (I want to use my color settings)
if UserColorPresetName
{
  RegRead, AppDataDir, HKEY_CURRENT_USER\Volatile Environment, APPDATA
  FileGetAttrib, fileColorAtt, %AppDataDir%\ZofzPCB\%UserColorPresetName%.color

  ;** check if exist user color file
  if (fileColorAtt)
  {
    ;** if exist, settings user color and board opacity
    RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_ColorPresetName, %UserColorPresetName%
    RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_ColorPresetNum, 0xFFFFFFFF
    RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, VolumeOpacity, 0xFF
  }
  else
  {
    ;** if not exist user color file
    RegRead, ColorPresetNum, HKEY_CURRENT_USER\Software\ZofzPCB\Gerber3D, g_ColorPresetNum

    ;** if setting not exist user color file
    if (ColorPresetNum == 0xFFFFFFFF)
    {
      ;** settings default color and board opacity
      SetDefaultColor()
    }
  }
}  
else
{
  ;** if not exist variable "UserColorPresetName" (I dont want to use my color settings)
  RegRead, ColorPresetNum, HKEY_CURRENT_USER\Software\ZofzPCB\Gerber3D, g_ColorPresetNum

  ;** if setting user color file
  if (ColorPresetNum == 0xFFFFFFFF)
  {
    ;** settings default color and board opacity
    SetDefaultColor()
  }
}

;** settings working data folder
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_CurentCAMFolder, %UserDataCAMFolder%
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_CurentProjFolder, %UserDataCAMFolder%
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_ScrShotFolder, %UserDataCAMFolder%

;** disable demo
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_DemoLevel, 3

;** disable hollow
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, g_EnableHollow, 0

;** disable automatic upgrade check
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, LastVersionInfoDay, 0

;** settings gerber file parameters
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefGrbIncremental, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefGrbOmitTrailingZeros, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefGrbMilimeters, 1
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefGrbLen1, 4
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefGrbLen2, 4

;** settings drill file parameters
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDGuess, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDIncremental, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDOmitTrailingZeros, 0
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDUnits, 1
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDlen1, 4
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_DefNCDlen2, 4
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, lg_ipcAutooffset, 1

;** settings window position (to fix the button coordinates)
RegWrite, REG_BINARY, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, CAMFilesAutoDlgPos, 0000000000000000
RegWrite, REG_BINARY, HKEY_CURRENT_USER, Software\ZofzPCB\Gerber3D, CAMFilesSimpDlgPos, 0000000000000000

;** run programm
Run %AppProgramFilesDir%%ZofzPCB_InstallFolder%%ZofzPCB_EXEFile%

;** wait for activate window
WinWait, ZofzPCB

;** settings maximize window
WinMaximize

;** open CAM files via menu....
Send {Click, 30, 35}
Send {Click, 60, 60}
Send {Click, 60, 80}
Send {Click, 670, 500}
Send {Click, 335, 620}

while WinExist() ;** loop running the program
{
  if GetKeyState("Esc") ;** when ESC is pressed, end the program
  {
    ;** settings maximize window (if it was not)
    WinMaximize
    
    ;** press Alt + F4
    Send !{F4}

    ;** calculates the position of the YES button in the confirmation window
    WinGetPos,,,, Height
    Height -= 265

    ;** click the YES button
    Send {Click, 460, %Height%}

    ;** wait at least 300ms to close the window
    Sleep, 300
  }

  if GetKeyState("XButton1") ;** when Mouse Button is pressed, press HOME keyboard
  {
    ;** press HOME
    Send {Home}
  }
}

;** restore mouse cursor position
MouseMove, %MousePosX%, %MousePosY%

return

ZofzPCB

Komentáře

Translate »