opening the lines of communication between revit ® and third-party applications david rushforth,...

24
Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil Engineers [email protected]

Post on 19-Dec-2015

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Opening the Lines of Communication Between Revit® and Third-Party Applications

David Rushforth, PE, LEED AP BD+CSenior Electrical Engineer, R.G. Vanderweil [email protected]

Page 2: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Presentation Expectations

Have questions? Please save them for after the presentation or send me an e-mail

Experience Level Topics are advanced Explanations are geared toward non-programmers Database communication only

Revit API experience is (partially) assumed

Goal Share “the power of the possible”

WARNING The following content was prepared by an engineer, NOT a

programmer. The samples of code shown may contain disturbing examples of poor programming practices and represent only one of many ways to accomplish the desired objective.

Page 3: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

About the Presenter

Electrical Engineer at R.G. Vanderweil Engineers Native to Las Vegas BS Electrical Engineering, BYU MS Electrical Engineering, UNLV

Page 4: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Presentation Outline

Communication Overview Lines of Communications

Text Based (Csv, Txt, XML, Ini, Dat) Microsoft Access®

SQL Microsoft Excel®

Autodesk AutoCAD®

Other Applications Autodesk Revit®

Another Approach: Microsoft Access® As Hub Ideas For Further Development

Page 5: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Communication Overview

Autodesk AutoCAD ®

Microsoft Excel ®SQLMicrosoft Access ®

Text

SKM Power Tools

Autodesk Revit®

Page 6: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Text Based

Page 7: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Text Based

Write New File (Example formats: Csv, Txt, XML, Ini, Dat) Dim writefilename As String writefilename = "C:\[your path here]" Dim fs As New FileStream(writefilename, FileMode.Create, FileAccess.Write) Dim s As New StreamWriter(fs) s.WriteLine("Stuff") s.Close()

Read/Write/Edit existing File Data Code Dim FilePath As String FilePath = " C:\[your path here]" Dim text As Array Dim lines As New List(Of String) text = System.IO.File.ReadAllLines(FilePath) lines.AddRange(text) Dim n As Integer For n = 0 To lines.Count - 1 ‘[read, store, insert, or make decisions based on lines(n) ] Next n

Color KeyVariable declarationsSupporting codeReadWrite

Page 8: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Microsoft Access®

Page 9: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Microsoft Access®

Connect to database file for direct manipulation Dim strAccessFile As String = "C:\Temp\MyDatabase.accdb" Dim mAccessApplication As New Microsoft.Office.Interop.Access.Application mAccessApplication.OpenCurrentDatabase(strAccessFile) Dim myEmployeesRecords As dao.Recordset Dim TableName As String = "Employees" myEmployeesRecords = mAccessApplication.CurrentDb.OpenRecordset("SELECT * FROM " & TableName) myEmployeesRecords.MoveFirst() Dim readFirstName As String readFirstName = myEmployeesRecords.Fields("FirstName").Value myEmployeesRecords.Edit() myEmployeesRecords.Fields("FirstName").Value = "David" myEmployeesRecords.Fields("LastName").Value = "Rushforth" myEmployeesRecords.Update() mAccessApplication.Quit(Option:=Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone) mAccessApplication = Nothing

For 64-bit compatibility Copy dao360.dll to Revit “Program” folder

Color KeyVariable declarationsSupporting codeReadWrite

Page 10: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: SQL

Page 11: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: SQL

Connect to database file for direct manipulation Dim StrConnectionString As String StrConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Temp\TestDatabase.mdf;Integrated

Security=True;User Instance=True“ Dim mySqlConnection As New SqlConnection(StrConnectionString) Dim mySqlCommand As New SqlCommand mySqlConnection.Open() mySqlCommand.Connection = mySqlConnection Dim TableName As String = "Employees“ mySqlCommand.CommandText = "SELECT * FROM " & TableName mySqlCommand.CommandText = "UPDATE " & TableName & " SET

