Skip to content

Instantly share code, notes, and snippets.

@heri16
Last active September 22, 2017 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heri16/58f74a078c66d8181fd6f60d7347b25c to your computer and use it in GitHub Desktop.
Save heri16/58f74a078c66d8181fd6f60d7347b25c to your computer and use it in GitHub Desktop.
AutoHotKey Helper Tool to Automate printing labels of multiple items in RENE Admin. Usage: Clipboard -> Alt+v
#NoEnv
#UseHook off
#KeyHistory 0
#SingleInstance force
SetBatchLines, -1
SetTitleMatchMode, 3
GroupAdd, wGroup, ahk_class TfrmDialog ahk_exe reneadmin.exe
GroupAdd, wGroup, ahk_class TfrmItemSearch ahk_exe reneadmin.exe
Hotkey, IfWinActive, ahk_class TfrmMain ahk_exe reneadmin.exe
Hotkey, !v, HotkeyAutoInputRows
;WinWait, ahk_exe reneadmin.exe
;WinWaitClose, ahk_exe reneadmin.exe
;MsgBox "RENE Admin Exited."
;ExitApp
Return
HotkeyAutoInputRows:
if clipboard {
mainHwnd := WinExist("ahk_class TfrmMain ahk_exe reneadmin.exe")
rowArray := StrSplit(clipboard, "`n", " `r")
AutoInputForm(rowArray, mainHwnd)
}
Return
AutoInputForm(rowArray, mainHwnd)
{
ControlGet, formControlHwnd, Hwnd,, TfrmPrintTag1, ahk_id %mainHwnd%
if ErrorLevel {
MsgBox, 16, Error, Silakan membuka Layar "Cetak Label" di RENE Admin, dan memilih tipe Label (Price Tag / Rack Tag). Sebelum mencoba kembali.
Return
}
popupControlHwnd := ClearAndActivateItemFilter(formControlHwnd)
for index, thisRow in rowArray
{
if (thisRow != "") {
; Find & remove duplicates
dupCount := 0
for i, eachRow in rowArray
{
if (eachRow == thisRow) {
rowArray[i] := ""
dupCount++
}
}
ControlSend, TtiCpxReneDetailEdit1, %thisRow%{Enter}, ahk_id %popupControlHwnd%
; Wait for text to be accepted by RENE
Loop
{
ControlGetText, EditControlText, TtiCpxReneDetailEdit1, ahk_id %popupControlHwnd%
if (EditControlText == "") {
; Text has been accepted
;Sleep, 100
; Detect Item Duplicated Popup
if WinExist("ahk_class TfrmDialog ahk_exe reneadmin.exe") {
WinClose
} else if (dupCount > 1) {
ControlSend, TtiInternalVirtualTree1, {End}%dupCount%, ahk_id %popupControlHwnd%
ControlSend, TtiVTEdit1, {Enter}, ahk_id %popupControlHwnd%
}
Break
} else {
; Detect Item Not Found or Item Search Popup
WinWait, ahk_group wGroup,, 0.2
if !ErrorLevel {
WinGetClass, wClass
if (wClass == "TfrmDialog") {
ControlSend, ahk_parent, {Enter}
WinWaitClose
ControlSend, TtiCpxReneDetailEdit1, {Esc}, ahk_id %popupControlHwnd%
} else if (wClass == "TfrmItemSearch") {
ControlSend,, {Esc}
WinWaitClose
ControlSend, TtiCpxReneDetailEdit1, {Esc}, ahk_id %popupControlHwnd%
}
}
}
}
; Maximum 10 Item
if Mod(index, 10) == 0 {
ApplyItemFilter(formControlHwnd, popupControlHwnd)
PreviewAndPrint(formControlHwnd)
MsgBox, 4100, RENE Cetak Label, Apa ingin Lanjut Cetak Label yang tersisa?
IfMsgBox, No
Return
popupControlHwnd := ClearAndActivateItemFilter(formControlHwnd)
}
}
}
ApplyItemFilter(formControlHwnd, popupControlHwnd)
PreviewAndPrint(formControlHwnd)
}
PreviewAndPrint(formControlHwnd)
{
SetKeyDelay,, 10
; -- PREVIEW --
ControlMove, TfrxPreview1, 200, 200,,, ahk_id %formControlHwnd%
Loop
{
; Tampilkan
ControlSend, ahk_parent, {Alt Down}m{Alt Up}, ahk_id %formControlHwnd%
; Check Preview has refreshed
ControlGetPos, X, Y, Width, Height, TfrxPreview1, ahk_id %formControlHwnd%
if (!ErrorLevel && X == 200 && Y == 200) {
Sleep, 100
} else {
Sleep, 3000
Break
}
}
; -- PRINT --
Loop
{
; Cetak
ControlSend, ahk_parent, {Alt Down}c{Alt Up}, ahk_id %formControlHwnd%
; Wait for Print Window
WinWait, ahk_class TfrxPrintDialog ahk_exe reneadmin.exe,, 1
if !ErrorLevel {
Break
}
}
MsgBox, 4097, RENE Cetak Label, Siap untuk di print? (Mohon cek setingan printer sudah benar.)
WinActivate
IfMsgBox, OK
ControlSend, TButton3, {Space}
IfMsgBox, Cancel
ControlSend, TButton2, {Space}
SetKeyDelay,, -1
}
ClearAndActivateItemFilter(formControlHwnd)
{
popupControlHwnd := ActivateItemFilter(formControlHwnd)
Loop
{
; Clear All Items
ControlClick, X380 Y75, ahk_id %popupControlHwnd%
; Wait for Clear All Dialog
WinWait, ahk_class TfrmDialog ahk_exe reneadmin.exe,, 1
if !ErrorLevel {
Break
}
}
ControlSend, ahk_parent, {Enter}
Return popupControlHwnd
}
ActivateItemFilter(formControlHwnd)
{
; Filter Lanjutan
ControlClick, X200 Y150, ahk_id %formControlHwnd%
; Wait for popup to become visible
Loop
{
ControlGet, isControlVisible, Visible,, TAdvSmoothPanel5, ahk_id %formControlHwnd%
if (!ErrorLevel && !isControlVisible) {
Sleep, 100
} else {
Break
}
}
; Berapa Barang Saja
ControlGet, popupControlHwnd, Hwnd,, TAdvSmoothPanel5, ahk_id %formControlHwnd%
ControlSend, TAdvOfficeRadioButton1, {Space}, ahk_id %popupControlHwnd%
Return popupControlHwnd
}
ApplyItemFilter(formControlHwnd, popupControlHwnd)
{
; OK
ControlClick, X460 Y330, ahk_id %popupControlHwnd%
; Wait for Popup to be hidden
Loop
{
ControlGet, isControlVisible, Visible,, TAdvSmoothPanel5, ahk_id %formControlHwnd%
if (!ErrorLevel && isControlVisible) {
Sleep, 100
} else {
Break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment