Skip to content

Commit cac32cc

Browse files
author
Jeremy Tammik
authored
Merge pull request #10 from NK29/master
Revit 2022 Migration
2 parents afaf9b3 + 8824d44 commit cac32cc

34 files changed

+122
-120
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2020 Jeremy Tammik
3+
Copyright (c) 2015-2021 Jeremy Tammik
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
77 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Labs/1_Revit_API_Intro/SourceCS/IntroCs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
</PropertyGroup>
6060
<ItemGroup>
6161
<Reference Include="RevitAPI">
62-
<HintPath>C:\Program Files\Autodesk\Revit 2021\RevitAPI.dll</HintPath>
62+
<HintPath>C:\Program Files\Autodesk\Revit 2022\RevitAPI.dll</HintPath>
6363
<Private>False</Private>
6464
</Reference>
6565
<Reference Include="RevitAPIUI">
66-
<HintPath>C:\Program Files\Autodesk\Revit 2021\RevitAPIUI.dll</HintPath>
66+
<HintPath>C:\Program Files\Autodesk\Revit 2022\RevitAPIUI.dll</HintPath>
6767
<Private>False</Private>
6868
</Reference>
6969
<Reference Include="System" />

Labs/1_Revit_API_Intro/SourceCS/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion( "2021.0.0.3" )]
36-
[assembly: AssemblyFileVersion( "2021.0.0.3" )]
35+
[assembly: AssemblyVersion( "2022.0.0.0" )]
36+
[assembly: AssemblyFileVersion( "2022.0.0.0" )]

Labs/1_Revit_API_Intro/SourceVB/6_ExtensibleStorage.vb

