Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit API eStorage without association

3 REPLIES 3
Reply
Message 1 of 4
raghulan
394 Views, 3 Replies

Revit API eStorage without association

Revit 2015 .NET API eStorage

 

I have two questions inregards to estorage\

 

1. How to do a create a storage to store information without associating to an entity.

I wanted to have some general infomraiton stored.

 

// Create a data structure, attach it to a wall, populate it with data, and retrieve the data back from the wall
void StoreDataInWall(Wall wall, XYZ dataToStore)
{
        Transaction createSchemaAndStoreData = new Transaction(wall.Document, "tCreateAndStore");
        createSchemaAndStoreData.Start();
        SchemaBuilder schemaBuilder = 
                new SchemaBuilder(new Guid("720080CB-DA99-40DC-9415-E53F280AA1F0"));
        schemaBuilder.SetReadAccessLevel(AccessLevel.Public); // allow anyone to read the object
        schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor); // restrict writing to this vendor only
        schemaBuilder.SetVendorId("ADSK"); // required because of restricted write-access
        schemaBuilder.SetSchemaName("WireSpliceLocation");
        // create a field to store an XYZ
        FieldBuilder fieldBuilder = 
                schemaBuilder.AddSimpleField("WireSpliceLocation", typeof(XYZ)); 
        fieldBuilder.SetUnitType(UnitType.UT_Length);
        fieldBuilder.SetDocumentation("A stored location value representing a wiring splice in a wall.");

        Schema schema = schemaBuilder.Finish(); // register the Schema object
        Entity entity = new Entity(schema); // create an entity (object) for this schema (class)
        // get the field from the schema
        Field fieldSpliceLocation = schema.GetField("WireSpliceLocation"); 
        // set the value for this entity
        entity.Set<XYZ>(fieldSpliceLocation, dataToStore, DisplayUnitType.DUT_METERS); 
        wall.SetEntity(entity); // store the entity in the element
        // get the data back from the wall
        Entity retrievedEntity = wall.GetEntity(schema);
        XYZ retrievedData = 
                retrievedEntity.Get<XYZ>(schema.GetField("WireSpliceLocation"),
                DisplayUnitType.DUT_METERS);
        createSchemaAndStoreData.Commit();  
}

 based on this example from dev guide.

 

2. If i need to create a eStore which can be accessed only by using my vendor id and application.

what settings should that value for read and write.

 

When I specify a vendor ID its give me an error.

 

So If I specificy vendor ID in it other developer cannot edit or delete those values right?

 

Thanks for your help.

Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com
3 REPLIES 3
Message 2 of 4
raghulan
in reply to: raghulan

Also,

When i tried to read the storage I created it says
"Reading of Entities of this Schema is not allowed to the current add-in."

I added the vendor ID to the manifest file too still i am getting this error.

Also please provide a snippet on how to read a estorage data which is not associated with any entity.

Currently in the help file it is mentioned as follows, where the schema is fetched based on the attached entity.

// get the data back from the wall
Entity retrievedEntity = wall.GetEntity(schema);
XYZ retrievedData =
retrievedEntity.Get<XYZ>(schema.GetField("WireSpliceLocation"),
DisplayUnitType.DUT_METERS);
Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com
Message 3 of 4
Scott_Wilson
in reply to: raghulan

You must store your data in an entity, there is no getting away from that. If you mean that you don't want to store your data in a transient element so that it is protected from user deletion / modification, then you have a couple of options.

 

Option 1: Use a system element that is always present, yet can't be deleted using the user interface. The Document.ProjectInformation element fits this need nicely. This could get a little messy in a worksharing environment though, as it will be used frequently by users to update project parameters and other add-ins (even those used by other worksharing users) could have the same idea as you and want constant access for storing thier own data. I don't advise this method if you need to support a worksharing environment.

 

Option 2: Use a DataStorage element, these are API specific elements with the sole purpose of having entities stored within them, they are invisible to the user interface so are unlikely (impossible maybe?) to be deleted by a user and because you have created them they are unlikely to be hijacked by other add ins. Once created they can be easily found again using a class filter and with a little management code you could designate one instance as a singleton if that is what you are after.

 

In relation to your problem with the schema not allowing you to read it. You need to make sure that the vendor id used to create the schema is the same as entered into the manufest file used to load your command / application.

Message 4 of 4
raghulan
in reply to: Scott_Wilson

Thanks Scott,
Will try and get back to you.
Regards,

Raghulan Gowthaman Cert IV TAA, B.E,.
Senior Technical Consultant | Developer - R&D
A2K Technologies Sydney
Web : www.a2ktechnologies.com.au
www.civil3dforum.com | www.e4forums.com
www.zcodia.com.au
www.raghulangowthaman.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community