In the first post on this topic, we saw how we can use the Extensible Storage API to define schema, fields, entities, add data to the fields and eventually setting the entity on Revit elements (namely a wall). In this post, we shall look at extracting all those information and various approaches of doing so.
Extracting Schema and Field Related Information from a Revit Element
The existing list of Schemas from a given Revit model can be accessed using the Schema.ListSchemas() method. This list can then be iterated through to extract each of the schemas: e.g.,
//Let us list all schemas in the document
IList schmeas = Schema.ListSchemas();
foreach (Schema sch in schmeas)
{
TaskDialog.Show(
"Schema Details", "Schema Name: " + sch.SchemaName);
}
Any specific Schema can also be accessed using the Schema.Lookup() method and by providing the unique GUID for that Schema, as shown below:
// Let us list all Fields for our schema
Schema ourSchema = Schema.Lookup(schemaGuid);
All the fields that are defined in a Schema can be directly accessed using the Schema.ListFields() method:
IList fields = ourSchema.ListFields();
foreach (Field fld in fields)
{
TaskDialog.Show(
"Field Details", "Field Name: " + fld.FieldName);
}
If API users are looking at extracting specific field information on any Revit element, it can be accessed by first accessing the entity object on a given element, and then by accessing the field information using the field name stored in the entity. The entity information on an element can be obtained using the Element.GetEntity() method and by passing the schema object (since entity is an instance of a given schema). With this entity object, the specific value of a field can be obtained using the Entity.Get() method which accepts parameters like field (which is accessed using its name). One of the overloads of this Get() method also accepts the unit types. The following code snippet uses both the Entity.Get() method overloads to extract the field information and values for a given entity.
// Now let us extract the value for the field we created
Entity wallSchemaEnt = wall.GetEntity(Schema.Lookup(schemaGuid));
XYZ wallSocketPos = wallSchemaEnt.Get(
Schema.Lookup(schemaGuid).GetField("SocketLocation"),
DisplayUnitType.DUT_METERS);
TaskDialog.Show("SocketLocation",
"SocketLocation: "
+ wallSocketPos.X.ToString() + ", "
+ wallSocketPos.Y.ToString() + ", "
+ wallSocketPos.Z.ToString());
String wallSocketNumber = wallSchemaEnt.Get(
Schema.Lookup(schemaGuid).GetField("SocketNumber"));
TaskDialog.Show(
"SocketNumber", "SocketNumber: " + wallSocketNumber);

Leave a Reply to RobiXxuCancel reply