Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get start and end points coordinates of structural beams

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
nelsonhp3
5126 Views, 5 Replies

Get start and end points coordinates of structural beams

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.

Capturar3.PNG

Please help!

 

5 REPLIES 5
Message 2 of 6
naveen.kumar.t
in reply to: nelsonhp3

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.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 6
nelsonhp3
in reply to: naveen.kumar.t

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:

 

Capturar4.PNG

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?

Capturar5.PNG

 

Message 4 of 6
naveen.kumar.t
in reply to: nelsonhp3

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 wellSmiley Happy

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 6
nelsonhp3
in reply to: naveen.kumar.t

What am I doing wrong?Capturar12.PNG

 

 

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:Capturar8.PNG

Then, a TaskDialog with a random number of parameters appears:


Capturar10.PNGCapturar7.PNGCapturar9.PNGCapturar6.PNG

 

 

 

 

 

 

 

 

What am I doing wrong again? Smiley LOL

Message 6 of 6
naveen.kumar.t
in reply to: nelsonhp3

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

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report