How retrieve already exist Extensible Storage ?

How retrieve already exist Extensible Storage ?

pmeigneux
Advocate Advocate
2,091 Views
4 Replies
Message 1 of 5

How retrieve already exist Extensible Storage ?

pmeigneux
Advocate
Advocate

Hello,

 

I want to use an extensible storage.

 

How do I know if it already exists in the current document (I know the GUID)?

 

Thank you.

 

Philippe.

0 Likes
Accepted solutions (1)
2,092 Views
4 Replies
Replies (4)
Message 2 of 5

matthew_taylor
Advisor
Advisor

Hi @pmeigneux,

Have you looked at the examples in the SDK?

What have you tried so far?

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 5

pmeigneux
Advocate
Advocate

Hi Matt,

 

Yes, I'm find :

/// <summary>
/// Create a data structure, attach it to a wall, 
/// populate it with data, and retrieve the data 
/// back from the wall
/// </summary>
public 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" ) );
 
  // allow anyone to read the object
  schemaBuilder.SetReadAccessLevel( 
    AccessLevel.Public );
 
  // restrict writing to this vendor only
  schemaBuilder.SetWriteAccessLevel( 
    AccessLevel.Vendor );
 
  // required because of restricted write-access
  schemaBuilder.SetVendorId( "ADSK" );
 
  // 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." );
 
  schemaBuilder.SetSchemaName( "WireSpliceLocation" );
 
  Schema schema = schemaBuilder.Finish(); // register the Schema object
 
  // create an entity (object) for this schema (class)
  Entity entity = new Entity( schema );
 
  // get the field from the schema
  Field fieldSpliceLocation = schema.GetField("WireSpliceLocation" );
 
  entity.Set<XYZ>( fieldSpliceLocation, dataToStore, DisplayUnitType.DUT_METERS ); // set the value for this entity
 
  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();
}



But How define a variable schema when i cannot create a new Schema ?

Philippe.

 

 

0 Likes
Message 4 of 5

matthew_taylor
Advisor
Advisor

@pmeigneux,

The API documents return quite a few hits for the search word 'schema'. I can see one that lists the loaded schemas, another that looks for one given a GUID.

Have you perused the search results?

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Philippe,

 

Thank you for your query.

 

Glad to hear you are looking into this important, useful and powerful functionality.

 

Many thanks to Matt for all the help you already provided!

 

In addition to Matt’s suggestions, The Building Coder defines a dedicated topic group for extensible storage:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23

 

Philippe, you answer is already answered there, several times over.

 

As far as I can tell, the extensible storage helper class JtNamedGuidStorage described in the post on Named Guid Storage for Project Identification shows how to implement what you are asking for.

 

I would be surprised if you run into any relevant questions on extensible storage that have not already been answered and published in that collection.

 

If you do, I will certainly add them!

 

Looking forward to seeing what you come up with  🙂

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder