Transcript Revit Technology Conference 2010
How the Revit API has saved our company time and money
Rod Howarth
Bornhorst + Ward
TM
Overview
• Introduction • What you can do with the API – Examples of B+W’s commands – What others are using it for – Technical overview of each macro • Where to start learning – Learning tools / resources – The ‘research process’
Revit Technology Conference 2010
Goals
• Describe WHAT can be done with the API • Overview of HOW I’ve implemented the API • Show you WHERE to find information on the API • Show you how to LEARN how to use it • Overarching aim is: ‘teach a man to fish’
Revit Technology Conference 2010
Bornhorst + Ward and Autodesk Revit
• Began implementation in 2005 • Used for all structural documentation • Fully customized families • Continuously looking for ways to improve
Revit Technology Conference 2010
My experience with Autodesk Revit
• I don’t claim to know Autodesk Revit in any great detail • I’m coming from a programming background • Began developing with API in 2008 • I’ve picked up some Autodesk Revit skills along the way • As opposed to Autodesk Revit users who learn programming
Revit Technology Conference 2010
How we have implemented the API
• Ideas pulled from years of Autodesk AutoCAD experience – Had a fully customized Autodesk AutoCAD setup • Mentality of ‘surely there’s a better way’ • Here’s what we want to automate – go code it • Feedback provided by drafters
Revit Technology Conference 2010
• Load Families • Title Block Editor • Plotting • Model Stripper • Element Numberer • Visibility Togglers • Quick Placer • Plan Copier • Detail Number Modifier • Sheet Setup • Family Management
Various API Examples Revit Technology Conference 2010
LoadFamilies
• Replacement for built in Load Families dialog • Loads multiple families at once • Small amount of time saved quickly adds up • Adaptable to different file structures
Revit Technology Conference 2010
LoadFamilies – Technical Details
• WPF (Windows Presentation Foundation) user interface – Allowed a nice code design with data binding – Looks better than tab based windows forms – Pictures from thumbnail • Actual API implementation is simple – Just calls document.LoadFamily / document.LoadFamilySymbol
– FamilyLoadOptions to override ‘family already present’ dialog
Revit Technology Conference 2010
Title Block Editor
• Easily update all of your title blocks • Huge timesaver – Original way was to manually edit a schedule – took hours – Now this is done in a few clicks
Revit Technology Conference 2010
Title Block Editor – Technical Details
• Heavily coupled with title block families • Parameters setup for revisions 1-rev 1-desc 2-rev etc – To allow for history • As well as parameters showing current revision • Loops through parameters to find latest revision • Then adds a new one
Revit Technology Conference 2010
Plotting - Overview
• Replaces inbuilt printing dialog • PDF, DWF, Paper, DWG • Automatically names + moves files • Links with document management • Saves time issuing documents • Keeps print settings standard
Revit Technology Conference 2010
Plotting – Technical Details
• ViewPrinter example is best place to start here – This shows a replication of the inbuilt menu • A lot going on, but nothing too complex • Uses DSOFile for document properties • Has been a few quirks in the API – Different default file names – Prints don’t come out in order – Has been improvements with every API release
Revit Technology Conference 2010
Model Stripper
• Allows stripping of files down to bare minimum • Used for sending models out of the office • Removes a lot of our intellectual property • Reduces file sizes • Still retains BIM data
Revit Technology Conference 2010
Model Stripper – Technical Details
• Uses FilteredElementCollectors to search document elements • ParameterFilter, OfClass, OfCategory • Calls Document.Delete method with found elements • New Revit 2011 API has vastly improved it
Revit Technology Conference 2010
Element Numbering
• Sets mark instance parameter • Numbering manually has problems – Tedious – Human error (C1..C2..C4…C4..) • Does Beams, Sections or Columns in Structural – Architectural does Doors, Stairs, Windows, etc • Run the tool, setup and click the elements – One after the other – will number accordingly – Allows control over numbering
Revit Technology Conference 2010
Element Numbering – Technical Details
• Document.Selection.PickObject(ObjectType.Element) method – Used in a loop • Allows users to select elements one after the other – Accessible by getting the Reference.Element Property returned • Then simply set the Mark parameter of each picked element
Revit Technology Conference 2010
Visibility Togglers
• Toggles visibility of certain things on/off • Simple API, small time saved but adds up • Emulates Visibility/Graphics menu • Allows use in keyboard shortcuts – Saves a number of clicks each time • Eased transition from Autodesk AutoCAD
Revit Technology Conference 2010
Visibility Togglers – Technical Details
• Used manifest file to make customizable toggles possible • Create KeyboardShortcut to External Tools menu • View.setVisibility method – Accepts category and visibility
Revit Technology Conference 2010
Quick Placer
• Keyboard shortcuts to place detail components • Similar to Autocad functionality • Custom shortcuts, not Revit shortcuts • Imports family if its not present
Revit Technology Conference 2010
Quick Placer – Technical Details
• Reads CSV file for shortcut details • Searches this based on user input • KeyPress event on Windows Form • 1 Character shortcut to open form • UiDocument. PromptForFamilyInstancePlacement
Revit Technology Conference 2010
Plan Copier
• Select Plan Type to use as base • Select the plans from that type to duplicate • Duplicates it for plan types in template • View types are setup in template, any version of Autodesk Revit
Revit Technology Conference 2010
Plan Copier – Technical Details
• Uses FilteredElementCollector.OfClass to get a ViewPlan • Then GetValidTypes() to get the types of plans in model • Gets ViewPlans with that Type • Document.Create.NewViewPlan to make new plan • newPlan.ApplyTemplate(originalView) to copy original • newPlan.ChangeTypeId(newTypeId)
Revit Technology Conference 2010
Detail Number Modifier
• Detail Number automatically set • Our numbering is done by View Name • Copies the View Name to the Detail Number • Does this for all Sections + Callouts on sheets
Revit Technology Conference 2010
Detail Number Modifier – Technical Details
• Uses a category filter with BuiltInCategory.OST_Sheets
• Loops sheets, and loops all Views in sheet.Views
• Retrieves View Name parameter from view.Parameters
• Sets Detail Number with parameter.Set
Revit Technology Conference 2010
Standard Sheet Setup
• Sets up sheets at start of project • Ensures standard names + numbering • Based on a text file with company standards • Saves time, typing and human error
Revit Technology Conference 2010
Standard Sheet Setup – Technical Details
• Reads text file line by line • Title Blocks from Document.TitleBlocks
• Document.Create.NewViewSheet
• newSheet.ViewName
• newSheet.SheetNumber
Revit Technology Conference 2010
• User selects elements • Only wants certain types • Runs tool, chooses types, • It changes selection
Selection Filter Revit Technology Conference 2010
Selection Filter – Technical Details
• Reads the categories and types of elements selected • Edits the UiDocument.Selection.Elements set
Revit Technology Conference 2010
Family Management
• System for managing and documenting families • Needed an efficient way of providing documentation • Old way (PDF version) was too much manual work • Multiple parts – Saver – saves metadata to files – Documenter – adds information + pictures to database – Documentation – Intranet page with live view of families – Reloader – Updates a project to have the latest families
Revit Technology Conference 2010
Family Management: Saver
• Writes metadata to family files • Automatically prompts and updates version number parameter • Stores Version, Date, Author, Editor • Breaks barrier between Autodesk Revit and ‘outside world’
Revit Technology Conference 2010
Family Management: Documenter
• Does initial import to database • Select a family file – Automatically gets a thumbnail – Can add more pictures – Add a comment
Revit Technology Conference 2010
Family Management: Documentation
• Web page with documentation on families • Retrieves all the information from the database • Reads metadata from files • Displays in easy to read and reference manner • Easily accessed from internal systems
Revit Technology Conference 2010
Family Management: Documentation Revit Technology Conference 2010
Family Management: Documentation Revit Technology Conference 2010
Family Management: Documentation Revit Technology Conference 2010
Family Management: Reloader
• Ensures the families in the model are the most up to date • Gives the option to replace any superseded families • Uses the metadata from library to compare to current families
Revit Technology Conference 2010
Family Management: Saver – Technical Details
• ExternalApplication that captures events – DocumentSaving, DocumentSavingAs – DocumentOpened, DocumentCreated, DocumentClosed • Gets/Updates the parameters when saving • Uses DSOFile.dll to store metadata after closed
Revit Technology Conference 2010
Family Management: Documenter Technical Details
• Guy Robinson has a thumbnail grabbing library on his blog • Can set which view for preview when saving • Imports to SQL database • Reads the text file with family for sizes
Revit Technology Conference 2010
Family Management: Documentation – Technical Details
• ASP.NET intranet site • Stored in SQL database • Uses a batch update of a database scheduled every night – So there’s no IO access done when user loads a page
Revit Technology Conference 2010
Family Management: Reloader – Technical Details
• Loops through the families loaded in the document • Find the matching family in the families database • Read the Version that was taken from the metadata in database • Compare with the matching parameter on family loaded • Give the user a list of families that have been updated • Use LoadFamiliy to replace if user selects it
Revit Technology Conference 2010
What others are doing
• Autodesk Revit Extensions • Import/Export to 3 rd party applications – Analysis Software – Cost Estimation Software • Room ReNumberer • Google Earth Export • Revit Content Browser/Importer
Revit Technology Conference 2010
What others are doing
• Room Phase Copier • Case Changer • Door Mark Updater • Sort and Mark tool • Wood Framing tools • Facilities Management • Avatech, Tools4Revit • RevitTv
Revit Technology Conference 2010
Where do I start?
• How do I start learning the Autodesk Revit API?
• Question I’ve been asked many times • There are a number of tools and resources for you to use • Handouts lists the ones I’ve mentioned here
Revit Technology Conference 2010
Learning Tools + Resources
• Started out fairly scarce • Now getting a lot better • Autodesk and the community actively trying to make it easier to learn • But you still have to be prepared to do some “trial and error”
Revit Technology Conference 2010
C# / VB.Net Resources
• First step is going to be to learn how to code in C# or VB.NET – Make a ‘hello world’ application in .NET first • Plenty of information online – MSDN – Stack Overflow • As well as lots of good books on C# – Read mainly the first few chapters – Head First C# (Stellman, Greene – O’Reilly)
Revit Technology Conference 2010
SDK Samples
• Lots of samples • Majority written in C# • Can do conversions online • A HTML file lists all of them (useful for searching) • An External Application puts them all on your ribbon
Revit Technology Conference 2010
Developers Guide eBook
• Shipped with SDK on disk • Very good overview • Easy to understand • Best place to start
Revit Technology Conference 2010
Compiled HTML Help File
• A CHM file is included with SDK • Technical documentation on the classes • Detailed descriptions and some examples • Learn the basics first
Revit Technology Conference 2010
Webcasts
• Dev TV introduction to API webcast recording • Regularly done live with question and answers • Do a little research into the basics before viewing • Check autodesk.com for new live webcasts
Revit Technology Conference 2010
Autodesk University
• AU Virtual • Previous years classes are available online • Download podcasts and listen to them whilst travelling to work
Revit Technology Conference 2010
Blogs
• The community is actively increasing the information out there • Best is ‘The Building Coder’ by Jeremy Tammik of Autodesk • Other great blogs: – Cad Application Development by Matt Mason – Revit Programming by Ed Pitt – Bolt out of the Red by Guy Robinson – Blog.RodHowarth.com
Revit Technology Conference 2010
Autodesk Revit API Search Engine
• Google custom search engine I set up • Only indexes API specific sites/blogs • Search for API specific information – Without the general clutter of the internet • http://revitapisearch.com
Revit Technology Conference 2010
Online Forums
• Great place for beginners • 2 main ones • AUGI Revit API Forums (most active) • Autodesk Discussion Group • Lots of helpful people to answer your queries • More importantly... lots of questions already asked!
Revit Technology Conference 2010
Autodesk Developer Network
• http://autodesk.com/adn • A must for all serious API developers.
• Direct line to Autodesk when you are stuck • If they can’t do it – chances are it’s not really possible.
• Works on a subscription model with online support and downloads
Revit Technology Conference 2010
RevitLookup
• Saved the best for last • This tool is essential to my API development work • Allows you to ‘snoop’ the database via the API.
• Pick an element, and see what properties and parameters are exposed via the API.
• First point of call • Available free online • Formerly known as RvtMgdDbg
Revit Technology Conference 2010
‘The Process’
• A number of steps that I generally follow when given a new task • Something to use once you’ve learnt the basics • This is ‘how to fish’
Revit Technology Conference 2010
1. Learn how to do it manually
• Generally you are trying to automate something • Rarely possible to do something you can’t manually do • What are the steps/menus to do it in Autodesk Revit?
Revit Technology Conference 2010
2. Identify key words / areas
• What were the menu names?
• What type of element are you working with?
• What is the functionality you are doing?
• Examples – Load Family – Beam – Level – Visibility
Revit Technology Conference 2010
3. RevitLookup
• Pick the elements you were manually choosing • Snoop the whole database and look for the keywords • Try and identify parameters or properties • If you can see the property here – you are in luck!
Revit Technology Conference 2010
4. Search SDK Samples + Developers Guide
• Use your key words to do a search • Windows can search inside .cs files • Can also use the solution with all samples • Or the HTML index of samples • If there is a sample, life just got easier!
Revit Technology Conference 2010
5. Search CHM
• Find more specifics on what you are after • Or use it as a refiner for your keywords – For if you haven’t had any luck yet – Do a search on variations of your keywords to find correct one • Gives you an idea of methods and how to use them
Revit Technology Conference 2010
6. Search online
• For if you are still out of luck or are confused • API search engine • AUGI forums • Autodesk Forums • ADN knowledge base
Revit Technology Conference 2010
7. IntelliSense / Experimentation
• If you have at least a starting point • Use IntelliSense to find your way through – Good for when you are using a sample as a base • Create a test application – Run it, use Message Boxes or Debug.Write to output info – VSTA can be helpful to avoid reloading Autodesk Revit
Revit Technology Conference 2010
8. ADN / Forums
• Reached the end of the line – still stuck • If you have ADN subscription, use DevHelp • Or AUGI forums can be a great, free, help • Usually takes a day or two for responses
Revit Technology Conference 2010
Conclusion
• The API is very powerful and can save you time + money!
• Big investment up front, but pays dividends • There is a lot of information out there nowadays – See your handouts for links • Buy pre-made • Hire a programmer • Or learn yourself!
• I will be at AEC booth if you want to chat
Revit Technology Conference 2010
Rod Howarth
Questions
... and don’t forget your survey form!
Revit Technology Conference 2010