Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Pushing Revit to the Next Level:

An Intro to Revit Plugins with C#


Jeremy Graham
Computational Design Leader
© HDR, Inc., all rights reserved.
1917
Year established

229
Global Offices

9,648
Employee-owners

1,761
Architects
© HDR, Inc., all rights reserved.
Learn Dynamo LinkedIn Learning Development
Dynamo lessons focusing on applying Revit lessons focusing on Build plugins for Revit, Rhino,
Python to tap into the Revit API developing Revit plugins with C# Grasshopper, Dynamo and web
applications.
Learning Objectives
1 Understand how to access the Revit API with C# by
C#
learning the basics of the programming language.

2 Understand how to build a Revit plug-in using Visual


Visual Studio
Studio

3 Find different areas of the Revit API to use with C# to


learn how to work with Revit Elements.

Revit API
4 Learn how to create and use Revit API objects when
creating Revit plug-ins such as Revit Parameters and
FilteredElelementCollectors.
Building Plugins
Building Plugins
What is C#?

Programming Language
High-level
General purpose
Object-Oriented
Building Plugins
Why C#?

Programming Language

.NET Framework
Framework for developing with Windows
Building Plugins
How with C#?

Programming Language

.NET Framework

The Revit API


Provides access to Revit via Plugins
C# Key Concepts
C# Key Concepts
Everything is an Object

Properties Methods
Describe the Object Allow the object to do something.
e.g. Colour, sex, age. e.g. Meow, sit, judge.

