Extensible storage access error; required ApplicationGUID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have a class I use to write and read extensible storage data to wall instances. Here is the class;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage;
using System;
public static class WallExtensibleStorage
{
private static Guid schemaGuid = new Guid("D077D2A4-5094-4C94-9B06-48EF366C2C80");
private static string vendorId = "MyCompany";
private static string schemaName = "Test";
public static void WriteDataToWall(Element wallElement, string fieldName, string value)
{
Document doc = wallElement.Document;
using (Transaction tr1 = new Transaction(doc, "Write extensible data"))
{
if (doc.IsModifiable == false) tr1.Start();
Schema schema = GetOrCreateSchema(doc);
Entity entity = GetOrCreateEntity(wallElement, schema);
Field field = schema.GetField(fieldName);
if (field != null)
{
entity.Set(field, value);
}
if (tr1.HasStarted()) tr1.Commit();
}
}
public static T ReadDataFromWall<T>(Element wallElement, string fieldName)
{
Document doc = wallElement.Document;
Schema schema = GetOrCreateSchema(doc);
Entity entity = GetOrCreateEntity(wallElement, schema);
Field field = schema.GetField(fieldName);
if (field != null && entity.Get<T>(field) != null)
{
return entity.Get<T>(field);
}
return default(T);
}
private static Schema GetOrCreateSchema(Document doc)
{
Schema schema = Schema.Lookup(schemaGuid);
if (schema == null)
{
using (Transaction tr2 = new Transaction(doc, "Create schema"))
{
if (doc.IsModifiable == false) tr2.Start();
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
schemaBuilder.SetReadAccessLevel(AccessLevel.Application);
schemaBuilder.SetWriteAccessLevel(AccessLevel.Application);
schemaBuilder.SetVendorId(vendorId);
schemaBuilder.SetSchemaName(schemaName);
schema = schemaBuilder.Finish();
if (tr2.HasStarted()) tr2.Commit();
}
}
return schema;
}
private static Entity GetOrCreateEntity(Element element, Schema schema)
{
Entity entity = null;
if (element.IsValidObject)
{
entity = element.GetEntity(schema);
}
if (entity == null)
{
entity = new Entity(schema);
element.SetEntity(entity);
}
return entity;
}
}
I use it like this;
WallExtensibleStorage.WriteDataToWall(this.Wall, "InteriorFinish", "Paint");
// Or like this
WallExtensibleStorage.WriteDataToWall(this.Wall, "InteriorFinishIsSet", true);
But this is throwing an exception saying;
Autodesk.Revit.Exceptions.InvalidOperationException: 'ApplicationGUID is required for Application access levels.'
What am I doing wrong? Any help is highly appreciated..!