I am trying to take advantage of ExtensibleStorage in the Revit API. I'm trying to store an Array in a ArrayField. I think maybe my errors are due to the IronPython interface, but maybe someone has done this successfully? I know that the object to set i supposed to be an IList, but I can't seem to make one. In the IronPython documentation, the Array-object is used as an example. If I try this: vl = IList[ElementId]([v.ViewId for v in views])
I get a Systemerror:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: MakeGenericType on non-generic type
This is my code:
from System import Guid, Array
from Autodesk.Revit.DB.ExtensibleStorage import *
guid = Guid.NewGuid()
views = revit.uidoc.GetOpenUIViews()
vl = Array[ElementId]([v.ViewId for v in views])
schemaBuilder = SchemaBuilder(guid)
schemaBuilder.SetReadAccessLevel(AccessLevel.Public)
schemaBuilder.SetWriteAccessLevel(AccessLevel.Public)
schemaBuilder.SetSchemaName('Testing')
schemaBuilder.AddArrayField('Views', ElementId)
schema = schemaBuilder.Finish()
entity = Entity(schema)
entity.Set('Views', vl)
And this is my error message:
Exception : Autodesk.Revit.Exceptions.InvalidOperationException: Unsupported type: Autodesk.Revit.DB.ElementId[]
at Autodesk.Revit.DB.ExtensibleStorage.Entity.Set[FieldType](String fieldName, FieldType value, ForgeTypeId unitTypeId)
at Autodesk.Revit.DB.ExtensibleStorage.Entity.Set[FieldType](String fieldName, FieldType value)
BTW: This is working fine:
from System import Guid, Array
from Autodesk.Revit.DB.ExtensibleStorage import *
guid = Guid.NewGuid()
views = revit.uidoc.GetOpenUIViews()
v = views[0].ViewId
schemaBuilder = SchemaBuilder(guid)
schemaBuilder.SetReadAccessLevel(AccessLevel.Public)
schemaBuilder.SetWriteAccessLevel(AccessLevel.Public)
schemaBuilder.SetSchemaName('Testing')
schemaBuilder.AddSimpleField('Views', ElementId)
schema = schemaBuilder.Finish()
entity = Entity(schema)
entity.Set('Views', v)
To get the value: entity.Get[ElementId]('Views')
I think I had the same trouble with AddArrayField in c#, and was probably doing something wrong but my quick fix solution was to simply use AddMapField.