Hello, I have a problem, I am creating a Revit macro and I would like to find the length of the guardrail which is drawing the war in 3D. But I can’t do it.
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using Settings;
namespace Calculs_ACV
{
public class GardeDeCorpProcessor
{
private List<string> resultatList;
public GardeDeCorpProcessor(List<string> resultatList)
{
this.resultatList = resultatList;
}
public void ProcessCategoryGardeDeCorp(Document doc, string typologie_cgd, string NameElem, string NameParam)
{
// Collecteurs pour différentes catégories
FilteredElementCollector collectorOssature = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming);
FilteredElementCollector collectorGeneric = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel);
FilteredElementCollector collectorRailings = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StairsRailingBaluster);
// Combiner les collecteurs en une seule liste
IEnumerable<Element> combinedCollectors = collectorOssature.Cast<Element>().Concat(collectorGeneric.Cast<Element>()).Concat(collectorRailings.Cast<Element>());
double totalLength = 0; // Longueur pour les garde-corps normaux
double totalLengthToiture = 0; // Longueur pour les garde-corps de toiture
// Parcourir tous les éléments combinés
foreach (Element elem in combinedCollectors)
{
// Vérifier si l'élément est une instance de famille
FamilyInstance familyInstance = elem as FamilyInstance;
if (familyInstance != null)
{
// Récupérer le type de famille
FamilySymbol familySymbol = familyInstance.Symbol;
if (familySymbol != null)
{
Parameter typologieParam = familySymbol.LookupParameter("Typologie CGD");
if (typologieParam != null && typologieParam.HasValue)
{
string typologieValue = typologieParam.AsString();
TaskDialog.Show("Debug",string.Format("Typologie trouvée : {0}",typologieValue));
if (typologieValue.Trim().Equals("Garde corps toiture", StringComparison.OrdinalIgnoreCase) == true)
{
TaskDialog.Show("Debug",string.Format( "Élément toiture : {0}",familyInstance.Name));
Parameter lengthParamToiture = elem.LookupParameter("Longueur");
if (lengthParamToiture != null && lengthParamToiture.HasValue)
{
totalLengthToiture += ConvertFeetToMeters(lengthParamToiture.AsDouble());
}
else
{
TaskDialog.Show("Debug",string.Format( "Paramètre Longueur manquant pour : {0}",familyInstance.Name));
}
}
else if (typologieValue.Trim().Equals("Garde corps", StringComparison.OrdinalIgnoreCase) == true)
{
Parameter lengthParam = elem.LookupParameter("Longueur");
if (lengthParam != null && lengthParam.HasValue)
{
totalLength += ConvertFeetToMeters(lengthParam.AsDouble());
}
}
}
else
{
TaskDialog.Show("Debug", string.Format("Pas de paramètre Typologie CGD pour : {0}",familyInstance.Name));
}
}
}
}
// Ajouter les résultats à la liste
resultatList.Add("GARDE CORPS,Longueur (Ml),<GARDE CORP>");
resultatList.Add(string.Format("Longueur totale des garde-corps normaux (Ml), {0},<GARDE CORP>",Math.Round(totalLength, 0)));
resultatList.Add(string.Format("Longueur totale des garde-corps de toiture (Ml), {0},<GARDE CORP>",totalLengthToiture));//Math.Round(totalLengthToiture, 2)));
if (AppSettings.setting.parameter.DetailTypoSetting())
{
resultatList.Add("");
}
}
// Méthode pour convertir des pieds en mètres
private static double ConvertFeetToMeters(double feet)
{
return feet * 0.3048; // Conversion de pieds à mètres
}
}
}
In this macro I will search in different categories, this is normal. Who can help me for my problems?