Archive for the ‘ Automation ’ Category

Code snippets with AutoHotkey

If you haven’t used AutoHotkey before, you should check on YouTube what it can do or try sample scripts from their website.

I think AutoHotkey is great productivity tool and my script is longer every day. One of the things I use AutoHotkey for is for code snippets.

I never really tried code snippets in Visual Studio, but I found code templates in Eclipse really useful and easy to define and use.

With this AutoHotkey script I came close to what I was used to in Eclipse:

; * XML
   PasteText("<word id=""Clip0"">`r`n <slo></slo>`r`n <eng>Clip0</eng>`r`n</word>")
; * PHP
::-br::<br />
   PasteText("#if r2010`r`n#else`r`nClip0`r`n#endif")

; PasteText function
   StringReplace, replaced, text, Clip0, %Clipboard%, All
   Send, ^V
   Sleep, 50                    ; Don't change clipboard while pasting! (Sleep > 0)
   Clipboard=%CurrentClip%           ; Restore original ClipBoard

In the above code, the text ‘Clip0’ is replaced by clipboard content, so in case if I type ‘<wo’ and I have text ‘Hello world!’ in clipboard, this is the resulting text:

<word id="Hello world!">
  <eng>Hello world!</eng>

Obfuscate Revit addins

EDIT: What is described below, does not work, if you have UAC enabled – you can not copy files in C:\Program Files\ directory or subdirectories – see this post for more information.

All of you that develop Revit addins have or will at one point need some obfuscation tool to protect your intellectual property. Jeremy and Kean have already written about what obfuscation is and how to do it for either Revit or AutoCAD addins.

I would like to add few notes which may be useful for you. Since I was on a tight budget, the only option for me was free obfuscator. I chose Eazfuscator.NET.

When I ran the obfuscation, I got an error saying “Unable to find type…” – see this post for more info. Daren had the similar problem and he solved it with free version of Babel.NET.

The solution was, to copy all the assemblies in Revit directory (e.g. C:\Program Files\Autodesk\Revit Architecture 2011\Program\) obfuscate it there and then move it back to working directory. Here is the BATCH file which does the trick (the file has to be located in your bin directory):

rem copy libraries
set file=Library1.dll
copy /y %file% "C:\Program Files\Autodesk\Revit Architecture 2011\Program\"
set file=Library2.dll
copy /y %file% "C:\Program Files\Autodesk\Revit Architecture 2011\Program\"

rem copy addin
set assembly=Addin.dll
copy /y %assembly% "C:\Program Files\Autodesk\Revit Architecture 2011\Program\"

rem obfuscate
"C:\Program Files (x86)\Eazfuscator.NET\" "C:\Program Files\Autodesk\Revit Architecture 2011\Program\%assembly%"
move /y "C:\Program Files\Autodesk\Revit Architecture 2011\Program\%assembly%"

rem cleanup libraries
set file=Library1.dll
del "C:\Program Files\Autodesk\Revit Architecture 2011\Program\%file%"
set file=Library2.dll
del "C:\Program Files\Autodesk\Revit Architecture 2011\Program\%file%"

I haven’t tried it yet, but I guess the method works also for AutoCAD addins.

Enhanced by Zemanta