Loop through clipboard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mruedar9
Posts: 1
Joined: 20 Oct 2018, 13:50

Loop through clipboard

20 Oct 2018, 14:07

Hi there,

I am developing a script that copies some data from an excel file, so they can be pasted in other program (Perform 3D)

I am having trouble with the function clipboard, because i have to clean the clipboard everytime I want to callback the last copied value. I want to know how can I loop through the last 5 values in the clipboard, and assign each one in a different cariable (a.k.a %path %dt %dur %skip %line). The goal is to make my code more short and efficient

Here is my script:
______________________________________________________________________________________________________________________-

Code: Select all

;;Define file names
;Perform file
IDP3D:=WinExist("PERFORM-3D V7.0.0 : LY-P10-DMI  ")
;Excel file
IDXLS:=WinExist("Far-field Records - Excel")
;Sleep Time. Recommended: 500 for remote conection, 250 average PC, 100 Fast PC
tsleep=100
;Records to Skip
offset=0
; Total number of records to add
nIM=44


;;;;;;Source Code
StartTime:=A_TickCount

;Prepare excel sheet 
WinActivate,ahk_id %IDXLS%
Send, {F5}
Send, A2
Send, {Enter}
Send, {Down %offset%}

loop, %nIM%
{
;;Excel: 
;Copy Folder Path
WinActivate,ahk_id %IDXLS%
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
path:=Clipboard
Send, {Tab}
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
;copy dt
dt:=Clipboard
Send, {Tab}
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
;copy dur
dur:=Clipboard
Send, {Tab}
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
;Copy skip
skip:=Clipboard
Send, {Tab}
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
;copy line
line:=Clipboard
Send, {Tab}
clipboard= ;
Send, {Ctrl Down}c{Ctrl Up}
ClipWait
;copy name
name:=Clipboard
Send, {Enter 2}
Sleep, %tsleep%

;;;Perform-3D: Paste Folder Path, the cursor should be in the folder path box
;Clear Input
WinActivate,ahk_id %IDP3D%
Send, {Home}
Send, {SHIFT Down}{End}{SHIFT Up}
Send, {DEL}
;Paste path
Send, %path%
;Clear Input
Send, {Tab 3}
Send, {Home}
Send, {SHIFT Down}{End}{SHIFT Up}
Send, {DEL}
;Paste dt
Send, %dt%
;Clear Input
Send, {Tab}
Send, {Home}
Send {SHIFT Down}{End}{SHIFT Up}
Send {DEL}
;Paste dur
Send, %dur%
;Clear Input
Send, {Tab 2}
Send, {Home}
Send {SHIFT Down}{End}{SHIFT Up}
Send {DEL}
;Paste # of lines to skip
Send, %skip%
;Clear Input
Send, {Tab}
Send, {Home}
Send {SHIFT Down}{End}{SHIFT Up}
Send {DEL}
;Paste acc values per line
Send, %line% 
;Clear Input
Send, {Tab 5}
Send, {Home}
Send {SHIFT Down}{End}{SHIFT Up}
Send {DEL}
;Paste File Name
Send, %name%
;Clear Input
Send, {Tab}
Send, {Home}
Send {SHIFT Down}{End}{SHIFT Up}
Send {DEL}
;Paste EQ Name
Send, %name%
;Check
Send, {Tab}
Send, {Enter}
;OK
Send, {Tab}
Send, {Enter}
;OK
WinActivate,"New Record Added"
Send,{Enter}
Sleep,  %tsleep%
}

Elapsed:= Round((A_TickCount -StartTime)/60000,1)
MsgBox, Elapsed Time %Elapsed% min
Esc::ExitApp
______________________________________________________
Thank you!!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Loop through clipboard

20 Oct 2018, 14:48

Code: Select all

;;Define file names
;Perform file
IDP3D:=WinExist("PERFORM-3D V7.0.0 : LY-P10-DMI ")
;Excel file
IDXLS:=WinExist("Far-field Records - Excel")
;Sleep Time. Recommended: 500 for remote conection, 250 average PC, 100 Fast PC
tsleep=100
;Records to Skip
offset=0
; Total number of records to add
nIM=44


;;;;;;Source Code
StartTime:=A_TickCount

;Prepare excel sheet 
WinActivate,ahk_id %IDXLS%
Send, {F5}
Send, A2
Send, {Enter}
Send, {Down %offset%}

loop, %nIM%
{
	;;Excel: 
	WinActivate,ahk_id %IDXLS%

	path := copyFromExcel(0)
	dt := copyFromExcel()
	dur := copyFromExcel()
	skip := copyFromExcel()
	line := copyFromExcel()
	name := copyFromExcel()

	Send, {Enter 2}
	Sleep, %tsleep%

	;;;Perform-3D: Paste Folder Path, the cursor should be in the folder path box
	WinActivate,ahk_id %IDP3D%
	clearThenSend(path, 0)
	clearThenSend(dt, 3)
	clearThenSend(dur)
	clearThenSend(skip, 2)
	clearThenSend(line)
	clearThenSend(name, 5)
	clearThenSend(name)

	Loop 2
		Send {Tab}{Enter}

	WinActivate,"New Record Added"
	Send,{Enter}
	Sleep, %tsleep%
}

Elapsed:= Round((A_TickCount -StartTime)/60000,1)
MsgBox, Elapsed Time %Elapsed% min
Esc::ExitApp

copyFromExcel(numTab := 1) {
	Send {Tab %numTab%}
	Clipboard := "" 
	Send {Ctrl Down}c{Ctrl Up}
	ClipWait
}

clearThenSend(msg, numTab := 1) {
	Send {Tab %numTab%}
	Send {Home}
	Send {Shift Down}{End}{Shift Up}
	Send {Del}
	Send % msg
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 248 guests