More extensible storage confusion :D

I’ve set my field ‘i1’ to have a string parameter which is “20, 20, 32, 68” as you can see at index[1] on the first Python codeblock.

I’m wanting to read the same field’s parameter in the next codeblock… But as you can see it’s magically empty!

I tried adding some pass through nodes (delay) but that didn’t help.
What/ how/ why?

You will need to show more of the script and code to be able to get some help. But i will ask is the first set of notes applying a change into review before you then do something else later on?

If yes then you need to save the transaction and re-get the data out afterwards, or better is to follow that data into the next nodes going forward.

1 Like

Ah… so I have to commit it…

Ty :slight_smile:

Only started playing with it this week… steep learning curve and very little documentation in Python!

EDIT… wait… isn’t setting committing it?
Or does it have to be applied to an object in Revit to ‘fix’ it?

The commit is the command actually running in Revit. Setting the value in python just “sets up” the API to run those commands once the transaction happens in Revit. Because Dynamo automatically wraps everything into a single transaction (commit), the set and read happen at the same time. So the value hasn’t actually been changed in Revit when it’s being read. A second transaction ensures that the value gets set and committed before the second transaction begins the read process.

1 Like

image

I am setting my entities in the “Fields populate” python block

I am trying to read my entities in “Fields read” python block.

Code from first block below:


import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference('RevitAPIUI')

from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ObjectType
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System

Series = "68"
schemaId = IN[1][2]

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
TransactionManager.Instance.EnsureInTransaction(doc)
schema = ExtensibleStorage.Schema.Lookup(schemaId)
entity = ExtensibleStorage.Entity(schema)

#Read the first field to find out what index there is a blank field
#Add the series number to the end of the first field's string (comma seperated)

entity.Set(schema.GetField("i1"),"20, 20, 32") #test set 

x = entity.Get[str](schema.GetField("i1")) #Get the contents of the first field
SeriesList = [entry.strip() for entry in x.split(',')]
SeriesCount = len(SeriesList) 

SeriesList.append(Series)
SeriesListAsString = ', '.join(SeriesList)

# Re-write the first field with the updated series added
entity.Set(schema.GetField("i1"), SeriesListAsString)


doc.ProjectInformation.SetEntity(entity) # store the entity in the document


y =  entity.Get[str](schema.GetField("i1"))

OUT = x,  SeriesCount, y, True

So I’ve set it to project information (I think)…
The output looks fine.

image

Yet, if I try to extract the entity in the next Python window I get a blank.

image

I tried closing the dynamo graph and testing to see if the schema had written in a new dynamo graph and I got:

So the schema is created and the fields exist… I just don’t seem to be able to “save” the fields.

I also tried to write the schema to a sheet but got an error that Sheet has no attribute “SetEntity”

What am I doing wrong?

I get that this is a toy problem, but one would never do this.

Items packed into extensible storage are already in memory, so rather than setting the value and then instantly getting the value you’d just pull the value which you already know.

Your ‘get’ should be a separate graph entirely, likely run a minute (hour, day, week, month, year, decade) later.

Surely it shouldn’t matter if I do it 1 minute later or 1 year later?

That field is coming back blank, so it’s not writing?

You haven’t committed the data into the field until the Dynamo instance finishes running. There isn’t any data until then.

1 Like

OK, so I ran the node to set… The one with the output.

Closed that Dynamo graph and opened a new one:

All this is doing is reading the first field:

But it’s not written anything to the first field?

Or do I have to shut Dynamo and try?

Ah… I was trying to call the entity in the wrong way.

    sheet_element = doc.GetElement(ElementId(sheet.Id))
    entity = sheet_element.GetEntity(schema)
    if entity.IsValid():
        # Verify the contents of the field
        verified_value = entity.Get[str](schema.GetField("i1"))

Seems I have to call it from the object, not just grab the schema.

1 Like

Correct. This is why pretty much every object type in Revit.DB inherits the ‘entity’ method. :slight_smile: