Does anyone know if you have to unwrap Revit elements to add a schema?
I didn’t and it seemed to work… now I can’t seem to get it to work wrapped or unwrapped.
Does anyone know if you have to unwrap Revit elements to add a schema?
I didn’t and it seemed to work… now I can’t seem to get it to work wrapped or unwrapped.
what do you mean with schema ? a python template ?
Extensible storage… Yep, I’m still trying to get my head round it
I’m getting the impression I do need to unwrap.
Start here
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB.ExtensibleStorage import *
OUT = Schema.ListSchemas()
Clockwork have custom nodes, such as Element.ExtensbileStorageData, Document.Schemas, etc. which you could crack open and look at the code
Thanks. I’m not trying to see what schemas I have already.
I’m trying to create a new one (got this bit)… add fields (got this bit)… then amend fields and add them to objects (struggling with the string version)
for reading and looking at fields I managed that…
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB.ExtensibleStorage import Schema
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument
schemas = Schema.ListSchemas()
OUT = ["There are " + str(len(schemas)) + " schemas in this model."]
for scheme in schemas:
info = []
info.append("Schema Name: " + str(scheme.SchemaName))
try:
info.append(len(scheme.ListFields()))
for i in (scheme.ListFields()):
info.append(i.FieldName)
except:
info.append("Can't read field")
OUT.append(info)
It’s the amending fields + writing to objects I’m struggling with.
Look at SchemaBuilder
and do everything inside a transaction
I’ve built the schema. I’ve added fields.
It’s the adding parameters to string fields and setting them to elements I’m struggling with.
I know it’s C# check JT here https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23
Cheers, will have a read.
I’ve found a fair bit in C# but very little in Python…
I really wanted to get my head round it in Python before I ventured into C#.
Try this using a single element for IN[0]. Note - only works with flavours of IronPython
import clr
import uuid
from System import Guid
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.ExtensibleStorage import *
doc = DocumentManager.Instance.CurrentDBDocument
my_data = XYZ(0.5, 2.3, 0)
element = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
# Build Schema
guid = str(uuid.uuid4())
schema_builder = SchemaBuilder(Guid(guid))
schema_builder.SetReadAccessLevel(AccessLevel.Public)
schema_builder.SetWriteAccessLevel(AccessLevel.Public)
schema_builder.SetSchemaName("MyFirstSchema")
# Build Field
field_builder = schema_builder.AddSimpleField("SimpleFieldName", XYZ)
field_builder.SetSpec(SpecTypeId.Length)
field_builder.SetDocumentation("A test field with a XYZ point")
# Finish Schema
schema = schema_builder.Finish()
# Create entity with schema to append to elements
entity = Entity(schema)
entity.Set[XYZ]("SimpleFieldName", my_data, UnitTypeId.Millimeters)
OUT = type(entity)
if element:
element.SetEntity(entity)
TransactionManager.Instance.TransactionTaskDone()
# Check we have info
if element:
OUT = element.GetEntity(schema).Get[XYZ]("SimpleFieldName", UnitTypeId.Millimeters)
This is likely going to be the case for a LOT of these workflows. The Python execution method isn’t fully supported (in any version) and as a result is WAY less stable for these aspects of the api. Moving to C# (zero touch node) is recommended to prevent crashes and increase performance.
It is one of several areas where you just need the more direct connection to the host application than the Python interpreters really allow.
Argh… I tried that one in Py3 as my first attempt about 100 ways…
Obviously I realised the set command wasn’t working in Py3 but for some reason I didn’t twig other stuff wasn’t work.
Thank you! << Doesn’t quite express how happy I am right now Thank you x100
1 step at a time
C# by Christmas
Was also wondering how
entity = Entity(schema)
worked for everyone else (online examples) but I had to type:
entity = ExtensibleStorage.Entity(schema)
Thanks to your post I know it’s this using here:
from Autodesk.Revit.DB.ExtensibleStorage import *
Yay! Thanks again
#SlowlyLearning