Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Extensible storage access error; required ApplicationGUID

harilalmn
Advocate

Extensible storage access error; required ApplicationGUID

harilalmn
Advocate
Advocate

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..!


0 Likes
Reply
357 Views
3 Replies
Replies (3)

BobbyC.Jones
Advocate
Advocate

Hello Harilal,
You'll need to provide an application guid to the schemabuilder to set the access level to Application.

 

SchemaBuilder.SetApplicationGUID()

 

I have a comment in my code that this GUID must match the add in GUID defined in your .addin file.  The docs don't mention this requirement, so not sure if it's true or not.

 

--
Bobby C. Jones
0 Likes

ricaun
Advisor
Advisor

Yes if you are using the 'AccessLevel.Application' you need to add the 'SetApplicationGUID', or you could change it to 'AccessLevel.Public' so the 'SetApplicationGUID' is not necessary, and any other application could change the data in the ExtensibleStorage.

 

Another thing that is not right is that in your code you need to create the field when you create your Schema, after you create a Schema you cannot edit the Schema.

 

I have this implementation for ExtensibleStorage that could help: https://github.com/ricaun-io/RevitAddin.StorageExample/

 

The StorageFactory class enables you to create simple storage with one field.

 

public class StorageWallService : StorageFactory<string, Wall>
{
    public override Guid Guid => new Guid("11111111-2222-3333-4444-555555555555");
    public override string FieldName => "Text";
    public override string SchemaName => "StorageWallService";
    public override string VendorId => "MyCompany";
}

With the basic implementations, Load, Save, Reset...

StorageWallService storageService = new StorageWallService();

var data = storageService.Load(wall);
storageService.Save(wall, "My Data");
storageService.Reset(wall);

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes

harilalmn
Advocate
Advocate

Thank you. I shall try that..!!