Friday, March 26, 2010

[Revit 2011] – No more revit.ini for registering add-ins!

Can I get a hallelujah? It’s been a long time coming, but now it’s finally here! Anyone who has developed with the Revit API before will know you had to edit the clumsy Revit.ini file to add your tool. When doing so you had to be careful to set the right numbers and counts, and not overwrite any other developers tools. Well now you can forget all that!

In Revit 2011 there is a new XML based interface for registering your tools. The new .addin mechanism allows you to register your External Commands and External Applications using 1 or more xml files stored in the standard windows directories (AppData or ProgramData).

Here’s an example file in the new format to register two external commands:

<?xml version="1.0" encoding="utf-16" standalone="no"?>

<RevitAddIns>

<AddIn Type="Command">

<Assembly>C:\MyTools\MyFirstTool.dll</Assembly>

<ClientId>8e1af74e-e290-4538-b61f-aaf5f0ffecf8</ClientId>

<FullClassName>MyTool.Command</FullClassName>

<Text>MyTool</Text>

</AddIn>

<AddIn Type="Command">

<Assembly>C:\MyTools\MySecondTool.dll</Assembly>

<ClientId>5fb945d4-f8e8-48ab-9649-194de466b180</ClientId>

<FullClassName>MySecondTool.Command</FullClassName>

<Text>MySecondTool</Text>

</AddIn>

</RevitAddIns>

This can be edited in notepad, and saved as WhateverILike.addin and stored in AppData or ProgramData (depending on whether you want it to be specific to the user or across anyone on the machine).

As you can see there, I’ve got two commands, registered easily in one .addin file. If I wanted to add another command later, I could either edit that file, or add a new .addin file! Most of the fields correspond to the old ini registration fields, except for ClientId, this is a GUID that is used to uniquely identify your add-in. You can get a GUID for your tool from here: http://www.guidgenerator.com/online-guid-generator.aspx

There are also a number of other properties and functionalities built in, such as setting the accessibility, icons, tool tip images etc, but have a look through the SDK documentation for information on those.

If this wasn’t easy enough, Autodesk have provided a dll file which can assist you with manipulating these files!

1 comment:

Anonymous said...

good info.

now the manifest file can be created automatically by a wizard as well:

http://spiderinnet.typepad.com/blog/2010/12/what-the-addin-registration-file-look-like.html