and ThirdParty Applications David Rushforth PE LEED AP BDC Senior Electrical Engineer RG Vanderweil Engineers davidrushforthorg Presentation Expectations Have questions Please save them for after the presentation or send me an email ID: 612810
Download Presentation The PPT/PDF document "Opening the Lines of Communication Betwe..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
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
david@rushforth.orgSlide2
Presentation Expectations
Have questions?Please save them for after the presentation or send me an e-mailExperience LevelTopics are advancedExplanations are geared toward non-programmersDatabase communication onlyRevit API experience is (partially) assumed
GoalShare “the power of the possible”WARNINGThe 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.Slide3
About the Presenter
Electrical Engineer at R.G. Vanderweil EngineersNative to Las VegasBS Electrical Engineering, BYUMS Electrical Engineering, UNLVSlide4
Presentation Outline
Communication OverviewLines of CommunicationsText Based (Csv, Txt, XML, Ini, Dat)Microsoft Access
®SQLMicrosoft Excel®Autodesk AutoCAD®
Other Applications
Autodesk Revit
®
Another Approach: Microsoft Access® As Hub
Ideas For Further DevelopmentSlide5
Communication Overview
Autodesk AutoCAD
®
Microsoft Excel
®
SQL
Microsoft Access
®
Text
SKM Power Tools
Autodesk Revit
®Slide6
Lines of Communication: Text BasedSlide7
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 Key
Variable declarations
Supporting code
Read
WriteSlide8
Lines of Communication: Microsoft Access®Slide9
Lines of Communication: Microsoft Access®
Connect to database file for direct manipulationDim 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 StringreadFirstName = myEmployeesRecords.Fields
("FirstName").ValuemyEmployeesRecords.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 Key
Variable declarations
Supporting code
Read
WriteSlide10
Lines of Communication: SQLSlide11
Lines of Communication: SQL
Connect to database file for direct manipulationDim StrConnectionString As StringStrConnectionString
= "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 =
mySqlConnectionDim 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 WhilemySqlDataReader.Close()mySqlConnection.Close()
Color Key
Variable declarations
Supporting code
Read
WriteSlide12
Lines of Communication: Microsoft Excel®Slide13
Lines of Communication: Microsoft Excel®
Connect to Excel file for direct manipulationDim strXlsFile As StringstrXlsFile
= "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 StringreadValue =
mExcelWorksheet.Range("A1").ValuemExcelWorksheet.Range
("A2").Value = “New Value"mExcelWorkbook.Windows(1).Visible = TruemExcelWorkbook.Save
()mExcelWorkbook = NothingmExcelApplication.Quit()
mExcelApplication = Nothing
Color Key
Variable declarations
Supporting code
Read
WriteSlide14
Lines of Communication: Autodesk AutoCAD®Slide15
Lines of Communication: Autodesk AutoCAD®
DXF FilesText based file formatCan be written or editedScriptsAuto-run script on open AutoCADcadpath =
myApplicationFilePath & " /b " & ScriptNameDim ACADProcessID As Integer
ACADProcessID
= Shell(
cadpath
,
vbMaximizedFocus
)
LISP
Load a LISP routine during a script
s.WriteLine
("(load ""MyLispFilename.lsp"")")Slide16
Lines of Communication: Other ApplicationsSlide17
Lines of Communication: Other Applications
Identify ways of:Getting Data OutReports (txt, xls)Export optionsGetting Data InImport options
Proprietary extensions (e.g. .xyz) may be text basedSlide18
Lines of Communication: Autodesk Revit
®
.
addins
or Revit.ini
Ribbon.dll
Set References (RevitAPI.dll, etc.)
Create Ribbon Toolbar
Create Button1
-When pressed access class in RibbonCommands.dll
Create 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 Info
Class
SetPowerSuiteParams
-Set changed parameters
Class
ParameterXfmr
-Sort Project Elements
-Sort Selected Elements
-Open form
Class …
RibbonCommands.dll
AHKSlide19
Lines of Communication: Autodesk Revit®
Getting Data OutRead ParametersGetting Data InImport from textConnect to Database or TableExcel to DXFLink CAD drawings
Set ParametersLoad FamiliesCreate objectsAutomating the InterfaceAutoHotkey
(AHK) ScriptsSlide20
Another Approach: Microsoft Access® As Hub
Work flowSend data from Revit to Access® databaseAccess® stores and controls the flow of information between Revit and third party applications
BenefitsPerform advanced lookups and calculationsReview and change design outside of RevitCan send changes back to RevitSame interface for Revit and Non-Revit projectsSlide21
Integrated Program Example
Autodesk AutoCAD
®
Microsoft Excel
®
SKM Power Tools
Text
Autodesk Revit
®
Microsoft Access
®Slide22
Ideas For Further Development
Write custom reports from RevitWrite errors or standards deviations to journalsExport room dimensionsAutomate print settingsCreate sheets, objects, or families from stored dataExtract specific family types from projectCreate a keynote databaseAutomate riser diagrams
Create room or space schedules with error reportingSlide23
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.david@rushforth.orgSlide24
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.