Revit APP Blog

Information on Revit APP.

Browsing Posts published in May, 2010

Open your visual studio, new a project, New a project.

Choose the Visual C# – > Windows in the left panel, and select “Class Library” in the right panel, then input “myRevitApp” in the Name edit box, after that, click OK to new a project,Project Setting.

In the project solution tree, right click ”References”, click “Add Reference”:Add Reference.

Choose the fourth tab “Browse” tab, and browse the directory of your revit application, then choose “RevitAPI.dll” and “RevitAPIUI.dll”

Add Reference Dialog

In addition, please add reference of “System.Windows.Forms” from “.Net” tab. Then add following three lines before the namespace…

using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.UI;

And replace the text in the namespace area with following code:

   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
   public class Class1 : IExternalCommand
   {
      public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
      {
         MessageBox.Show(“my first revit application!”);
         return Result.Succeeded;
      }
   }
Build the solution. Add an empty file named myRevitApp.addin and add following text in this file:

<?xml version=”1.0″ encoding=”utf-8″?>
<RevitAddIns>
  <AddIn Type=”Command”>
    <Assembly>C:\Project\Projects\myRevitApp\bin\Debug\myRevitApp.dll</Assembly>
    <ClientId>7cbae747-78f9-4dd5-ac92-a94f6229f9b3</ClientId>
    <FullClassName>myRevitApp.Class1</FullClassName>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
  </AddIn>
</RevitAddIns>

Please change the Path in the <Assembly> to the dll you just build. And put this file in C:\ProgramData\Autodesk\Revit\Addins\2011 if you’re using win7, or C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\ if you’re using window xp.

And run your revit, you can see an add-ins tab, click the button under “External Tools”, you will see the pop up message box.

Add ins command   Message box

Enjoy.

Many people are wondering what the prospect of Revit API development is. They believe there is some opportunities, however don’t know how big it is and how large the market will be. Even Revit based products still have many limitations, gaps, and are not mature as AutoCAD, I still would say that there is a great opportunity for Revit API development and there would be a great increase market on this with grows of Revit market. There are three reasons.

First, building information modeling (BIM) is the future of building modeling and would be a standard. It proves its value in the complete life cycle of building modeling starting from the very beginning stage – conceptual design.

Second, all Revit based products which are parametric BIM tools are the main BIM tools produced by Autodesk. Autodesk will definitely reinforce these products to make it as the leader role in this area. From the latest 2011 release, we can see many new features / enhancement / problem fix. And I believe Autodesk will improve these products continuously.

Third, as we know, none software can satisfy every user, there always be gaps between the user requirements and the software capabilities. So many smart companies deliver their public API for their software and allow third party developer to develop add-ins based on their API. There are tons of successful cases. Like apple’s iPhone platform and Autodesk’s AutoCAD platform. The third party add-ins will also add value to the platform. From the change in 2011 Revit API, we can see that Autodesk is trying to provide as much API as possible and I am expecting Revit API will be as strong as AutoCAD APIs at the end of day.

Based on these, I have confidence that Revit API development has a bright future. The only concern is how quick Autodesk will make the Revit success and make the Revit API strong enough.

