At this previous blog post you can find how to read ASHRAE table of a specific element. Basically a GUID is stored at the Built in parameter as a string: RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM
But where can we get the list of Loss Methods available?
The following sample show the getLossMethods function that will read the ExternalServer that holds that information and create a list of names and guids of each loss method available. The most important is the guid of each method as this is the information required on the parameter.
For this sample, it will create a simple list of LossCoef data structure, that contains the value pair (and you may replace this with a hash list, or a winform that show the options, etc). Also note this sample is for Ducts (type of the server, see previous post for Pipes)
// temp structure to hold data
struct LossCoef{public Guid id; public string name;}
private List<LossCoef> getLossMethods(ExternalServiceId serviceId)
{
MultiServerService service = ExternalServiceRegistry.
GetService(serviceId) as MultiServerService;
IList<Guid> serverIds = service.GetRegisteredServerIds();
List<LossCoef> list = new List<LossCoef>();
foreach (Guid serverId in serverIds)
{
IExternalServer server = getServerById(serverId, serviceId);
IDuctFittingAndAccessoryPressureDropServer ductServer =
server as IDuctFittingAndAccessoryPressureDropServer;
LossCoef lc = new LossCoef();
lc.id = serverId;
lc.name = ductServer.GetName();
list.Add(lc);
}
return list;
}
private IExternalServer getServerById(Guid serverGUID,
ExternalServiceId serviceId)
{
//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;
}
And here is Execute method showing how to use it. In this case will change the Loss Method by setting the parameter value (as a GUID string value).
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
foreach (ElementId eleId in uidoc.Selection.GetElementIds())
{
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;
List<LossCoef> lc = getLossMethods(
ExternalServices.BuiltInExternalServices.
DuctFittingAndAccessoryPressureDropService);
// the 4th item should be "Specific Loss"
// but you may double check
param.Set(lc[3].id.ToString());
}
return Result.Succeeded;
}