Posts Tagged ‘ AutoCAD ’

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