FirstName='EditedFirstName',LastName='EditedLastName' WHERE (NameID= 1234)“ mySqlCommand.CommandText = "SELECT * FROM " & TableName & " WHERE (FirstName='FirstName1')“ mySqlCommand.ExecuteNonQuery() ‘RUN THIS AFTER EACH .CommandText Dim mySqlDataReader As SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader While mySqlDataReader.Read() 'While Data is Present MsgBox(mySqlDataReader("FirstName") & ", " & mySqlDataReader("LastName")) End While mySqlDataReader.Close() mySqlConnection.Close()

Color KeyVariable declarationsSupporting codeReadWrite

Page 12: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Microsoft Excel®

Page 13: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Microsoft Excel®

Connect to Excel file for direct manipulation Dim strXlsFile As String strXlsFile = "C:\Temp\test.xls" Dim mExcelApplication As New Microsoft.Office.Interop.Excel.Application Dim mExcelWorkbook As Microsoft.Office.Interop.Excel.Workbook = mExcelApplication.Workbooks.Open(strXlsFile) Dim mExcelWorksheet As Microsoft.Office.Interop.Excel.Worksheet = mExcelWorkbook.Worksheets(1) Dim readValue As String readValue = mExcelWorksheet.Range("A1").Value mExcelWorksheet.Range("A2").Value = “New Value" mExcelWorkbook.Windows(1).Visible = True mExcelWorkbook.Save() mExcelWorkbook = Nothing mExcelApplication.Quit() mExcelApplication = Nothing

Color KeyVariable declarationsSupporting codeReadWrite

Page 14: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Autodesk AutoCAD®

Page 15: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Autodesk AutoCAD®

DXF Files Text based file format Can be written or edited

Scripts Auto-run script on open AutoCAD

cadpath = myApplicationFilePath & " /b " & ScriptName Dim ACADProcessID As Integer ACADProcessID = Shell(cadpath, vbMaximizedFocus)

LISP Load a LISP routine during a script

s.WriteLine("(load ""MyLispFilename.lsp"")")

Page 16: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Other Applications

Page 17: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Other Applications

Identify ways of: Getting Data Out

Reports (txt, xls) Export options

Getting Data In Import options

Proprietary extensions (e.g. .xyz) may be text based

Page 18: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Autodesk Revit®

.addins or Revit.ini

Ribbon.dll

Set References (RevitAPI.dll, etc.)Create Ribbon ToolbarCreate Button1 -When pressed access class in RibbonCommands.dllCreate Button2 -…

References (Revit API)RevitAPI.dll, RevitAPIUI.dll

Load dll on startup

Set References (RevitAPI.dll, etc.)Class PowerSuite -Gather Param info -Open Power Suite -Transfer InfoClass SetPowerSuiteParams -Set changed parametersClass ParameterXfmr -Sort Project Elements -Sort Selected Elements -Open formClass …

RibbonCommands.dll

AHK

Page 19: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Lines of Communication: Autodesk Revit®

Getting Data Out Read Parameters

Getting Data In Import from text Connect to Database or Table Excel to DXF Link CAD drawings Set Parameters Load Families Create objects

Automating the Interface AutoHotkey (AHK) Scripts

Page 20: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Another Approach: Microsoft Access® As Hub

Work flow Send data from Revit to Access® database Access® stores and controls the flow of information between Revit and

third party applications Benefits

Perform advanced lookups and calculations Review and change design outside of Revit

Can send changes back to Revit Same interface for Revit and Non-Revit projects

Page 21: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Integrated Program Example

Autodesk AutoCAD ®

Microsoft Excel ®

SKM Power ToolsText

Autodesk Revit®

Microsoft Access®

Page 22: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

Ideas For Further Development

Write custom reports from Revit Write errors or standards deviations to journals Export room dimensions Automate print settings Create sheets, objects, or families from stored data Extract specific family types from project Create a keynote database Automate riser diagrams Create room or space schedules with error reporting

Page 23: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

THANK YOU!

If you liked it… Fill out the online class survey.

If this will help you in your work… Send me an email and let me know how it helped.

If you have questions… Ask now or send me an e-mail later. [email protected]

Page 24: Opening the Lines of Communication Between Revit ® and Third-Party Applications David Rushforth, PE, LEED AP BD+C Senior Electrical Engineer, R.G. Vanderweil

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.