Scripting with Autohotkey and Paste Special

Discussion in 'Mapping Questions & Discussion' started by Grup, Apr 4, 2010.

  1. Grup

    Grup L1: Registered

    Messages:
    19
    Positive Ratings:
    1
    Note: No guarantees w/ this method either written or implied. I suggest trying this method out w/ a copy of your map before using it on the real thing.

    I've written an AutoHotKey script that helps me to make rotationally symmetric maps. If there is a better way to do this without using autohotkey, then let me know.

    I think the neat thing about this script is that it figures out where the currently selected objects are and derives new numbers based on those numbers. Possibly this can be applied to other situations.

    This is what it does:
    1. figures out where your currently selected objects are (by looking at text in the status bar),
    2. copies those value onto the clipboard,
    3. brings up the paste special dialog,
    4. enters x and y offsets from the original and rotates the object 180 degrees.

    I understand that in general it is nice to do a full half side of the map, and then rotate the whole thing 180 degrees, however, sometimes I like this approach for touch ups.

    So, in order to do this yourself at home, install http://www.autohotkey.com/

    then create a file, with a .ahk extension and paste in this text:

    Code:
    ^+m:: ;control shift m
    ; copy the selected object
    SendInput ^c
    ; get the status bar text that has the selected object coordinates (A means the active window)
    StatusBarGetText, SB, 4, A
    ; Find the first numbers (the x coordinate) and the second numbers (y coordinate) after the left parenthesis
    RegExMatch(SB,"\((-?[0-9]+) (-?[0-9]+)", pattern)
    X := pattern1
    Y := pattern2
    ; At this point X and Y have the coordinates of the selected objects.
    ; Note that Paste Special pastes using offsets from the original 
    ; So, 0-X would offset the new copy at the origin, and 0-X-X puts the new copy on the other side of the origin.
    X := 0-X-X
    Y := 0-Y-Y
    ; this makes the mouse click the edit menu (possibly you'll have to fiddle w/ these numbers?)
    click 78, 39
    ; this makes the mouse click the paste special menu item (possibly you'll have to fiddle w/ these numbers?)
    click 137, 247
    ; plug in the values
    SendInput 1
    SendInput {tab}{tab}{tab}
    SendInput %X%{tab}{tab}%Y%{tab}{tab}0{tab}{tab}
    SendInput 0{tab}0{tab}180
    
    Then run the ahk file to activate the hot key/script. Note that this will load the script in to memory and only needs to be run once (until you restart the computer or close the script). I start it up as soon as I start up my first Hammer session.

    Select the object that you want to copy.

    If you have a number of objects that you want to handle at the same time, you probably have to group them. And actually there are some subtleties (bugs?) here with hammer. Among other issues, it seems you can't group brushes w/ non brushes (or even if you can, it doesn't work as I expect with paste special).

    Then press control-shift-M.

    This brings up the paste special dialog and plugs in the important numeric values. It doesn't touch the checkboxes. I'm sure that can be done w/ autohotkey, but I haven't put any effort in to figuring that out. You need that first checkbox (start at center of original) checked in order for this to work.

    And then after the paste special dialog is up, with all the new values, press enter to actually do the pasting. That could be automated as well, by adding the following line to the script:

    Code:
    SendInput {Enter}
    However, I'm leaving that out for now and until such time, if ever, I enhance the script to make sure those checkboxes are checked.

    And if you include the above line, you might also add the following (control shift e) to move the 3d display to center on the new object:

    Code:
    SendInput ^+e
    One more thing, the script brings up the Paste Special dialog by using automated mouse clicks. It is possible that due to some display settings, that the click coordinates are not correct for your display, so these might need adjusting. If this is causing problems for you, there is a utility that comes w/ autohotkey called AutoIt3 Window Spy that can help you figure out the correct coordinates. If you do change the script, you need to right click on the icon in the system tray and select "Reload This Script", in order for it to pick up your changes.

    Happy to hear any feedback anyone might have regarding this.
     
    Last edited: Apr 8, 2010
  2. TheTurnip

    TheTurnip L2: Junior Member

    Messages:
    62
    Positive Ratings:
    20
    Maybe it's just me being a mapping newbie, but how is this different than just copy/pasting and rotating 180 degrees half your map?
     
  3. Tehrasha

    Tehrasha L3: Member

    Messages:
    115
    Positive Ratings:
    26
    I may be wrong, but I believe this method will work on things like overlays which do not reorient properly with a select_all/copy/paste/rotate.
     
  4. Grup

    Grup L1: Registered

    Messages:
    19
    Positive Ratings:
    1
    Ok, this is how I'm using it:

    I start with a rotationally symmetric map.

    Let's say however, that I want to just add a new wall somewhere.

    I could just add that wall in one half of the map, delete the other half, and then copy and paste and rotate the whole map 180 degrees, find and replace all textures, relink up entities correctly, etc. or

    I can use my handy dandy script and just select that new wall, group the brushes in the wall, and press ctrl-shift-M, and I'm done. (well I might need to change textures).

    So it is a matter of convenience. Again, I'm not suggesting you create a whole map this way, but when I want to make minor modifications, I find this to be much more convenient.

    Now, hopefully this doesn't need to be said, as it should be obvious, but if this is not something that you are going to be doing repeatedly, then it doesn't make sense to use my script.

    If you need to do the same thing but don't want to invest time installing autohotkey and my script, then you can just do what the script does by hand (and you can of course do the calculations in your head or by using a calculator).
     
    Last edited: Apr 8, 2010