lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ conduit

Show off your RPG maps, campaigns, and tokens. Share your gaming experiences and stories under General Discussion and save this forum for things you've created that may help others run their own games. Use the subforums when appropriate.

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
evilC
Cave Troll
Posts: 49
Joined: Thu Mar 21, 2013 3:29 pm
Location: London, UK

lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ conduit

Post by evilC »

http://evilc.com/files/maptool/librpedit-ahk.zip

lib:RPEdit-AHK
by [email protected]
v1.1

a Notepad++ / RPEdit bridge using AutoHotkey

Features
========
* One-click save and load between Maptools and Notepad++
When you save from Notepad to Maptools it performs the following operations:
Copies text from notepad. Switches to maptools. Changes to the map with the token on and selects it. Opens RPEdit. Pastes code into RPEdit. Clicks save. Closes RPEdit, Switches back to original map, reselects original token selection, resets clipboard to original state
* Comments (/* */ and // ) are allowed inside notepad++ - they are stripped out as they are pasted into Maptools
* Preserves settings (Associations of notepad files to Maptool libraries) between sessions.


Requirements
============
Absolutely required, no easy workaround:
RPEdit: http://forums.rptools.net/viewtopic.php?f=46&t=16770
Autohotkey: http://www.autohotkey.com/
Partially required:
Notepad++: http://notepad-plus-plus.org/
It would be fairly trivial to hack the AHK script to use any editor.
Optional:
RPEdit Notepad++, to give you mt syntax highlighting etc: http://forums.rptools.net/viewtopic.php?t=13690

Installation
============
1) Install required software. See above. This includes installing RPEdit into Maptool
2) Drag libRpedit-AHK.rptok that came in this archive into the maptool window. Ideally place it next to the RPEdit token.
3) You should have a blue Edit Token macro button in your campaign pane from installing RPTool. Right click it and select Edit
4) In the top right of this window, set Hot Key to "Ctrl F3" and then click OK.
5) Click the Edit Token button in RPEdit, and when the window pops up, undock (Make it floating) and then close it.
6) The libRpedit-AHK.ahk file that came in this archive is the autohotkey script that executes keystrokes and mouse clicks to automate the bridge.
When you double click it, if you have AutoHotkey installed, you will see a green "H" icon in your system tray by the clock.
You can quit the macro by right-clicking the icon.
Please be aware that the AHK script creates a setting file in the same folder as it lives. If you wish to launch the macro from your desktop,
it is advised to keep it somewhere else and use a shortcut to the script on the desktop, so you do not accidentally delete the settings file.

Usage
=====
Controls:
F11 - "Load" from Maptools to Notepad. Note, this should be avoided if you wish to preserve comments (See below).
F12 - "Save" from Notepad to Maptools
F10 - Set File Association for the current tab open in Notepad++

DO NOT move the mouse or touch the keyboard until the macro finishes!

The conduit works by associating a Maptools text file (extension .mt) with a library inside Maptools.
It looks at the window title for notepad++ to find out the file name currently being edited.
It is therefore ESSENTIAL that the filename being edited ends in .mt
YOU DO NOT NEED TO SAVE THE .mt FILE IN NOTEPAD WHEN YOU "SAVE" IT TO MAPTOOLS - the "current" file just needs to end in .mt
So for example, start notepad, load or create an empty file, save it as "lib-mylib.mt".
Now hit F10, and a dialog will pop up.
Type in the name of the map (CaSe SenSiTive!) and the name of the library token that you wish to associate with this .mt file
eg for map, enter Grasslands, and if your lib token is lib:mylib, type in mylib
Now lib-mylib.mt in notepad is associated with lib:mylib on Grasslands.

Once set up, workflow is thus:
Ideally you should keep your "Master" copy as Notepad. Within notepad, you can use normal /* */ or // comments,
but when pasted from Notepad to Maptool, these are thrown away. If you wish to use comments, you must use Notepad as the master copy!
Do not worry, it is safe to create a new macro in MT by duplicating text inside the notepad window.

So, at the very beginning, when you create a new library, use F11 to load it into notepad.
Then hit F12 to "Save" the library into Maptools.

Do not worry about all the flashing boxes and moving cursors etc when you launch a macro. Just leave the keyboard and mouse alone until it stops.
The code is fairly robust, and communication is two-way. If there is a problem, Maptool will tell the macro, and it will either tell you or stop.
That's it!
Last edited by evilC on Thu Mar 28, 2013 2:31 pm, edited 2 times in total.

evilC
Cave Troll
Posts: 49
Joined: Thu Mar 21, 2013 3:29 pm
Location: London, UK

Re: lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ cond

Post by evilC »

reserved


User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ cond

Post by CoveredInFish »

This is surely a cool thing, cool project!, too sad its windows only. First I've lost notepad++, now this. Sigh.
Maybe it would be cool to mark that limitation in the topic.

evilC
Cave Troll
Posts: 49
Joined: Thu Mar 21, 2013 3:29 pm
Location: London, UK

Re: lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ cond

Post by evilC »

Well there is nothing inherently windows about it really.
Sure, you can only get AHK on windows, but the script is very simple and could easily be written in something else.

The "secret sauce" lies in the maptool library. When it pops open a dialog to request information from the AHK script, after AHK pastes in the data, the library opens another input box with the "return value" as the default value in the text box. That way, the maptool library can confirm whether operations requested by the AHK script were successful.

So my script hits CTRL-F1 to trigger a MT macro, this pops open a window with a textbox to enter the name of the library token to select, AHK pastes in "lib:somelib", the MT macro tries to select that token and if it succeeds it pops up another dialog with the text "token found" in it. AHK then copies the text into the clipboard, reads it, and knows the token select was successful.

So all you need is a macro language that can hit keys, read the clipboard contents, move the mouse and read the title of windows. Oh and it should be able to read and write to settings files.
As long as you have a macro language that can do that, this is possible using any OS and any editor.

evilC
Cave Troll
Posts: 49
Joined: Thu Mar 21, 2013 3:29 pm
Location: London, UK

Re: lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ cond

Post by evilC »

Also, is the bit about the notepad file needing to end in .mt, but not needing to be saved clear?
Quite hard to explain the concept.

Also, if anyone else could try this and let me know how it goes, I would be grateful. There is a lot of timing involved in the script and I am not sure how it would run on a not-so-beefy PC.
If you need to tweak timings, in the source of the AHK script, the sd() (Short delay) and ld() (long delay) functions are used quite a lot - so it would be a simple first step to alter the delays in there.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: lib:RPEdit-AHK - An automated RPEdit <--> Notepad++ cond

Post by CoveredInFish »

I might try to transfer that concept to macOS (i guess automator should be sufficient for that) so thanks for the explanation. I fear, I wont find the time to do so soon, well, we'll see ...

Post Reply

Return to “User Creations”