On Revit MEP projects (also available on Revit), we can read the Loss Method data, but the information about the ASHRAE Table is not directly hosted on the element. So the question is: how access this table information, in the image below, the name “SR4-2”?
In fact this information is stored at the Extensible Storage and linked back to the element at the RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM parameter via a GUID value.
To get the table name we need to make this connection.
From a give element, the first step is read the parameter value. The following code show this
FamilyInstance fitting = doc.GetElement(eleId) as FamilyInstance;
if (fitting == null) continue;
Parameter param = fitting.get_Parameter(
BuiltInParameter.RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM);
if (param == null) continue;
string strValGUID = param.AsString();
string strValTemp = getTableNameByServerId(fitting,
strValGUID,
ExternalServices.BuiltInExternalServices.
DuctFittingAndAccessoryPressureDropService);
Now the interesting part: the getTableNameByServerId method is not on the API. The following code show all the steps. Thanks to Shelley and Jill, on Autodesk Shanghai team, for this excellent sample.
//the field name of duct table
public static readonly string fieldDuctTableName = "ASHRAETableName";
//the field name of pipe table
public static readonly string fieldPipeTableName = "PipeFittingKFactorTableName";
//get the server, and then get entity from the server,
//get table name from the entity
private string getTableNameByServerId(
FamilyInstance fitting,
string strGUID,
ExternalServiceId serviceId)
{
if (fitting == null || strGUID == null || serviceId == null)
return null;
Guid serverGUID;
if (!Guid.TryParse(strGUID, out serverGUID))
return null;
// For Pipe, the loss method might be defined on type
if (serverGUID == MEPCalculationServerInfo.PipeUseDefinitionOnTypeGUID)
{
//check if the loss method of type is "table"
int eLossMethod = fitting.Symbol.get_Parameter(
BuiltInParameter.RBS_PIPE_TYPE_FITTING_LOSS_METHOD_PARAM).
AsInteger();
if (eLossMethod == (int)PipeLossMethodType.Table)
return fitting.Symbol.get_Parameter(
BuiltInParameter.RBS_PIPE_TYPE_FITTING_LOSS_TABLE_PARAM).
AsString();
else
return null;
}
IExternalServer server = getServerById(strGUID, serviceId);
if (server != null)
{
Schema schema = null;
string fieldTableName = "";
if (serviceId == ExternalServices.BuiltInExternalServices.
DuctFittingAndAccessoryPressureDropService)
{
IDuctFittingAndAccessoryPressureDropServer ductServer =
server as IDuctFittingAndAccessoryPressureDropServer;
if (ductServer != null)
{
schema = ductServer.GetDataSchema();
fieldTableName = fieldDuctTableName;
}
}
else if (serviceId == ExternalServices.
BuiltInExternalServices.
PipeFittingAndAccessoryPressureDropService)
{
IPipeFittingAndAccessoryPressureDropServer pipeServer =
server as IPipeFittingAndAccessoryPressureDropServer;
if (pipeServer != null)
{
schema = pipeServer.GetDataSchema();
fieldTableName = fieldPipeTableName;
}
}
if (schema != null)
{
Field field = schema.GetField(fieldTableName);
if (field != null)
{
Entity entity = fitting.GetEntity(schema);
if (entity != null && entity.IsValid())
return entity.Get<string>(field);
}
}
}
return null;
}
private IExternalServer getServerById(
string strGUID, ExternalServiceId serviceId)
{
if (strGUID == null || serviceId == null)
return null;
Guid serverGUID;
if (!Guid.TryParse(strGUID, out serverGUID))
return null;
//get the service first, and then get the server
MultiServerService service =
ExternalServiceRegistry.GetService(serviceId)
as MultiServerService;
if (service != null && serverGUID != null)
{
IExternalServer server = service.GetServer(serverGUID);
if (server != null)
return server;
}
return null;
}