Hi there,
I want to get the position coordinates of all structural beams with C# code, like I did with Dynamo. But I can't find a way to do this.
Please help!
Solved! Go to Solution.
Hi there,
I want to get the position coordinates of all structural beams with C# code, like I did with Dynamo. But I can't find a way to do this.
Please help!
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
Hi @nelsonhp3 ,
try using the below code
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType(); IList<Curve> curves = new List<Curve>(); Options Op = app.Create.NewGeometryOptions(); Op.ComputeReferences = true; Op.IncludeNonVisibleObjects = true; Op.View = doc.ActiveView; foreach (Element e in collector) { FamilyInstance beam = e as FamilyInstance; GeometryElement GE = beam.get_Geometry(Op); foreach(GeometryObject Go in GE) { //Get the curve from BEAM GEOMETRY Curve C = Go as Curve; curves.Add(C); } } foreach(Curve C in curves) { if(C!=null) { string startPoint = C.GetEndPoint(0).ToString(); string endPoint = C.GetEndPoint(1).ToString(); } }
I hope this helps.
Hi @nelsonhp3 ,
try using the below code
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType(); IList<Curve> curves = new List<Curve>(); Options Op = app.Create.NewGeometryOptions(); Op.ComputeReferences = true; Op.IncludeNonVisibleObjects = true; Op.View = doc.ActiveView; foreach (Element e in collector) { FamilyInstance beam = e as FamilyInstance; GeometryElement GE = beam.get_Geometry(Op); foreach(GeometryObject Go in GE) { //Get the curve from BEAM GEOMETRY Curve C = Go as Curve; curves.Add(C); } } foreach(Curve C in curves) { if(C!=null) { string startPoint = C.GetEndPoint(0).ToString(); string endPoint = C.GetEndPoint(1).ToString(); } }
I hope this helps.
Hi, thanks for the response!
I made this Stringbuilder to see the results with TaskDialog:
foreach (Curve C in curves) { if (C != null) { string startPoint = C.GetEndPoint(0).ToString(); string endPoint = C.GetEndPoint(1).ToString(); sb2.AppendLine("StartPoint: " + startPoint); sb2.AppendLine("EndPoint: " + endPoint); } } TaskDialog.Show("Beams locations test", sb2.ToString());
And this is the result:
Why is it duplicated?
And there's a way to create a list of all beams and their positions along with other parameters like the next screenshot?
Hi, thanks for the response!
I made this Stringbuilder to see the results with TaskDialog:
foreach (Curve C in curves) { if (C != null) { string startPoint = C.GetEndPoint(0).ToString(); string endPoint = C.GetEndPoint(1).ToString(); sb2.AppendLine("StartPoint: " + startPoint); sb2.AppendLine("EndPoint: " + endPoint); } } TaskDialog.Show("Beams locations test", sb2.ToString());
And this is the result:
Why is it duplicated?
And there's a way to create a list of all beams and their positions along with other parameters like the next screenshot?
Hi @nelsonhp3 ,
I think the beam is made up of more than one curve. To test this after adding curves to the list use TaskDialog to show the number of curves.
That's why you are getting more points and it is not duplicated.
and to answer your second question the simplest way is you can use the below code to get the list of element's parameters and their corresponding values
string s="";
Element e; FamilyInstance beam = e as FamilyInstance; foreach(Parameter P in beam.Parameters) { switch(P.StorageType) { case StorageType.Double: double value = P.AsDouble();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.ElementId: ElementId value = P.AsElementId();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.Integer: int value = P.AsInteger();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.String: string value = P.AsValueString();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; } }
TaskDialog.Show("Parameters list", s);
Now TaskDialog.show() will show you the element's parameter name and its corresponding value in a dialog.
I hope this helps.
If this helped solve your problem please mark it as solution, so other users can get this solutions as well
Hi @nelsonhp3 ,
I think the beam is made up of more than one curve. To test this after adding curves to the list use TaskDialog to show the number of curves.
That's why you are getting more points and it is not duplicated.
and to answer your second question the simplest way is you can use the below code to get the list of element's parameters and their corresponding values
string s="";
Element e; FamilyInstance beam = e as FamilyInstance; foreach(Parameter P in beam.Parameters) { switch(P.StorageType) { case StorageType.Double: double value = P.AsDouble();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.ElementId: ElementId value = P.AsElementId();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.Integer: int value = P.AsInteger();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; case StorageType.String: string value = P.AsValueString();
s = s + "\n" + P.Definition.Name + " " + value.ToString(); break; } }
TaskDialog.Show("Parameters list", s);
Now TaskDialog.show() will show you the element's parameter name and its corresponding value in a dialog.
I hope this helps.
If this helped solve your problem please mark it as solution, so other users can get this solutions as well
What am I doing wrong?
I made a modification in the code to test using SelectElement:
using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using System; namespace TesteIncendio2 { [Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { 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; FamilyInstance beam = null; string s = ""; try { Element e = SelectElement(uidoc, doc); Element SelectElement(UIDocument Uidoc, Document Doc) { Reference reference = Uidoc.Selection.PickObject(ObjectType.Element); Element element = Uidoc.Document.GetElement(reference); return element; } //Element e; beam = e as FamilyInstance; } catch (Exception ex1) { TaskDialog.Show("Erro 1: ", ex1.ToString()); } using (Transaction t = new Transaction(doc, "param")) { t.Start("param"); try { foreach (Parameter P in beam.Parameters) { switch (P.StorageType) { case StorageType.Double: double valueDouble = P.AsDouble(); s = s + "\n" + P.Definition.Name + " " + valueDouble.ToString(); break; case StorageType.ElementId: ElementId valueElId = P.AsElementId(); s = s + "\n" + P.Definition.Name + " " + valueElId.ToString(); break; case StorageType.Integer: int valueInt = P.AsInteger(); s = s + "\n" + P.Definition.Name + " " + valueInt.ToString(); break; case StorageType.String: string valueStr = P.AsValueString(); s = s + "\n" + P.Definition.Name + " " + valueStr.ToString(); break; } } } catch (Exception ex2) { TaskDialog.Show("Erro 2: ", ex2.ToString()); } TaskDialog.Show("Parameters list", s); t.Commit(); return Result.Succeeded; } } } }
A TaskDialog with the Exception shows this:
Then, a TaskDialog with a random number of parameters appears:
What am I doing wrong again?
What am I doing wrong?
I made a modification in the code to test using SelectElement:
using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using System; namespace TesteIncendio2 { [Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { 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; FamilyInstance beam = null; string s = ""; try { Element e = SelectElement(uidoc, doc); Element SelectElement(UIDocument Uidoc, Document Doc) { Reference reference = Uidoc.Selection.PickObject(ObjectType.Element); Element element = Uidoc.Document.GetElement(reference); return element; } //Element e; beam = e as FamilyInstance; } catch (Exception ex1) { TaskDialog.Show("Erro 1: ", ex1.ToString()); } using (Transaction t = new Transaction(doc, "param")) { t.Start("param"); try { foreach (Parameter P in beam.Parameters) { switch (P.StorageType) { case StorageType.Double: double valueDouble = P.AsDouble(); s = s + "\n" + P.Definition.Name + " " + valueDouble.ToString(); break; case StorageType.ElementId: ElementId valueElId = P.AsElementId(); s = s + "\n" + P.Definition.Name + " " + valueElId.ToString(); break; case StorageType.Integer: int valueInt = P.AsInteger(); s = s + "\n" + P.Definition.Name + " " + valueInt.ToString(); break; case StorageType.String: string valueStr = P.AsValueString(); s = s + "\n" + P.Definition.Name + " " + valueStr.ToString(); break; } } } catch (Exception ex2) { TaskDialog.Show("Erro 2: ", ex2.ToString()); } TaskDialog.Show("Parameters list", s); t.Commit(); return Result.Succeeded; } } } }
A TaskDialog with the Exception shows this:
Then, a TaskDialog with a random number of parameters appears:
What am I doing wrong again?
Hi @nelsonhp3 ,
I see no problem in your code.
The taskdialog which appears shows the element's parameters and its value.
So that you can easily see the element' parameter in UI using taskdialog.
Now you know how to get the element's parameters and its position.
So as you said, You can now create a list and add beam's parameters and its positions to the list.
I hope it clarifies
Hi @nelsonhp3 ,
I see no problem in your code.
The taskdialog which appears shows the element's parameters and its value.
So that you can easily see the element' parameter in UI using taskdialog.
Now you know how to get the element's parameters and its position.
So as you said, You can now create a list and add beam's parameters and its positions to the list.
I hope it clarifies
Can't find what you're looking for? Ask the community or share your knowledge.