private static void InsulateAccessory(Document doc, Element e, DataTable insPar, DataTable insSet) { #region Initialization //Read common configuration values string sysAbbr = e.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString(); //Declare insulation thickness vars #region Retrieve accessory diameter var cons = mp.GetConnectors(e); double dia = (cons.Primary.Radius * 2).FtToMm().Round(0); #endregion #region Read specified Insulation Thickness double specifiedInsulationThickness; //This try/catch is introduced to catch exceptions where the specified diameter is not //listed in the insulation excel table try { specifiedInsulationThickness = ReadThickness(sysAbbr, insPar, dia); //In feet } catch (Exception) { //This is to handle non standard valves -- usually small bore stuff for air venting and alike specifiedInsulationThickness = 0; } #endregion #endregion //See if the accessory is in the settings list, else return no action done if (insSet.AsEnumerable().Any(row => row.Field <string>("FamilyAndType") == e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString())) { //See if element is not allowed to be insulated var query = insSet.AsEnumerable() .Where(row => row.Field <string>("FamilyAndType") == e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()) .Select(row => row.Field <string>("AddInsulation")); bool insulationAllowed = bool.Parse(query.FirstOrDefault()); //Retrieve insulation type parameter and see if the accessory is already insulated Parameter parInsTypeCheck = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); if (parInsTypeCheck.HasValue) { //If not allowed (false is read) negate the false to true to trigger the following if //Delete any existing insulation and return if (!insulationAllowed) { doc.Delete(InsulationLiningBase.GetInsulationIds(doc, e.Id)); return; } //Case: If the accessory is already insulated, check to see if insulation is correct Parameter parInsThickness = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); double existingInsulationThickness = parInsThickness.AsDouble(); //In feet //Test if existing thickness is as specified //If ok -> do nothing, if not -> fix it if (!specifiedInsulationThickness.Equalz(existingInsulationThickness, 1.0e-9)) { ElementId id = InsulationLiningBase.GetInsulationIds(doc, e.Id).FirstOrDefault(); if (id == null) { return; } PipeInsulation insulation = doc.GetElement(id) as PipeInsulation; if (insulation == null) { return; } insulation.Thickness = specifiedInsulationThickness; } } else { //Case: If no insulation -> add insulation if allowed if (!insulationAllowed) { return; } //Read pipeinsulation type and get the type string pipeInsulationName = dh.ReadParameterFromDataTable(sysAbbr, insPar, "Type"); if (pipeInsulationName == null) { return; } PipeInsulationType pipeInsulationType = fi.GetElements <PipeInsulationType, BuiltInParameter>(doc, BuiltInParameter.ALL_MODEL_TYPE_NAME, pipeInsulationName).FirstOrDefault(); if (pipeInsulationType == null) { throw new Exception($"No pipe insulation type named {pipeInsulationName}!"); } //Create insulation PipeInsulation.Create(doc, e.Id, pipeInsulationType.Id, specifiedInsulationThickness); } } }
private static void InsulatePipe(Document doc, Element e, DataTable insPar) { #region Initialization //Read common configuration values string sysAbbr = e.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString(); //Declare insulation thickness vars var dia = ((Pipe)e).Diameter.FtToMm().Round(0); double specifiedInsulationThickness = ReadThickness(sysAbbr, insPar, dia); //In feet already #endregion //Retrieve insulation type parameter and see if the pipe is already insulated Parameter parInsTypeCheck = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); if (parInsTypeCheck.HasValue) { //Case: If the pipe is already insulated, check to see if insulation is correct Parameter parInsThickness = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); double existingInsulationThickness = parInsThickness.AsDouble(); //In feet //Test if existing thickness is as specified //If ok -> do nothing, if not -> fix it if (!specifiedInsulationThickness.Equalz(existingInsulationThickness, 1.0e-9)) { ElementId id = InsulationLiningBase.GetInsulationIds(doc, e.Id).FirstOrDefault(); if (id == null) { return; } if (specifiedInsulationThickness.Equalz(0, Extensions._epx)) { doc.Delete(id); return; } PipeInsulation insulation = doc.GetElement(id) as PipeInsulation; if (insulation == null) { return; } insulation.Thickness = specifiedInsulationThickness; } } else { //Case: If no insulation -> add insulation //Read pipeinsulation type and get the type string pipeInsulationName = dh.ReadParameterFromDataTable(sysAbbr, insPar, "Type"); if (pipeInsulationName == null) { return; } PipeInsulationType pipeInsulationType = fi.GetElements <PipeInsulationType, BuiltInParameter>(doc, BuiltInParameter.ALL_MODEL_TYPE_NAME, pipeInsulationName).FirstOrDefault(); if (pipeInsulationType == null) { throw new Exception($"No pipe insulation type named {pipeInsulationName}!"); } //Test to see if the specified insulation is 0 if (specifiedInsulationThickness.Equalz(0, Extensions._epx)) { return; } //Create insulation PipeInsulation.Create(doc, e.Id, pipeInsulationType.Id, specifiedInsulationThickness); } }
private static void InsulateFitting(Document doc, Element e, DataTable insPar, DataTable insSet) { #region Initialization //Read configuration data //var insPar = GetInsulationParameters(); //Read common configuration values string sysAbbr = e.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString(); //Declare insulation thickness vars #region Retrieve fitting diameter double dia; //See if the fittings is in the settings list, else return no action done if (insSet.AsEnumerable().Any(row => row.Field <string>("FamilyAndType") == e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString())) { //See if element is not allowed to be insulated var query = insSet.AsEnumerable() .Where(row => row.Field <string>("FamilyAndType") == e.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()) .Select(row => row.Field <string>("AddInsulation")); bool insulationAllowed = bool.Parse(query.FirstOrDefault()); #region DiameterRead //Retrieve specified insulation thickness var mf = ((FamilyInstance)e).MEPModel as MechanicalFitting; //Case: Reducer if (mf.PartType.ToString() == "Transition") { //Retrieve connector dimensions var cons = mp.GetConnectors(e); //Insulate after the larger diameter double primDia = (cons.Primary.Radius * 2).FtToMm().Round(0); double secDia = (cons.Secondary.Radius * 2).FtToMm().Round(0); dia = primDia > secDia ? primDia : secDia; } //Case: Other fitting else { //Retrieve connector dimensions var cons = mp.GetConnectors(e); dia = (cons.Primary.Radius * 2).FtToMm().Round(0); } #endregion #endregion #region Read specified Insulation Thickness double specifiedInsulationThickness = ReadThickness(sysAbbr, insPar, dia); //In feet #endregion #endregion //Retrieve insulation type parameter and see if the fitting is already insulated Parameter parInsTypeCheck = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); if (parInsTypeCheck.HasValue) { //Case Tee: If the element is a tee, delete any existing insulation //Or it should not have insulation if (mf.PartType.ToString() == "Tee" || insulationAllowed == false) { doc.Delete(InsulationLiningBase.GetInsulationIds(doc, e.Id)); if (mf.PartType.ToString() == "Tee") { InsulateTee(); } return; } //Case: If the fitting is already insulated, check to see if insulation is correct Parameter parInsThickness = e.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); double existingInsulationThickness = parInsThickness.AsDouble(); //In feet //Test if existing thickness is as specified //If ok -> do nothing, if not -> fix it if (specifiedInsulationThickness.Equalz(existingInsulationThickness, 1.0e-9) == false) { //Case: specifiedInsulationThickness is 0 if (specifiedInsulationThickness.Equalz(0, 1.0e-9)) { doc.Delete(InsulationLiningBase.GetInsulationIds(doc, e.Id)); return; } ElementId id = InsulationLiningBase.GetInsulationIds(doc, e.Id).FirstOrDefault(); if (id == null) { return; } PipeInsulation insulation = doc.GetElement(id) as PipeInsulation; if (insulation == null) { return; } //Can cause exception if specifiedInsulation = 0 //This can happen if the PipingSystem Type Abbreviation does not exist in the //Insulation.xlsx file and ReadThickness returns 0 //TODO: Write a general fix for this insulation.Thickness = specifiedInsulationThickness; } } else { if (mf.PartType.ToString() == "Tee" && insulationAllowed == true) { InsulateTee(); return; } if (insulationAllowed && specifiedInsulationThickness > 1.0e-6) //Insulate only if insulation is allowed and insulation thickness is above 0 { //Case: If no insulation -> add insulation //Read pipeinsulation type and get the type string pipeInsulationName = dh.ReadParameterFromDataTable(sysAbbr, insPar, "Type"); if (pipeInsulationName == null) { return; } PipeInsulationType pipeInsulationType = fi.GetElements <PipeInsulationType, BuiltInParameter>(doc, BuiltInParameter.ALL_MODEL_TYPE_NAME, pipeInsulationName).FirstOrDefault(); if (pipeInsulationType == null) { throw new Exception($"No pipe insulation type named {pipeInsulationName}!"); } //Create insulation PipeInsulation.Create(doc, e.Id, pipeInsulationType.Id, specifiedInsulationThickness); } } //Local method to insulate Tees void InsulateTee() { Parameter par1 = e.LookupParameter("Insulation Projected"); Parameter par2 = e.LookupParameter("Dummy Insulation Visible"); if (specifiedInsulationThickness.Equalz(0, Extensions._epx)) { //Set insulation if (par1 == null) { return; } par1.Set(specifiedInsulationThickness); //Make invisible if not if (par2 == null) { return; } if (par2.AsInteger() == 1) { par2.Set(0); } } //Set insulation if (par1 == null) { return; } par1.Set(specifiedInsulationThickness); //Make visible if not if (par2 == null) { return; } if (par2.AsInteger() == 0) { par2.Set(1); } } } }
public TypeOfInsulation(PipeInsulationType revitType) { InstanceGroups = new Dictionary <int, List <PipeInsulation> >(); RevitType = revitType; }