SchemaBuilder
Description:
This class is used to create Schemas in the Extensible Storage framework.
This class is used to create Schemas in the Extensible Storage framework.
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.
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.
public class SchemaBuilder : IDisposable
// 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.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)
Field fieldSpliceLocation = schema.GetField("WireSpliceLocation"); // get the field from the schema
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();
}
}
| Name | Return Type | Description |
|---|---|---|
| SchemaBuilder(Guid) | None | Constructs a new SchemaBuilder where the resulting Schema will use the input GUID. |
| Name | Return Type | Description |
|---|---|---|
| AcceptableName(String) | bool | Checks whether a string is an acceptable name for a Schema or a Field. |
| AddArrayField(String, Type) | FieldBuilder | Creates a field containing an array of values in the Schema, with given name and type of contained values. |
| AddMapField(String, Type, Type) | FieldBuilder | Creates a field containing an ordered key-value map in the Schema, with given name and type of contained values. |
| AddSimpleField(String, Type) | FieldBuilder | Creates a field containing a single value in the Schema, with given name and type. |
| Dispose() | None | Releases all resources used by the |
| Finish() | Schema | Registers and returns the created Schema object. |
| GUIDIsValid(Guid) | bool | Checks whether the supplied GUID value is valid. |
| Ready() | bool | Checks whether the builder may be used. |
| SetApplicationGUID(Guid) | SchemaBuilder | Sets the GUID of the application or add-in that may access entities of this Schema under the Application acess level. |
| SetDocumentation(String) | SchemaBuilder | Sets the documentation string for the Schema. |
| SetReadAccessLevel(AccessLevel) | SchemaBuilder | Sets top level read access (for entities) |
| SetSchemaName(String) | SchemaBuilder | Sets the name of the Schema. |
| SetVendorId(String) | SchemaBuilder | Sets the ID of the third-party vendor that may access entities of this Schema under the Vendor acess level, and to generally identify the owner of this Schema. |
| SetWriteAccessLevel(AccessLevel) | SchemaBuilder | Sets top level write access (for entities) |
| VendorIdIsValid(String) | bool | Checks whether the given vendor ID string is valid. A valid vendor ID string: 1. Has a length of at least 4 characters and no more than 253 characters, and 2. Contains only letters, digits, or any of the following special characters: ! " # & \ ( ) + , . |
| Name | Return Type | Description |
|---|---|---|
| IsValidObject | bool | Specifies whether the .NET object represents a valid Revit entity. |