Invalid Entity when setting extensible storage using Revit 2025 api

Invalid Entity when setting extensible storage using Revit 2025 api

rtejada
Contributor Contributor
314 Views
2 Replies
Message 1 of 3

Invalid Entity when setting extensible storage using Revit 2025 api

rtejada
Contributor
Contributor

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

0 Likes
315 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

AddSimpleField returns a FieldBuilder object. Maybe you need to call SetSpec and SetDocumentation on that, like in the sample code you point out.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

rtejada
Contributor
Contributor

Hi Jeremy, thanks for your fast response, I tried your suggestion,  did not work. Thanks again

0 Likes