Im trying to convert one of my Custom node made in python to C#.
Im trying to get the 'element 'which is dimensioned from the dimension element.
if the tag is single tag then I can get the element directly , but if it is multi tag then I have to get the dimension element attached to and then get the rebar element attached to the dimension element.
Document doc = Document;
var activeview = doc.ActiveView.Id;
StringBuilder results = new StringBuilder();
#region Collectors
FilteredElementCollector tagscollector = new FilteredElementCollector(doc,activeview);
FilteredElementCollector rebarcollector = new FilteredElementCollector(doc,activeview);
ICollection<Element> tagsinview = tagscollector.OfCategory(BuiltInCategory.OST_RebarTags).ToElements();
ICollection<Element> rebarsinview = tagscollector.OfCategory(BuiltInCategory.OST_Rebar).ToElements();
#endregion
#region Lists initiaitons
List<ElementId>taggedrebarid = new List<ElementId>();
List<ElementId>allrebarid = new List<ElementId>();
List<IndependentTag>alltags = new List<IndependentTag>();
List<IndependentTag>duptags = new List<IndependentTag>();
List<Dimension>dupdims = new List<Dimension>();
List<ElementId>duprebarid = new List<ElementId>();
List<Element>dupbars = new List<Element>();
List<ElementId>uniquerebarid = new List<ElementId>();
#endregion
foreach ( IndependentTag t in tagsinview)
alltags.Add(t);
#region Getting all tagged element IDs
foreach (IndependentTag t in tagsinview)
{
Element e = t.GetTaggedLocalElement();
if (e is Dimension)
{
Dimension dim1 = (Dimension)e;
ReferenceArray ref1 = dim1.References;
HashSet<ElementId> refIds = new HashSet<ElementId>();
foreach (Reference r in ref1)
{
refIds.Add(r.ElementId);
}
taggedrebarid.AddRange(refIds.ToList());
}
//Add the rebars to a list
else
{
taggedrebarid.Add(t.GetTaggedLocalElement().Id);
}
}
#endregion
#region Getting all rebars ids
foreach ( Rebar r in rebarsinview)
allrebarid.Add(r.Id);
#endregion
#region getting rebars tha tare tagged twice
for ( var g = 0 ; g < taggedrebarid.Count(); g++)
{
if(uniquerebarid.Contains(taggedrebarid[g]))
{
duprebarid.Add(taggedrebarid[g]);
}
else
{
uniquerebarid.Add(taggedrebarid[g]);
}
}
foreach(ElementId rebid in duprebarid)
dupbars.Add(doc.GetElement(rebid));
#endregion
#region text output taskdialog
/// taskdialog window reuslts
var resultswindow = new TaskDialog("No of tags")
{
MainContent =taggedrebarid.Count().ToString() ,
CommonButtons = TaskDialogCommonButtons.Yes
};
resultswindow.Show();
#endregion
}