Diary of a Wimpy BIM Manager - The Building Coder

Diary of a Wimpy BIM Manager: Tales of
In-House Revit® API Development for Architects
Iffat Mai
Practice Application Development Manager
Perkins+Will
Thanks to:
Poll
1. Discipline




Architect
Engineer
Programmer
Other
2. Revit



Very experienced
Quite experienced
Not experienced
3. Revit



Experience
API Skill
Very experienced
Quite experienced
Not experienced
Overview






Introduction
Overview of Revit API
Tool Development Process
Demo of sample tools
Walk through some codes
Resources
Objective

Share in-house Revit API tool development process

Do it in-house or out-source the development work

Inspire BIM Manager to take on the Revit API challenge
Background




Architectural Degree from MIT
Worked with MIT media lab (have some programming skills)
Twenty plus years of experience of working in the Architectural
field in NYC.
Started as an Arris user (Unix)
 AutoCAD user (DOS, Windows)
 CAD Manager
 IT Manager
 Digital Design Manager
 BIM Manager
 Research Manager/Application Developer
Perkins + Will and Autodesk Revit

Began implementation in 2004

Revit Architecture is our Core BIM Application

Team of 24+ Design Applications Professionals supporting Projects

850+ Staff trained in-house

Over 180 projects are completed or underway

Committed to Use BIM Methods for 100% of our Projects
Kempinski Hotel + Residences
Revit Experience

Familiar with Autodesk® Revit® Architecture

Have an architectural design background

Trained and supported architectural teams to use Autodesk®
Revit® Architecture

Began developing with API in 2007

I’m an Autodesk® Revit® BIM Manager who learned API
programming
Why Customize Revit?




Automate repetitive work
Processing large quantity of data
Facilitate import & export
Synchronize data
What is Revit API?

API = Application Programming Interface
AutoCAD API vs. Revit API
AutoCAD API





Scripts
Lisp
ObjectARX
ActiveX
AutoCAD.Net
Revit API


.Net
VSTA
Revit API History
Revit 5
No API
Revit 6
No API
Revit 7
No API
Revit 8
First Public API for Building and Structure
Revit 9
More Element Creation Added
Revit Architecture 2008
Revit API SDK released
Revit Architecture 2009
VSTA Released. API for MEP added
Autodesk Revit Architecture 2010
Developer’s Guide released
Autodesk Revit Architecture 2011
RevitAPI.dll and RevitAPIUI.dll split
Revit API Namespace Changes
Revit 2011 divides the API three primary namespaces:
 Autodesk.Revit.ApplicationServices


Autodesk.Revit.DB


Classes accessing application settings and options
Classes accessing file data
Autodesk.Revit.UI

Classes accessing or customizing the user interface
Revit API Namespaces
Revit API Platform
Application
Services
Database
User Interface
(Revit.DB)
(Revit.UI)
Structure
Architecture
MEP
(Revit.DB.Structure)
(Revit.DB.Architecture)
(Revit.DB.Mechanical)
(Revit.DB.Electrical )
(Revit.DB.Plumbing)
(Revit.ApplicationServices)
.Net vs. VSTA
DECAF
.Net


Editor: Microsoft Visual Studio
Program language





VSTA



VB.net
C#
Create external tools/App
Exist outside of Revit
Use across many Revit
Projects
Editor: Built-in inside Revit
Program language




VB.net
C#
Create Macro
Exist inside of Revit
Use only in the Projects it was
created or loaded in
Microsoft Visual Studio


