Input CSV coordinates into dialog box

Get help with using AutoHotkey and its commands and hotkeys
DRoam
Posts: 2
Joined: 14 Nov 2017, 12:11

Input CSV coordinates into dialog box

Post by DRoam » 14 Nov 2017, 12:31

I'm using an analysis software for my job that allows me to input several XYZ coordinates. Problem is, it only allows me to input them one at a time and it has no import feature. So I have to manually type in the same 40+ XYZ coordinates every time I do my setup.

I'd like to just type up a .txt file with CSV coordinates and use AutoHotkey to read from the CSV file and input the coordinates for me. Here's the basic setup:

CSV file:
(General format: Label,XCoord,YCoord,ZCoord)
Example:
[Line #] Line contents
[1] Inlet, 7.5,0,1.73
[2] Outlet, 14.5,0,1.73
[3] Zone 1, 12,0,1.73
etc.

Input steps (what I need AHK to do in the dialog box):
1. Type in XCoord, [Tab]
2. Type in YCoord, [Tab]
3. Type in ZCoord, [Tab]
4. Type in Label, [Enter]
5. [Shift+Tab] x 3
6. Repeat for each line in CSV file

I have no experience in AutoHotkey whatsoever, and it would take me a lot more time to figure out how to do this than I have right now. I was hoping someone who has time on their hands and enjoys using AHK would be willing to get this set up for me, or at least get me started. I'm willing to put in as much work myself as time allows, but any help you can provide to get me closer to a working script would be greatly appreciated.

Thank you.
Guest

Re: Input CSV coordinates into dialog box

Post by Guest » 14 Nov 2017, 12:49

Your psuedo code is half your script, you only need to wrap it in a loop and read the data. Below is a script that should work, try it with say two rows of CSV.
If you script goes haywire press Esc should stop it. You may get a lot better results if you can use ControlSend, right click on the AutoHotkey try icon to start the window spy to find the control names and try a small script - just one line to see if you can use ControlSend, that way your data is always sent to the correct field.
https://autohotkey.com/docs/commands/ControlSend.htm The Spy should show you an ClassNN which is what you use in the 'control' parameter, the keys are the 'cells' below to send. That way you don't have to rely on tabs to navigate and quite possibly your program doesn't have to be active either to be able to input the data.

Also start with the https://autohotkey.com/docs/Tutorial.htm to get an idea of the basics and read the documentation for each command/function below.

Code: Select all

FileDelete, testcsv.csv
FileAppend,
(join`r`n
Inlet, 7.5,0,1.73
Outlet,14.5,0,1.73
), testcsv.csv

; --------- just comment or remove the above

#z:: ; press Winkey-z to start ; you may wish to add a 

; WinActive, ahk_exe yourprogram.exe ; this will ensure your window is active

FileRead, MyCSV, testcsv.csv ; read the file

Loop, parse, MyCSV, `n, `r
	{
	 ; if (A_Index = 1) or (A_LoopField = "") ; uncomment these two lines if your file has a HEADER line and EMPTY lines
	 ;	continue                              ; if not you can leave them commented
	 Cells:=StrSplit(A_LoopField,",") ; this will only work with simple CSV files, if there are "" in the labels or Cells it won't work
	 Send % Cells[2] "{tab}"
	 Send % Cells[3] "{tab}"
	 Send % Cells[4] "{tab}"
	 Send % Cells[1] "{enter}"
	 Send {shift}{tab}
	 Send {shift}{tab}
	 Send {shift}{tab}
	 Sleep 100
	}
Return

Esc::ExitApp

DRoam
Posts: 2
Joined: 14 Nov 2017, 12:11

Re: Input CSV coordinates into dialog box

Post by DRoam » 14 Nov 2017, 15:10

You're a lifesaver. That was just the starting point I needed. I was able to play with that code and get it to do just what I needed. This will save me so much time. Thank you!
Post Reply

Return to “Ask For Help”