What You Will Need to Get Started

  • A working understanding of Autodesk Revit Architecture, Autodesk Revit Structure or Autodesk Revit MEP 2011
  • An installation of an Autodesk Revit-based product, including the Software Development Kit
  • MS Visual Studio 2008 or MS Visual Studio 2008 Express Edition, or a full installation of Microsoft Visual Studio. If you plan to start with VSTA, you do not need to install any of these.
  • Some experience in a .NET based development language (Autodesk Revit API examples are provided in C# and Visual Basic.NET.)
  • 2 days of free time

Understanding Autodesk Revit

All Autodesk Revit-based products are Parametric Building Information Modeling (BIM) tools. Such a tool can be looked at as a CAD program that is used to build a 3D model rather than a set of individual drawing files. Autodesk Revit modeling is accomplished with real-world elements like columns, walls, doors and windows. The user can create views of the model, including plans, sections and callouts. All these views are directly generated from the 3D physical model so changes made in one view will automatically propagate through all other views. This process virtually eliminates the need to update multiple drawings and details when a change is made in the model.

The Autodesk Revit API is designed to reflect the same user interaction paradigms as the program’s Graphical User Interface. Therefore, the first step to understanding the API is to learn how to use the program. If you are an Autodesk Revit novice, we suggest you first start by going through the Tutorials which you can access through the program’s Help menu. You may also find it helpful to take a Training class from your local Autodesk reseller. This will help you quickly get up to speed with the program

Autodesk Resources:

Select = Autodesk Revit Building

Then Select = Autodesk Revit API

External Resources:

Installation of the Autodesk Revit API

The Autodesk Revit API is automatically installed with the default installation of the Autodesk Revit based product.

The Autodesk Revit API Software Development Kit is installed from the Tools and Utilities section of the Autodesk Revit installation DVD.

Development Requirements

The Autodesk Revit API requires the Microsoft .NET Framework v3.5.  To edit and debug your API applications, you need an interactive development environment such as Microsoft Visual Studio 2008 or one of the MS Visual Studio Express Editions for C# or Visual Basic.NET.  When developing with the Autodesk Revit API, ensure that your project references two DLLs: RevitAPI.dll and RevitAPIUI.dll contained in the Autodesk Revit Program directory.

Some programming skills are required to effectively use the API. If you are a beginner in programming, we strongly advise you to learn Microsoft Visual Studio 2008 and one of the compatible languages like C# or Visual Basic.NET. There are many good books and classes to get you started.

Resources:

Online resources

Books:

  • Code Complete, Second Edition, by Steve McConnell
  • Software Project Survival Guide, by Steve McConnell

Overview

Autodesk Revit Architecture 2011, Autodesk Revit Structure 2011 and Autodesk Revit MEP 2011 offer an API designed to allow power users and external application developers to integrate their applications with Autodesk Revit. The APIs for each of these three products are very similar and will be jointly referred to as the Autodesk Revit 2011 API or Autodesk Revit API.  It is strongly recommended that you become familiar with Autodesk Revit Architecture, Structure or MEP and its features before attempting to use the Autodesk Revit API. Training can be found through the Autodesk Developer Network (ADN).

What Can I Do With the Autodesk Revit API?

The following are general areas where the API is suitable:

  • Creating add-ins to automate repetitive tasks in the Autodesk Revit user interface
  • Enforcing project design standards by checking for errors automatically
  • Extracting project data for analysis and to generate reports
  • Importing external data to create new elements or parameter values
  • Integrating other applications, including analysis applications, into Autodesk Revit products
  • Creating Autodesk Revit project documentation automatically

The new XYZ and UV classes in Revit 2011 API under namespace Autodesk.Revit.DB are immutable. That’s to say, objects of these classes can’t be changed once it’s created. It’s similar with number in Python.

Then, please keep in mind that any method of XYZ/UV will not change its value, like for following methods:
   CrossProduct
   Add
   Subtract
   Negate
   Multiply
   Divide
They will all return a new XYZ object contains the calculation result instead of changing original value. UV is similar.

Refactored Document properties related to transactions

Two existing properties have been re-implemented to better complement the changes in the transaction framework:

  • Document.IsReadOnly

Indicates that a document is – either temporarily or permanently – in read-only state. If it is read-only, it would mean that new transactions may not be started in that document, thus no modification could be made to the model.

  • Document.IsModifiable

Indicates whether a document is or is not currently modifiable. A document is not modifiable if either there is no transaction currently open or when some temporary state lock modification for a certain operation. Taken from another perspective, a transaction may be started only when document is not yet modifiable, but is also not read-only.

Transactions in events

All events have been changed to no longer automatically open transactions like they originally did in earlier releases. As a result of this new policy, the document will not be modified during an event unless one of the event’s handlers modifies it by making changes inside a transaction. A transaction may be opened by either the event handler if there is no transaction already opened (sometimes when the event is invoked, there is already a trasnaction open). If an event handler opens a transaction it is required that it will also close it (commit it or roll it back), otherwise all eventual changes will be discarded.

Please be aware that modifying the active document is not permitted during some events (e.g. the DocumentClosing event). If an event handler attempts to make modifications during such an event, an exception will be thrown. The event documentation indicates whether or not the event is read-only.

The Revit API has been split into two DLLs. The new DLLs are:

  • RevitAPI.dll – which now contains only methods used to access Revit’s application, documents, elements, and parameters at the database level.
  • RevitAPIUI.dll – which contains all API interfaces related to manipulation and customization of the Revit user interface, including:
  • IExternalCommand and External Command related interfaces
  • IExternalApplication and related interfaces
  • Selection
  • RibbonPanel, RibbonItem and subclasses
  • TaskDialogs

In order to facilitate access to application and document level interfaces from both DLLs, the Application and Document classes have also split into two:

  • Autodesk.Revit.UI.UIApplication – provides access to UI-level interfaces for the application, including the ability to add RibbonPanels to the user interface, and the ability to obtain the active document in the user interface.
  • Autodesk.Revit.ApplicationServices.Application – provides access to all other application level properties.
  • Autodesk.Revit.UI.UIDocument – provides access to UI-level interfaces for the document, such as the contents of the selection and the ability to prompt the user to make selections and pick points
  • Autodesk.Revit.DB.Document – provides access to all other document level properties

The ExternalCommandData interface now provides access to the UIApplication object as well as the active view. From the active UIApplication object you can obtain the active UI document. You can also construct the UIApplication from the Application object, and the UIDocument from the DB level document at any time.

[One Point]

You can know better how Autodesk split Revit API DLL by a few simple codings. Practice it, and you can know it better:-)

The Revit API namespaces have been changed to be more consistent and more suitable to expansion. In previous releases, API classes were split along the lines of functionality and Revit vertical product, which led to confusion about where classes which were Elements or Symbols belonged if they were specific to one vertical. In the new namespace structure, there is a primary division into three sets of namespaces:

  • Autodesk.Revit.ApplicationServices – contains classes accessing settings and options for the main Revit application
  • Autodesk.Revit.DB – contains classes accessing data from the Revit file
  • Autodesk.Revit.UI – contains classes accessing or customizing the Revit user interface

Within these main namespaces there are subdivisions based on discipline, e.g.:

  • Autodesk.Revit.DB.Architecture
  • Autodesk.Revit.DB.Structure
  • Autodesk.Revit.DB.Mechanical
  • Autodesk.Revit.DB.Electrical
  • Autodesk.Revit.DB.Plumbing

Classes which are useful in more than one discipline are placed in the Autodesk.Revit.DB main namespace.

Less commonly used classes, like event arguments, are also placed in subordinate namespaces, e.g.:

  • Autodesk.Revit.DB.Events
  • Autodesk.Revit.UI.Events

As a result of the rearrangement of the namespaces, a few classes have been modified more drastically than simply being moved to new namespaces:

  • Autodesk.Revit.Geometry.Element has been renamed to Autodesk.Revit.DB.GeometryElement to avoid a naming conflict.
  • Autodesk.Revit.Geometry.Instance has been renamed to Autodesk.Revit.DB.GeometryInstance to avoid a naming conflict.
  • Autodesk.Revit.Structural.Enums.Material has been renamed to Autodesk.Revit.DB.MaterialType to avoid a naming conflict.
  • Autodesk.Revit.Options.Application has been removed. The properties accessible from this class have been moved into Autodesk.Revit.ApplicationServices.Application.

To obtain a full list mapping the changes from the Revit 2010 API, see the document Revit 2011 API Namespace Remapping.xlsx in the Software Development Kit install.

Powered by WordPress Web Design by SRS Solutions © 2012 Revit APP Blog Design by SRS Solutions