Cat
1
2
3 Classes
4 The Blueprint of Objects
5
6 public class Cat Class
7 { Defines the object
8 public string Color { get; private set; }
9 public int Age { get; set; }
10
11 public Cat(String color, int age)
12 {
13 Color = color;
14 Age = age;
15 }
16
17 public string Meow()
18 {
19 return “Meow”;
20 }
21 }
22
23
24
1
2
3
Modifier
Type
Name
Classes
4 The Blueprint of Objects
5
6 public class Cat Declare Class
7 { Defines class named Cat
8 public string Color { get; private set; } Members
9 public int Age { get; set; } Methods and Properties
10 of the class
11 public Cat(String color, int age)
12 {
13 Color = color; Start Statement Block
14 Age = age;
15 }
16
17 public string Meow()
18 {
19 return “Meow”;
20 }
21 }
22
End Statement Block
23
24
1
2
3
Type Statement Block Classes
4 The Blueprint of Objects
Name
5
6 public class Cat
7 {
8 public string Color { get; private set; } Properties
9 public int Age { get; set; } Cat characteristics
10
11 public Cat(String color, int age)
12 {
13 Color = color;
14 Age = age;
15 }
16
17 public string Meow()
18 {
19 return “Meow”;
20 }
21 }
22
23
24
1
2
3 Classes
4 The Blueprint of Objects
5
6 public class Cat
7 { Method Parameters
8 public string Color { get; private set; }
9 public int Age { get; set; }
10
11 public Cat(String color, int age) Constructor Method
12 { Method to create a Cat
13 Color = color; object
14 Age = age;
15 } Colon Ends Assignment Statement
16
17 public string Meow() Object Method
18 { Cat object actions
19 return “Meow”;
20 }
21 }
22
Return Value
23
24
1
2
3
Type
Classes
4 Creating an Object
Variable
5
6
7
8 Cat Maggie = new Cat(“Grey”, 2); Instantiate Cat Object
9 Creates Cat Object
10 string speak = Maggie.Meow();
11
12 Maggie.Age = 3;
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3 Classes
4 Calling Methods
5 Dot Notation
6
7
8 Cat Maggie = new Cat(“Grey”, 2);
9
10 string speak = Maggie.Meow(); Call Method
11 Cat Object Meows
12 Maggie.Age = 3;
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3 Classes
4 Accessing Properties
5
6
7
8 Cat Maggie = new Cat(“Grey”, 2);
9
10 string speak = Maggie.Meow();
11
12 Maggie.Age = 3; Reassign Property
13 Age updated
14
15
16
Assignment
17
18
19
20
21
22
23
24
C# Data Types
1
2
3
Comment
C# Data Types
4 Strings, Numbers and Booleans
5
6
7 //Strings (text)
8 string name = “Molly”;
9
10 //Numbers (Integer and Double)
11 int integer = 1;
12 double dub = 1.0;
13
14 //Booleans (True or False)
15 bool t = true;
16 bool f = false;
17
18
19
20
21
22
23
24
1
2
3 Data Types
4 Lists and Enumerations
List Data Type
5
6
7 //Lists
8 List<Cat> Cats = new List<Cat>();
9 Cat Object
10 //Add a Cat to the list.
11 Cat Molly = new Cat();
12 Cats.Add(Molly);
Adding Cat Object to List
13 Declaring Enumeration
14 //Enumerations
15 enum Month { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
16
17 //Assign an enum value
18 Month month = Month.Mar;
19
20
21
22
Enum Accessed via Dot Notation

23
24
1
2
3
Empty List to Add to
Working with Data
4 Temporary Variable Looping
5
6 Color Retrieved
7 //Looping
8 List<string> Colors = new List<string>(); //Empty List
Empty String List
9
10 foreach (Cat c in Cats)
11 {
12 string color = c.Color; //Retrieve Cat Color from Property
13 Colors.Add(color); //Add to List Grey
14 }
c
15
16
17 Color Added to List
18
19
20
21
22 List of Cats
23
24
1
2
3
Empty List to Add to
Working with Data
4 Temporary Variable Looping
5
6 Color Retrieved
7 //Looping
8 List<string> Colors = new List<string>(); //Empty List
Empty String List
9
10 foreach (Cat c in Cats)
11 {
12 string color = c.Color; //Retrieve Cat Color from Property
13 Colors.Add(color); //Add to List Orange
14 }
c
15
16
17 Color Added to List
18
19
20
21
22 List of Cats
23
24
1
2
3
Empty List to Add to
Working with Data
4 Temporary Variable Looping
5
6 Color Retrieved
7 //Looping
8 List<string> Colors = new List<string>(); //Empty List
Empty String List
9
10 foreach (Cat c in Cats)
11 {
12 string color = c.Color; //Retrieve Cat Color from Property
13 Colors.Add(color); //Add to List Black
14 }
c
15
16
17 Color Added to List
18
19
20
21
22 List of Cats
23
24
1
2
3
Empty List to Add to
Working with Data
4 Temporary Variable Looping
5
6 Color Retrieved
7 //Looping
8 List<string> Colors = new List<string>(); //Empty List
Empty String List
9
10 foreach (Cat c in Cats)
11 {
12 string color = c.Color; //Retrieve Cat Color from Property
13 Colors.Add(color); //Add to List Orange
14 }
c
15
16
17 Color Added to List
18
19
20
21
22 List of Cats
23
24
The Revit API
Application Programming Interface
A set of operations provided by a piece of software, web
application or web service that allow other applications to
interact with them.
The Revit API
Dining with Revit

Customer Waiter Kitchen


The Revit API
Dining with Revit

Customer Waiter Kitchen


Revit Plugin Revit API Revit
The Revit API
Dining with Revit

Request

Customer Waiter Kitchen


Revit Plugin Revit API Revit
The Revit API
Dining with Revit

Request

Response

Customer Waiter Kitchen


Revit Plugin Revit API Revit
The Revit API
Dining with Revit

Request

Response

Customer Waiter Kitchen


Revit Plugin Revit API Revit
Exercise One
Creating a Revit Plugin
Exercise Two
Filtering for Elements
Exercise Three
Updating the Model
@Learndynamo linkedin.com/in/jeremy--graham/

Autodesk and the Autodesk logo 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.
© 2018 Autodesk. All rights reserved.

You might also like