Lines changed: 104 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -50,166 +50,168 @@ Imports IntroVb.Util
5050
''' </summary>
5151
<Transaction(TransactionMode.Manual)> _
5252
Friend Class ExtensibleStorage
53-
Implements IExternalCommand
53+
Implements IExternalCommand
5454

55-
''' <summary>
56-
''' The schema specific GUID.
57-
''' </summary>
58-
Private _guid As Guid = New Guid("87aaad89-6f1b-45e1-9397-2985e1560a02")
55+
''' <summary>
56+
''' The schema specific GUID.
57+
''' </summary>
58+
Private _guid As Guid = New Guid("87aaad89-6f1b-45e1-9397-2985e1560a02")
5959

60-
''' <summary>
61-
''' Allow only walls to be selected.
62-
''' </summary>
63-
Private Class WallSelectionFilter
64-
Implements ISelectionFilter
60+
''' <summary>
61+
''' Allow only walls to be selected.
62+
''' </summary>
63+
Private Class WallSelectionFilter
64+
Implements ISelectionFilter
6565

66-
Public Function AllowElement(ByVal e As Element) As Boolean Implements ISelectionFilter.AllowElement
67-
Return TypeOf e Is Wall
68-
End Function
66+
Public Function AllowElement(ByVal e As Element) As Boolean Implements ISelectionFilter.AllowElement
67+
Return TypeOf e Is Wall
68+
End Function
6969

70-
Public Function AllowReference(ByVal r As Reference, ByVal p As XYZ) As Boolean Implements ISelectionFilter.AllowReference
71-
Return True
72-
End Function
70+
Public Function AllowReference(ByVal r As Reference, ByVal p As XYZ) As Boolean Implements ISelectionFilter.AllowReference
71+
Return True
72+
End Function
7373

74-
End Class
74+
End Class
7575

76-
Public Function Execute( _
77-
ByVal commandData As ExternalCommandData, _
78-
ByRef message As String, _
76+
Public Function Execute(
77+
ByVal commandData As ExternalCommandData,
78+
ByRef message As String,
7979
ByVal elements As ElementSet) _
8080
As Result _
8181
Implements IExternalCommand.Execute
8282

83-
Dim uiDoc As UIDocument = commandData.Application.ActiveUIDocument
84-
Dim doc As Document = uiDoc.Document
83+
Dim uiDoc As UIDocument = commandData.Application.ActiveUIDocument
84+
Dim doc As Document = uiDoc.Document
8585

86-
' Create transaction for working with schema
86+
' Create transaction for working with schema
8787

88-
Dim trans As New Transaction(doc, "Extensible Storage")
89-
trans.Start()
88+
Dim trans As New Transaction(doc, "Extensible Storage")
89+
trans.Start()
9090

91-
' Select a wall element
91+
' Select a wall element
9292

93-
Dim wall As Wall = Nothing
94-
Try
95-
Dim r As Reference = uiDoc.Selection.PickObject(ObjectType.Element, New WallSelectionFilter)
96-
wall = TryCast(doc.GetElement(r), Wall)
97-
Catch exception1 As Autodesk.Revit.Exceptions.OperationCanceledException
98-
message = "Nothing selected; please select a wall to attach extensible data to."
99-
Return Result.Failed
100-
End Try
93+
Dim wall As Wall = Nothing
94+
Try
95+
Dim r As Reference = uiDoc.Selection.PickObject(ObjectType.Element, New WallSelectionFilter)
96+
wall = TryCast(doc.GetElement(r), Wall)
97+
Catch exception1 As Autodesk.Revit.Exceptions.OperationCanceledException
98+
message = "Nothing selected; please select a wall to attach extensible data to."
99+
Return Result.Failed
100+
End Try
101101

102-
Debug.Assert(wall IsNot Nothing, "expected a wall to be selected")
102+
Debug.Assert(wall IsNot Nothing, "expected a wall to be selected")
103103

104-
If wall Is Nothing Then
105-
message = "Please select a wall to attach extensible data to."
106-
Return Result.Failed
107-
End If
104+
If wall Is Nothing Then
105+
message = "Please select a wall to attach extensible data to."
106+
Return Result.Failed
107+
End If
108108

109-
' Create a schema builder
109+
' Create a schema builder
110110

111-
Dim builder As New SchemaBuilder(_guid)
111+
Dim builder As New SchemaBuilder(_guid)
112112

113-
' Set read and write access levels
113+
' Set read and write access levels
114114

115-
builder.SetReadAccessLevel(AccessLevel.Public)
116-
builder.SetWriteAccessLevel(AccessLevel.Public)
115+
builder.SetReadAccessLevel(AccessLevel.Public)
116+
builder.SetWriteAccessLevel(AccessLevel.Public)
117117

118-
' Note: if this was set as vendor or application access,
119-
' we would have been additionally required to use SetVendorId
118+
' Note: if this was set as vendor or application access,
119+
' we would have been additionally required to use SetVendorId
120120

121-
' Set name to this schema builder
121+
' Set name to this schema builder
122122

123-
builder.SetSchemaName("WallSocketLocation")
124-
builder.SetDocumentation("Data store for socket related info in a wall")
123+
builder.SetSchemaName("WallSocketLocation")
124+
builder.SetDocumentation("Data store for socket related info in a wall")
125125

126-
' Create field1
126+
' Create field1
127127

128128
Dim fieldBuilder1 As FieldBuilder =
129129
builder.AddSimpleField("SocketLocation", GetType(XYZ))
130130

131131
' .SetSpec(SpecTypeId.Length) ' 2021
132132
' GetType(XYZ)).SetUnitType(UnitType.UT_Length) ' 2020
133133

134-
' Set unit type
134+
' Set unit type
135135

136-
'fieldBuilder1.SetUnitType(UnitType.UT_Length) ' 2020
137-
fieldBuilder1.SetSpec(SpecTypeId.Length) ' 2021
136+
fieldBuilder1.SetSpec(SpecTypeId.Length) ' 2022
138137

139-
' Add documentation (optional)
138+
'fieldBuilder1.SetUnitType(UnitType.UT_Length) ' 2020
139+
fieldBuilder1.SetSpec(SpecTypeId.Length) ' 2021
140140

141-
' Create field2
141+
' Add documentation (optional)
142142

143-
Dim fieldBuilder2 As FieldBuilder = _
143+
' Create field2
144+
145+
Dim fieldBuilder2 As FieldBuilder =
144146
builder.AddSimpleField("SocketNumber", GetType(String))
145147

146-
'fieldBuilder2.SetUnitType(UnitType.UT_Custom);
148+
'fieldBuilder2.SetUnitType(UnitType.UT_Custom);
147149

148-
' Register the schema object
150+
' Register the schema object
149151

150-
Dim schema As Schema = builder.Finish
152+
Dim schema As Schema = builder.Finish
151153

152-
' Create an entity (object) for this schema (class)
154+
' Create an entity (object) for this schema (class)
153155

154-
Dim ent As New Entity(schema)
155-
Dim socketLocation As Field = schema.GetField("SocketLocation")
156-
'ent.Set(Of XYZ)(socketLocation, New XYZ(2, 0, 0), DisplayUnitType.DUT_METERS) ' 2020
157-
ent.Set(Of XYZ)(socketLocation, New XYZ(2, 0, 0), UnitTypeId.Meters) ' 2021
156+
Dim ent As New Entity(schema)
157+
Dim socketLocation As Field = schema.GetField("SocketLocation")
158+
'ent.Set(Of XYZ)(socketLocation, New XYZ(2, 0, 0), DisplayUnitType.DUT_METERS) ' 2020
159+
ent.Set(Of XYZ)(socketLocation, New XYZ(2, 0, 0), UnitTypeId.Meters) ' 2021
158160

159-
Dim socketNumber As Field = schema.GetField("SocketNumber")
160-
ent.Set(Of String)(socketNumber, "200")
161+
Dim socketNumber As Field = schema.GetField("SocketNumber")
162+
ent.Set(Of String)(socketNumber, "200")
161163

162-
wall.SetEntity(ent)
164+
wall.SetEntity(ent)
163165

164-
' Now create another entity (object) for this schema (class)
166+
' Now create another entity (object) for this schema (class)
165167

166-
Dim ent2 As New Entity(schema)
167-
Dim socketNumber1 As Field = schema.GetField("SocketNumber")
168-
ent2.Set(Of String)(socketNumber1, "400")
169-
wall.SetEntity(ent2)
168+
Dim ent2 As New Entity(schema)
169+
Dim socketNumber1 As Field = schema.GetField("SocketNumber")
170+
ent2.Set(Of String)(socketNumber1, "400")
171+
wall.SetEntity(ent2)
170172

171-
' Note: this will replace the previous entity on the wall
173+
' Note: this will replace the previous entity on the wall
172174

173-
' List all schemas in the document
175+
' List all schemas in the document
174176

175-
Dim s As String = String.Empty
176-
Dim schemas As IList(Of Schema) = schema.ListSchemas
177-
Dim sch As Schema
178-
For Each sch In schemas
179-
s += vbCrLf + "Schema name: " + sch.SchemaName
180-
Next
181-
TaskDialog.Show("Schema details", s)
177+
Dim s As String = String.Empty
178+
Dim schemas As IList(Of Schema) = Schema.ListSchemas
179+
Dim sch As Schema
180+
For Each sch In schemas
181+
s += vbCrLf + "Schema name: " + sch.SchemaName
182+
Next
183+
TaskDialog.Show("Schema details", s)
182184

183-
' List all Fields for our schema
185+
' List all Fields for our schema
184186

185-
s = String.Empty
186-
Dim fields As IList(Of Field) = schema.Lookup(_guid).ListFields
187-
Dim fld As Field
188-
For Each fld In fields
189-
s += vbCrLf + "Field name: " + fld.FieldName
190-
Next
191-
TaskDialog.Show("Field details", s)
187+
s = String.Empty
188+
Dim fields As IList(Of Field) = Schema.Lookup(_guid).ListFields
189+
Dim fld As Field
190+
For Each fld In fields
191+
s += vbCrLf + "Field name: " + fld.FieldName
192+
Next
193+
TaskDialog.Show("Field details", s)
192194

193-
' Extract the value for the field we created
195+
' Extract the value for the field we created
194196

195-
Dim wallSchemaEnt As Entity = wall.GetEntity(schema.Lookup(_guid))
197+
Dim wallSchemaEnt As Entity = wall.GetEntity(Schema.Lookup(_guid))
196198

197-
Dim wallSocketPos As XYZ = wallSchemaEnt.Get(Of XYZ)(
199+
Dim wallSocketPos As XYZ = wallSchemaEnt.Get(Of XYZ)(
198200
Schema.Lookup(_guid).GetField("SocketLocation"),
199201
UnitTypeId.Meters) ' 2021
200-
' DisplayUnitType.DUT_METERS) ' 2020 _
202+
' DisplayUnitType.DUT_METERS) ' 2020 _
201203

202-
s = "SocketLocation: " + Format.PointString(wallSocketPos)
204+
s = "SocketLocation: " + Format.PointString(wallSocketPos)
203205

204-
Dim wallSocketNumber As String = wallSchemaEnt.Get(Of String)( _
205-
schema.Lookup(_guid).GetField("SocketNumber"))
206+
Dim wallSocketNumber As String = wallSchemaEnt.Get(Of String)(
207+
Schema.Lookup(_guid).GetField("SocketNumber"))
206208

207-
s += vbCrLf + "SocketNumber: " + wallSocketNumber
209+
s += vbCrLf + "SocketNumber: " + wallSocketNumber
208210

209-
TaskDialog.Show("Field Values", s)
211+
TaskDialog.Show("Field Values", s)
210212

211-
trans.Commit()
213+
trans.Commit()
212214

213-
Return Result.Succeeded
214-
End Function
215-
End Class
215+
Return Result.Succeeded
216+
End Function
217+
End Class

Labs/1_Revit_API_Intro/SourceVB/IntroVb.vbproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
</PropertyGroup>
6565
<ItemGroup>
6666
<Reference Include="RevitAPI">
67-
<HintPath>C:\Program Files\Autodesk\Revit 2021\RevitAPI.dll</HintPath>
67+
<HintPath>C:\Program Files\Autodesk\Revit 2022\RevitAPI.dll</HintPath>
6868
<Private>False</Private>
6969
</Reference>
7070
<Reference Include="RevitAPIUI">
71-
<HintPath>C:\Program Files\Autodesk\Revit 2021\RevitAPIUI.dll</HintPath>
71+
<HintPath>C:\Program Files\Autodesk\Revit 2022\RevitAPIUI.dll</HintPath>
7272
<Private>False</Private>
7373
</Reference>
7474
<Reference Include="System" />

Labs/1_Revit_API_Intro/SourceVB/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("2021.0.0.3")>
35-
<Assembly: AssemblyFileVersion("2021.0.0.3")>
34+
<Assembly: AssemblyVersion("2022.0.0.0")>
35+
<Assembly: AssemblyFileVersion("2022.0.0.0")>

0 commit comments

Comments
 (0)