Invalid Entity when setting extensible storage using Revit 2025 api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone
I am following help article https://help.autodesk.com/view/RVT/2025/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Advanced_Topi...
I have the next code
Public Sub SetDocOfflineKey(ByVal docItem As Document, ByVal url As String)
Using t As New Transaction(docItem, "MyStorage")
t.Start()
Dim collector As New FilteredElementCollector(docItem)
Dim myDataStorage As Element = collector.OfClass(GetType(DataStorage)).FirstElement
Dim myEntity As Entity
If myDataStorage Is Nothing Then
myDataStorage = DataStorage.Create(docItem)
myEntity = New Entity(GetSchema)
Else
myEntity = myDataStorage.GetEntity(GetSchema)
End If
myEntity.Set("CheckOutSourceUrl", url) 'here it fails
myDataStorage.SetEntity(myEntity)
t.Commit()
End Using
End Sub
Private Function GetSchema() As Schema
Static Dim mySchema As Schema
If mySchema Is Nothing Then
Dim schemaGuid As Guid = New Guid("{9DBE0174-AA01-4CDD-BA86-96DE1FDCE148}")
mySchema = Schema.Lookup(schemaGuid)
If mySchema Is Nothing Then
Dim schemaBuilder As New SchemaBuilder(schemaGuid)
schemaBuilder.SetSchemaName("MyStorage")
schemaBuilder.SetWriteAccessLevel(ExtensibleStorage.AccessLevel.Public)
schemaBuilder.SetReadAccessLevel(ExtensibleStorage.AccessLevel.Public)
schemaBuilder.AddSimpleField("CheckOutSourceUrl", GetType(String))
Return schemaBuilder.Finish
Else
Return mySchema
End If
Else
Return mySchema
End If
End Function
The above code throw the exception "The entity is invalid" at the myEntity.Set("CheckOutSourceUrl", url) line above. It works for all previous Revit api ( at least 2018 - 2024)
I am wondering if something extra needs to be done with this version
Your help is much appreciated