.Net Framework 3.5
Editor(IDE)  Microsoft Visual Studio
(http://www.microsoft.com/express/Downloads)
Parlez Vous C Sharp?

Language Options:








C#
VB.net
C++
Most sample codes in SDK are written in C#
VB.net is much more readable
VB.net is not case sensitive.
VB.net - Intellisense can automatically corrects Keywords and
variable names
Use web translator to convert C# to VB
(http://www.developerfusion.com/tools/convert/csharp-to-vb/)


Both compiles and runs at the same speed
You can reference .dll written in other language.
VB.NET vs. C#
VB.NET
Imports System
Namespace Hello
Class HelloWorld
Overloads Shared Sub Main(ByVal args() As String)
Dim name As String = "VB.NET"
'See if an argument was passed from the command line
If args.Length = 1 Then name = args(0)
Console.WriteLine("Hello, " & name & "!")
End Sub
End Class
End Namespace
C#
using System;
namespace Hello {
public class HelloWorld {
public static void Main(string[] args) {
string name = "C#";
// See if an argument was passed from the command line
if (args.Length == 1)
name = args[0];
Console.WriteLine("Hello, " + name + "!");
}
}
}
(Source: http://www.harding.edu/fmccown/vbnet_csharp_comparison.html)
Autodesk Revit SDK



SDK = Software Development ToolKit
Install from Autodesk Revit Installation disk
Download from Autodesk Developer Center



http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975
.NET code samples and documentation
Useful tools
Autodesk Revit SDK




Add-In Manager
RevitLookup
RevitAPI.chm
Revit 2011 Developer Guide.pdf
Training

DevTV: Introduction to Revit 2011 Programming - Part 1 - New!


http://download.autodesk.com/media/adn/DevTV_Revit_API_2011_English_Part1/Revit_2011_DevTV_EN.html
DevTV: Introduction to Revit 2011 Programming – Part 2 - New!

http://download.autodesk.com/media/adn/DevTv_Revit_NET_English-Part2/Revit%20DevTV%20%20part%202.html
.NET
Microsoft Visual Studio
VB.Net
Revit API SDK
Tool Development Process
Documentation
Coding
Tool
Proposal
Feasibility
Study
Training
Debugging
Maintenance
Specification
Testing
Deployment
Tool Proposal





Welcome ideas from all users
Showcase your tools to encourage more ideas.
End user – task specific tools
Design Application Manager – common issue tools
Technical Directors

Quality control
 Standard enforcement
 Process enhancement
Feasibility Study
Can you do it with Revit API?
How long will it take to do it?
What is my ROI?
Can you do it using Revit API?







Can the steps be done manually via the User Interface?
Use Revit LookUp tool to trace the object
Check with RevitAPI.CHM reference to see what properties and
methods are available
Review the Revit API Developer’s Guide.
Look at the SDK sample folder for similar application
Search Revit API blogs and Forum on the internet
Verify with ADN support that it can be done
How long will it take to develop?

How familiar are you with Revit API?
How good are you with .Net programming
Is the logic and task very straight forward?
Is there an existing sample application that you can modify?
Make your best estimate

Then multiply by 3x




What is my ROI?

How often will they use the tool on this project?

One time only
 Only during one phase
 Used through out the entire project

Can this tool be used on other projects?

Not at all
 If parameter and variable are customizable
 Yes, all the time!
Specification





Clearly define input and output requirement
Describe in details all the functions the
application will have.
Work out the logics of how the tool will flow
Sketch out flow chart for visual overview
Cartoon sets of the input and output forms
and reports
Coding, Debugging & Testing








Use Revit API template to start
Use SDK sample application as a base
Set Microsoft Visual Studio Debug property to start Revit
Add option to automatically load test file
Use small test file for initial testing
Use copies of actual project files for later testing
Solicit project team members to test the application
Implement feedback to improve design and performance
Documentation, Training & Maintenance





Add comments inside the codes for documentation
Create user guide documentation
Add Help button that will take the user directly to the
documentation
Provide video snippet for self-guided training
Maintenance for version upgrade is required for every new
Revit API release.
Deployment






Consolidate all tools into one folder
Create a Ribbon ExternalApplication that
contains all the tools as buttons.
Copy the DLL folder to the local machines
Maintain subfolder for version control
Copy .addin manifest file to designated
Revit addins folder
Keep icon files in a separate folder
ExternalApplication Ribbon




Create Ribbon file to combine all commands
Design Ribbon icons
Read Autodesk Icon Guidelines.pdf
Check out Ribbon sample file in the SDK
SDK Samples Category












Basics
Geometry
Parameters
Elements
Families
Materials
Annotation
Views
Rooms/Spaces
Data Exchange
MEP
Structure
Tools Demo

Data Manipulation Tools

Batch Tools

Design Tools

Utility Tools
Data Manipulation Tools



Export Drawing List to Excel
Import updates from Excel
Add new sheets from Excel
Design Tool


SDK – Sample>Massing
MeasurePanelArea
Measure Panel Area (Update)
protected IList<Element> GetPanels()
{
FilteredElementCollector collector
= new FilteredElementCollector( m_uiDoc.Document);
BuiltInCategory bic = BuiltInCategory.OST_CurtainWallPanels;
collector.OfClass( typeof( FamilyInstance ) ).OfCategory( bic);
IList<Element> panels = collector.ToElements();
return panels;
}
Source: http://thebuildingcoder.typepad.com/blog/installation/
Batch Tools

Door Renumber
 Renumber door number to match
room number
Utility Tool – Find Dwg
Find Dwg

Problem:

Dwg can be linked and imported
 Often Dwg files can’t be found after it is inserted
 I want to be able to find it and delete it if I want to.

Solution:

Filter elements till I find DWG
 Present them in a list
 Give user the option to View
and Delete
Revit LookUp Tool

RvtMgdDbg  Revit Lookup
Anatomy of Find Dwg Tool
Command
IExternalCommand
CommandData
CommandData
Filter
DwgList (Form)
Dwg
Obj
Array
Anatomy of Find Dwg Tool



Command.vb
DwgList.vb (Form)
DwgObj.vb
Reference Revit Assemblies

Revit required assemblies:



C:\Program Files\Autodesk\Revit Architecture 2011\Program\RevitAPI.dll
C:\Program Files\Autodesk\Revit Architecture 2011\Program\RevitAPIUI.dll
Set property of the dll to:

Copy Local = False
 Specific Version = True
Command.vb
Imports Autodesk.Revit
Imports
Imports Autodesk.Revit.UI
Imports System.Windows.Forms
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)> _
Attributes
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Automatic)> _
<Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)> _
Public Class Command
Implements IExternalCommand
Command Class Begin
Private m_revit As Autodesk.Revit.UI.UIApplication
Public Function Execute(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
ByRef message As String, _
ByVal elements As Autodesk.Revit.DB.ElementSet) _
As Autodesk.Revit.UI.Result Implements Autodesk.Revit.UI.IExternalCommand.Execute
m_revit = commandData.Application
Dim displayForm As New DwgList(commandData)
Implements
IExternalCommand
Function Execute
Using (displayForm)
If displayForm.ShowDialog() <> DialogResult.OK Then
Return Autodesk.Revit.UI.Result.Cancelled
End If
calls
DwgListForm
End Using
displayForm.Dispose()
Return Autodesk.Revit.UI.Result.Succeeded
End Function
Sub Finalize
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Command Class End
IExternalCommand
Implements IExternalCommand
Private m_revit As Autodesk.Revit.UI.UIApplication
Public Function Execute(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
ByRef message As String, _
ByVal elements As Autodesk.Revit.DB.ElementSet) _
As Autodesk.Revit.UI.Result Implements
Autodesk.Revit.UI.IExternalCommand.Execute
m_revit = commandData.Application
Dim displayForm As New DwgList(commandData)
Using (displayForm)
If displayForm.ShowDialog() <> DialogResult.OK Then
Return Autodesk.Revit.UI.Result.Cancelled
End If
End Using
displayForm.Dispose()
Return Autodesk.Revit.UI.Result.Succeeded
End Function
Anatomy of Dwg Obj Tool
Name
ElementID
Dwg
Obj
Type
ViewType
BaseLevel
DwgList Class
Public Class DwgList
'a reference to the external command data.
Private m_commandData As ExternalCommandData
''' <summary>
''' Constructor
''' </summary>
''' <param name="commandData">the external command data</param>
Public Sub New(ByVal commandData As ExternalCommandData)
MyBase.New()
InitializeComponent()
m_commandData = commandData
Initialize()
End Sub
Filter
Dim ImportInstanceFilter As New
ElementClassFilter(GetType(DB.ImportInstance))
iter = New FilteredElementCollector(doc)_
.WherePasses(ImportInstanceFilter)_
.GetElementIterator()
Looping (Do While…Loop)
'Move to the first instance symbol
iter.Reset()
'Create a array of DwgObjList
Do While iter.MoveNext
If (Not (iter.Current) Is Nothing) Then
sym = iter.Current
sym_name = sym.Parameter(ImpSymName).AsString
ins_id = sym.Id
ins_size = sym.Parameters.Size
parByName = iter.Current.Parameter(csParamToFind)
Is2D = iter.Current.Parameter(csParam2D)
Linked = sym.IsLinked
LinkedType = "N.A."
viewname = "N.A."
baselevel = "N.A."
Creating DwgObj Array
DwgObjList.Add(New DwgObj(sym_name, ins_id,
LinkedType, viewname, baselevel))
Name
ElementID
Dwg
Obj
Type
ViewType
BaseLevel
Tool Deployment

