Nice AR example

Here is really nice example, that soryn made for graduate thesis.

Augmented Reality – VFX Breakdown from soryn on Vimeo.

I am adding this one also because of nice music. Please let me know if anybody knows the artist!

Augmented reality

During the weekend I ran across this really cool augmented reality software. Check it out at AR-media website.

Error report after user closes Revit

I got  bug report, where the customer was saying, that Revit is crashing when our addin is installed. After discussion, I got some more information, but still not enough to solve it. It was indeed problem with our addin – Revit didn’t crash, but the user got an error report, when Revit was closing.

After some more investigation, I found out, that this wasn’t happening on development machines, since we got UAC turned off. Once I got UAC to “Always notify”, I got the same problem.

The reason behind this was, that we are creating log file in SpecialFolder.CommonApplicationData directory (C:\ProgramData\ on on Windows 7 ) , which is where Windows does not allow us to write anything. Problem was solved once I moved log file to current user’s application data (SpecialFolder.ApplicationData). I might add, that I am on Windows 7 64bit.

Below are the directories, which are affected by UAC setting (Windows Vista & Windows 7):

SpecialFolder.CommonApplicationData: C:\ProgramData
SpecialFolder.ProgramFiles: C:\Program Files

This one is safe:

SpecialFolder.ApplicationData:        C:\Documents and Settings\myusername\Application Data

If for some reason you wan to keep your file in these directories, you can try with UAC elevation.
And those folders on Windows XP:

SpecialFolder.CommonApplicationData:  C:\Documents and Settings\All Users\Application Data
SpecialFolder.ProgramFiles:           C:\Program Files
SpecialFolder.ApplicationData:        C:\Documents and Settings\myusername\Application Data

Another interesting thing is, that any Revit shared parameter definition file stored in CommonApplicationData isn’t affected by this setting.

Enhanced by Zemanta

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>

InnoSetup: Check if Revit is running

When installing Revit (or AutoCAD) addins, you have to check if process is running otherways files are not copied correctly.

I am using Inno Setup for my setup projects, since I found it extremely powerful and easy to use. Previously I used Visual Studio Installer, you can read Kean’s tutorial how to implement it. The solution was great since you got the MSI file, which you could include in other installers, but there was to much mantainance and then came the news about retirement.

The code to check in Inno Setup if Revit is running:

function IsModuleLoaded(modulename : PAnsiChar): Boolean;
  external 'IsModuleLoaded2@files:psvince.dll stdcall';

function InitializeSetup(): Boolean;
    Guid : string;
    ErrorCode : integer;
    nMsgBoxResult: Integer;
  foo : string;
  dir: string;
  Result := True;
  while IsModuleLoaded2('Revit.exe') and (nMsgBoxResult <> IDCANCEL) do
      nMsgBoxResult := MsgBox(CustomMessage('RevitRunning'), mbConfirmation, MB_RETRYCANCEL)
  // if Cancel is pressed
  if nMsgBoxResult = IDCANCEL then
    Result := False;

You need to include psvince.dll file in the [Files] section of the script, for the setup to run properly.

Source: {#PATH}\psvince\x86\psvince.dll; Flags: dontcopy

You can download source for psvince.dll. When tested on 64 bit machines, I noticed, that 64 bit processes are not found, so I came up with this:

– add definition for new function at the top of psvince.cpp

BOOL WINAPI EnumProcs2(char* procname);

– copy code bellow in psvince.cpp

int APIENTRY IsModuleLoaded2( char *lpModule )
    return EnumProcs2( lpModule );

BOOL WINAPI EnumProcs2(char* procname)
    //MessageBox(NULL, procname, "msg", MB_OK);
    HANDLE handleToSnapshot;
    PROCESSENTRY32 procEntry;
    procEntry.dwSize = sizeof(PROCESSENTRY32);
    handleToSnapshot = CreateToolhelp32Snapshot(2, 0);
    if (Process32First(handleToSnapshot, &procEntry))
            //MessageBox(NULL, procEntry.szExeFile, "msg",MB_OK);
            if (strcmp(procname, procEntry.szExeFile) == 0)
                //delete handleToSnapshot;
                return TRUE;
        } while (Process32Next(handleToSnapshot, &procEntry));
    return FALSE;

– update exports in psvince.def

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