Schema - How To Read and Write

Hey, I am trying to access a Schema from the Extensible Storage, and read / write to a field within it.

Please excuse my limited understanding of how this all works.

I have used archilab to get the schema i want to read from (the schema has full read/write access).
How do I got about listing it’s fields and reading the data within them?
Also how do I then change the value in the fields?

Here is what I get when retrieving the Schema’s field by name:


For some reason says error on line 56. It is really on line 33(32).

Here is what I get when trying to collect the Schema by using GetEntity on the Project Information element in which the data is saved:

@andre.abotnes I don’t think you can do it like that. Custom Zero Touch nodes don’t have the same UnwrapElement functionality as the ones that come with Dynamo. It’s just one of the many limitations. Basically it comes from the fact that Schema is not part of the Element class tree. It’s a different kind of object. Anyways, I think there are two ways to achieve what you want here:

  • either use Python to retrieve the Schema, and then edit it. If you are getting it from Revit directly in Python then it won’t be wrapped into archi-lab class.
  • or I would have to extend archi-lab.net packages with a few extra nodes to allow for read/write access to schema. Technically it doesn’t have to be me. It could be anyone. archi-lab.net is open source.
2 Likes

UPDATE:

Thanks to @Konrad_K_Sobon for helping me figure this out:
Solution was to specify datatype in entity.get.
entity.Get[str](fieldname)

ORIGINAL POST:

Thanks for the reply @Konrad_K_Sobon, that got me going.
Now I have trouble understanding the Entity.Get method, and how to make use of it with python.
I both want to get and set, but I guess they both work the same way.
Any good tips on how to proceed?

# André Abotnes andre.abotnes@norconsult.com
import sys
import clr

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

# Import List ( ICollection(ElementId) = List[ElementId]() )
clr.AddReference('System')
from System.Collections.Generic import List

# Import Revit API + APIUI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.ExtensibleStorage import *

OUT = []
projectInfo = UnwrapElement(IN[0][0])
schemas = Schema.ListSchemas()

for schm in schemas:
	if schm.SchemaName == IN[1]:
		entity = projectInfo.GetEntity(schm)
		OUT = entity.Get("FilePath")

FYI: The package Pack and Play contains a few python examples for working with extensible storage via Python. Feel free to refer to it as it helps.

https://dynamopackages.com/download/e3022155-6adc-4e9b-96b7-2e47d3aa8ccd/0.0.2

2 Likes

Hot tip! Thanks alot!
image

1 Like