SchemaBuilder Class


This class is used to create Schemas in the Extensible Storage framework.

Namespace: Autodesk.Revit.DB.ExtensibleStorage
Assembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Since: 2012

Syntax

C#
public class SchemaBuilder : IDisposable
Visual Basic
Public Class SchemaBuilder _
	Implements IDisposable
Visual C++
public ref class SchemaBuilder : IDisposable

Remarks

Named parameter idiom: Methods that set up the Schema return a reference to the builder so you can invoke multiple methods in a chain (e.g., builder.setReadAccessLevel(...).setWriteAccessLevel(...)). Methods that add fields return a FieldBuilder instead.

Examples

Copy C#
// 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)
{
    using (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");
       FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("WireSpliceLocation", typeof(XYZ)); // create a field to store an XYZ
       fieldBuilder.SetSpec(SpecTypeId.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)
       Field fieldSpliceLocation = schema.GetField("WireSpliceLocation"); // get the field from the schema
       entity.Set<XYZ>(fieldSpliceLocation, dataToStore, UnitTypeId.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"), UnitTypeId.Meters);
       createSchemaAndStoreData.Commit();  
    }
}
Copy VB.NET
' Create a data structure, attach it to a wall, populate it with data, and retrieve the data back from the wall
Private Sub StoreDataInWall(wall As Wall, dataToStore As XYZ)
    Using createSchemaAndStoreData As New Transaction(wall.Document, "tCreateAndStore")
        createSchemaAndStoreData.Start()
        Dim schemaBuilder As 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")
        Dim fieldBuilder As FieldBuilder = schemaBuilder.AddSimpleField("WireSpliceLocation", GetType(XYZ))
        ' create a field to store an XYZ
        fieldBuilder.SetSpec(SpecTypeId.Length)
        fieldBuilder.SetDocumentation("A stored location value representing a wiring splice in a wall.")

        Dim schema As Schema = schemaBuilder.Finish()
        ' register the Schema object
        Dim entity As New Entity(schema)
        ' create an entity (object) for this schema (class)
        Dim fieldSpliceLocation As Field = schema.GetField("WireSpliceLocation")
        ' get the field from the schema
        entity.[Set](Of XYZ)(fieldSpliceLocation, dataToStore, UnitTypeId.Meters)
        ' set the value for this entity
        wall.SetEntity(entity)
        ' store the entity in the element
        ' get the data back from the wall
        Dim retrievedEntity As Entity = wall.GetEntity(schema)
        Dim retrievedData As XYZ = retrievedEntity.[Get](Of XYZ)(schema.GetField("WireSpliceLocation"), UnitTypeId.Meters)
        createSchemaAndStoreData.Commit()
    End Using
End Sub

Inheritance Hierarchy

System Object
Autodesk.Revit.DB.ExtensibleStorage SchemaBuilder

See Also