Compile .dll
Create .addin manifest files
Pushout the dll and .addin files to local machines

Or

Use Add in Manager to load the external tool manually


Register .addin Manifest file
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Text>$projectname$</Text>
<Description>Some description for $projectname$</Description>
<Assembly>$destinationdirectory$\$safeprojectname$.dll</Assembly>
<FullClassName>$safeprojectname$.Commands</FullClassName>
<ClientId>$guid1$</ClientId>
</AddIn>
</RevitAddIns>
GUID

GUID = Globally Unique Identifier
http://www.guidgenerator.com/online-guid-generator.aspx
Addin File





Revit requires the add-in to be registered BEFORE it starts
Open the FindDwg.addin file
Edit the <Assembly> to reflect the actual location of .dll
Copy the .dll to one of the following locations:
- For the current Windows User only


- For all users


%ALLUSERSPROFILE%\Autodesk\REVIT\Addins\2011
For Windows XP –


%APPDATA%\Autodesk\REVIT\Addins\2011
C:\Documents and Settings\All Users\ApplicationData\Autodesk\Revit\Addins\2011\
For Vista/Windows 7 –

C:\ProgramData\Autodesk\Revit\Addins\2011\
How to run the Tool?


Go to Addin Tab > External Commands dropdown,
select “FindDwg”
Or

Create a custom Application with a Ribbon button for the
command
Blogs





Bolt Out Of The Red – Guy Robinson http://redbolts.com/blog/
Revit Programming – Ed Pitt - http://revitprogrammer.blogspot.com/
The Building Coder – Jeremy Tammik http://thebuildingcoder.typepad.com/blog/
CAD Application Development – Matt Mason http://cadappdev.blogspot.com/
Rod Howarth – Rod Howarth http://roddotnet.blogspot.com/
Revit Resource Guide
Revit Resource Guide – by Rod Howarth
(http://blog.rodhowarth.com/2010/03/revit-api-resource-guidefree-download.html)

Summary




Knowing Revit API gives you an edge over your competition
Learning Revit API has become a lot easier than ever before
To do or not to do (in-house vs. out-sourcing) ?
Give yourself an early Holiday present – Learn Revit API!
Please Complete the Survey!
Q&A
Email:
Iffat.mai@perkinswill.com
Autodesk [and other] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to
their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may
appear in this document. © 2010 Autodesk, Inc. All rights reserved.