please excuse the crossposting but I thought someone might have come up with a solution to this problem:
I want to implement Extensible Storage in an addin I’m coding using CPython and I am hitting a wall when I try to set a value of a field in an schema using a template parameter in the function call. It seems this is an issue with PythonNet ¿has anybody experienced it?
As a workaround: what would you suggest?
I copy below the code and error from my post in dynamobim forums:
component = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
def create_schema():
schema_guid = System.Guid("DF3BBCC1-4D4D-4A01-B444-F9722814F9CE")
schema_builder = SchemaBuilder(schema_guid)
schema_builder.SetReadAccessLevel(AccessLevel.Public)
schema_builder.SetWriteAccessLevel(AccessLevel.Public)
schema_builder.SetSchemaName("TestSchema")
schema_builder.SetDocumentation("Test schema to store ids")
field_builder = schema_builder.AddSimpleField("ParentComponentID", System.String)
schema = schema_builder.Finish()
return schema
def add_schema_instance(schema, rvt_element):
field = schema.GetField("ParentComponentID")
schema_instance = Entity(schema)
schema_instance.Set[System.String](field, "ID0004") # Problem is here
rvt_element.SetEntity(schema_instance)
TransactionManager.Instance.TransactionTaskDone()
schema = create_schema()
When I try to port it to CPython, this same code crashes with exception
Warning: TypeError : No method matches given arguments for Set: (<class ‘Autodesk.Revit.DB.ExtensibleStorage.Field’>, <class ‘str’>)
As I said above, the following call in IronPython is indeed passed correctly to the method: schema_instance.Set[System.String](field, "ID0003")
The reason for my inquiry is that the addin I am working on is completely developed in CPython to use external libraries not available for IronPython (mainly IfcOpenShell and others)
Yes it works but using the IronPython engine
I want to use CPython (PythonNet), hence the problem.
I have to either port all the code to ironpython or find a way to be able to integrate the extensible storage code done in IronPython with the CPython base. Does that make sense?
No solution for Python3, I’m afraid. We did everything in IronPython.
If your addin needs to be done in Py3 you could refactor your extensible storage classes in C# and use the DLLs in your scripts.
Our best bet is what Andrea was saying on this other thread with the work on v5.
Regards!