PDA

View Full Version : AutoHotKey scripts



truevis
2008-07-30, 12:17 PM
I've been finding AutoHotKey (http://www.autohotkey.com)(AHK) excellent for automating repetitive Revit tasks. I'm going to share some of the scripts I've been using for my consulting work.

Writing an AHK script usually starts with using AutoScriptWriter II that comes with the AHK install. I go through the motions of the task I want to automate and it records some of the things I did. I then paste that text into my text editor (I'm liking PSPad (http://www.pspad.com).).

Things like mouse clicks obviously depend on one's screen resolution. There is a function to find a bitmap onscreen (to click on) but I haven't needed that yet.

When I'm recording I use the keyboard as much as possible. E.g.: Alt-Enter = Element Properties.

Reading the AHK help file obviously helps.

These lines go at the top of the AHK file:
#SingleInstance force
SetBatchLines, 10ms ; Slows the script down to 10ms per line, helps prevent it going to fast for Revit to handle

Here's a script where I select a solid in the family editor, hit F7, and it sets the solid's material to a new parameter called "Material". I had to do it for many families and each F7 saves me many keystrokes. The "MouseClick" line would have to be modified depending on one's screen size.



F7:: ; hotkey for adding Material parameter to solid
WinWait, Revit
WinWaitActive, Revit
Sleep, 100
Send, {ALTDOWN}{ENTER}{ALTUP}
WinWait, Element Properties, Instance Parameters
IfWinNotActive, Element Properties, Instance Parameters , WinActivate, Element Properties, Instance Parameters
WinWaitActive, Element Properties, Instance Parameters
MouseClick, left, 411, 430
Sleep, 100
WinWait, Associate Family Parameter, &Existing family par
IfWinNotActive, Associate Family Parameter, &Existing family par, WinActivate, Associate Family Parameter, &Existing family par
WinWaitActive, Associate Family Parameter, &Existing family par
Send, {ALTDOWN}d{ALTUP}
WinWait, Parameter Properties, (Cannot appear in sc
IfWinNotActive, Parameter Properties, (Cannot appear in sc, WinActivate, Parameter Properties, (Cannot appear in sc
WinWaitActive, Parameter Properties, (Cannot appear in sc
Send, Material{TAB}m{ENTER}{ENTER}{ENTER}
return

truevis
2008-07-30, 12:25 PM
Here's a script that makes F3 do a Purge Unused:

F3:: ; hotkey Purge Unused
#Persistent
ToolTip, Purging Unused...
SetTimer, RemoveToolTip, 1500
WinWait, Revit
IfWinNotActive, Revit
WinWaitActive, Revit
Sleep, 100
Send, !fuu{ENTER}{ENTER}
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

truevis
2008-07-30, 12:35 PM
This script maps F5 to do a Save As to a filename that's been copied to the Windows clipboard first. It also sets some options. I've been using it because I have a list of families to make, and often one is based on another. Thus, a quick Save As is the first step.


F5:: ; hotkey
WinWait, Revit
IfWinNotActive, Revit
WinWaitActive, Revit
ClipWait
MsgBox, 4, , %clipboard% `nDo you want to continue? (Press YES or NO)
IfMsgBox No
return
Sleep, 100
Send, !fa
WinWait, Save As, Previous folder(Alt+
IfWinNotActive, Save As, Previous folder(Alt+, WinActivate, Save As, Previous folder(Alt+
WinWaitActive, Save As, Previous folder(Alt+
Sleep, 100
Send, ^v!p
WinWait, File Save Options, &Make this a Central
IfWinNotActive, File Save Options, &Make this a Central, WinActivate, File Save Options, &Make this a Central
WinWaitActive, File Save Options, &Make this a Central
Sleep, 200
Send, !g
Sleep, 200
Send, {ENTER}
WinWait, Save As, Previous folder(Alt+
IfWinNotActive, Save As, Previous folder(Alt+, WinActivate, Save As, Previous folder(Alt+
WinWaitActive, Save As, Previous folder(Alt+
Sleep, 100
Send, !s
return

david.kingham
2008-07-30, 02:13 PM
Here's one I put together using the ImageSearch function.
Creates shortcuts for the Filter button (Win + 1) Finish Sketch (Win + 2) and Quit Sketch (Win + 3)
Images I used are attached too, I had to crop them down pretty small because they have a transparency, so if you got the area around the icon it wouldn't work on some computers because the background color may be different


SetTitleMatchMode 2
#IfWinActive Revit Architecture 2009
WinGetPos RevitX, RevitY, RevitWidth, RevitHeight, Revit Architecture 2009
#1::
ImageSearch FilterX, FilterY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\filtercrop.png
Click %FilterX%, %FilterY%
#2::
ImageSearch FinishSketchX, FinishSketchY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\finishsketchcrop.png
Click %FinishSketchX%, %FinishSketchY%
#3::
ImageSearch QuitSketchX, QuitSketchY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\quitsketchcrop.png
Click %QuitSketchX%, %QuitSketchY%

return

david.kingham
2008-07-30, 02:22 PM
And this one to open the View Range by hitting F2



#SingleInstance force
SetTitleMatchMode 2

#IfWinActive Revit, Detail Level
{
F2::
{
{
Send {Alt}vv{Altup}
}
WinWaitActive Element Properties
{
Click 405, 485
Click 300, 470
}
}
return
}

truevis
2008-07-30, 03:03 PM
Here's one I put together using the ImageSearch function....

Excellent example. I'd use
#IfWinActive Revit to make it work with all Revit flavors.

I could not get your images. Maybe try attaching them in a .ZIP.

still.james
2008-07-30, 03:11 PM
this is great, i will try have a go but im looking forward to more hot key scripts.

here are those images in a zip to

truevis
2008-08-01, 03:57 AM
Here's part of a script I did today that sets selected column heights. I mapped win-1 to 4 to set heights for each common level range on a big structural project I've been working on. Sure saved me a lot of clicking today! Choosing the levels from a large pull-down list is tedious but win AHK, it goes click {HOME}{DOWN 4}{ENTER}, etc.

It was also useful when I was populating columns up a grid intersection as I'd Copy/Paste Aligned Same Place, and then hit the appropriate shortcut key to send the new column up.


;SETS LEVELS OF SELECTED COLUMNS
#1:: ; level 0+
WinWait, Revit
IfWinNotActive, Revit, WinActivate, Revit
WinWaitActive, Revit
Send, {ALTDOWN}{ENTER}{ALTUP}
WinWait, Element Properties, Instance Parameters
IfWinNotActive, Element Properties, Instance Parameters , WinActivate, Element Properties, Instance Parameters
WinWaitActive, Element Properties, Instance Parameters
MouseClick, left, 391, 324
Sleep, 100
Send, {HOME}{DOWN 4}{ENTER}
WinWait, Element Properties, Instance Parameters
IfWinNotActive, Element Properties, Instance Parameters , WinActivate, Element Properties, Instance Parameters
WinWaitActive, Element Properties, Instance Parameters
Send, {TAB}0
MouseClick, left, 393, 353
Sleep, 100
Send, {HOME}{DOWN 10}{ENTER}
WinWait, Element Properties, Instance Parameters
IfWinNotActive, Element Properties, Instance Parameters , WinActivate, Element Properties, Instance Parameters
WinWaitActive, Element Properties, Instance Parameters
Send, {TAB}4{ENTER 2}
return

DaveP
2008-08-01, 07:03 PM
I'm a simple kind of guy.
I just rolled this one out to the office.
All it does is answer that annoying "This Central File has been copied" message.
We make new Local Copies every morning, so you have to answer that every day.



#Persistent
SetTimer, MsgBoxCheck, 1000
MsgBoxCheck:
If WinExist("Revit", "This Central File has been copied or moved from", "ahk_class #32770")
{
WinClose
}



That's all it does - just answer that one message
And, to be honest, I stole it from Dave Baldacchino's "Transparent Local file" script.
http://forums.augi.com/showthread.php?t=65897&highlight=make+local

truevis
2008-08-10, 10:59 PM
I'd posted one about how to remove the username from the INI: http://forums.augi.com/showpost.php?p=839396&postcount=5

I was watching Olympic judo last night and wanted to magnify the commentary on nbcolympics.com (http://www.nbcolympics.com/), so I used an AHK script to magnify the screen. It is really something! I'm wondering if it could be used with Revit for anything? http://www.autohotkey.com/forum/topic11700.html

truevis
2008-08-14, 04:48 PM
Actually, we want to use "#IfWinActive Revit" before any hotkey lines if we want the hotkey only to do anything when in Revit. (I'm still learning!)

david.kingham
2008-10-30, 08:37 PM
Here's a little one I threw together for our users to search our library easier, just hit CTRL+F in Revit and it will open windows explorer in the search mode looking at our library, you just have to change the path after Run Find to point to your library



#SingleInstance force
#NoTrayIcon
SetTitleMatchMode 1
Hotkey, IfWinActive, Revit
Hotkey, ^f, SEARCH
Return
SEARCH:
Run Find Q:\Revit\Content\Neenan Library
Return

Dave F.
2008-11-21, 01:39 PM
.
We make new Local Copies every morning

Dave
Out of curiosity, why do that?

Thanks

DaveP
2008-11-21, 02:48 PM
'couple of reasons.
First, we work with a partner in Malaysia. They copy our Central file over to their office & work on it while we're sleeping (remember sleeping?). When we get the file back in the morning, the Central file - even though it is the same name - has been replaced, so our Locals are no longer compatible.

Second, we figure it's just as fast to make a new Local as it is to Open the file and do a Reload Latest right away. We have a VB program here that takes care of making our Locals (not unlike what David's script here does), so most of it is automatic.

Finally, all it takes is one person to be working for an hour or two before they do a STC and THEN find out that their Local isn't compatible to make up for a lot of "extra" making Locals. It's cheap insurance.

Dave F.
2008-11-21, 02:52 PM
Good points, well made. :-)

Thanks

Pierre-Nelson NAVARRA
2008-12-02, 08:56 AM
Is it possible to create a new tool bar with buttons in Revit?

david.kingham
2008-12-09, 04:52 PM
Through the API yes, but this is the only way

Martin P
2009-10-06, 07:58 PM
Here's one I put together using the ImageSearch function.
Creates shortcuts for the Filter button (Win + 1) Finish Sketch (Win + 2) and Quit Sketch (Win + 3)
Images I used are attached too, I had to crop them down pretty small because they have a transparency, so if you got the area around the icon it wouldn't work on some computers because the background color may be different


SetTitleMatchMode 2
#IfWinActive Revit Architecture 2009
WinGetPos RevitX, RevitY, RevitWidth, RevitHeight, Revit Architecture 2009
#1::
ImageSearch FilterX, FilterY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\filtercrop.png
Click %FilterX%, %FilterY%
#2::
ImageSearch FinishSketchX, FinishSketchY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\finishsketchcrop.png
Click %FinishSketchX%, %FinishSketchY%
#3::
ImageSearch QuitSketchX, QuitSketchY, 0,0,RevitWidth,RevitHeight, Q:\Revit\Files\AHK\Revit\quitsketchcrop.png
Click %QuitSketchX%, %QuitSketchY%

return


LOL!....
Here I am struggling to work my head round to getting an "edit Sketch" and "finish sketch" to work with imagesearch in Autohotkeys for that menu thing i did, and trawling round the autohotkeys forums looking fo ir bits I could lift and try to follow - and you have pretty much done it already and its here - I found it on google! absolutely perfect, will just need a tweak i think to work in 2010 and I think it will be exactly what I was planning to do too!

Are you having it search the entire screen then for the images rather than just the top part?

BTW I have now added each of those flyout menus to it own mouse gesture using strokeit on my office system - it is extremely fast to get to the command you want, and it is right next to where you are working, very happy with it :) - I noticed a mouse gesture function on the Autohotkey site, might be worth tying it all into one big AHK file?.... bit beyond me though at the moment, you guys look as though you have been at this for a while already? just a thought ;) Anyhow great to know that there are others using AHK with Revit.

david.kingham
2009-10-06, 08:07 PM
Haha I forgot I even did that (obviously I haven't used it for some time) I like the idea of strokeit, I used to use that when I used a tablet, combined with your script it could be blazing fast! Let me know if I can help you with anything