revit-apirevitbim

Revit API - How to get existing detail line Origin and Direction?


This might be a newb question but I haven't found any information on it. I've found info on how to create new detail lines but that's about it.

I'm trying to retrieve the origin and direction of an existing detail line but I can't figure out how. I am able to access the geometry curve but that only seems to give me the start and end points of the line with this.

Does anyone know how to achieve this?

Here's my code:

FilteredElementCollector colFamDetailLineElements = new FilteredElementCollector(familyDoc)
    .OfClass(typeof(CurveElement)).OfCategory(BuiltInCategory.OST_Lines);

if (colFamDetailLineElements.Count() != 0)
    {
    foreach (DetailLine x in colFamDetailLineElements)
        {
        string length = x.GeometryCurve.ApproximateLength.ToString();                        
        string start = x.GeometryCurve.GetEndParameter(0).ToString();
        string stop = x.GeometryCurve.GetEndParameter(1).ToString();

        Debug.Print("line Id: " + x.Id + ". line start: " + start + ". line stop: " + stop);

         Debug.Print("Titleblock Line length: " + x.GeometryCurve.Length.ToString());
         }
    }

output:

line Id: 2563. line start: 2.66453525910038E-15. line stop: 0.416666666666672
Titleblock Line length: 0.41666666666667

enter image description here

All help and direction is appreciated.


Solution

  • Figured it out finally almost 2 months later and its pretty simple.

    If you have an existing DetailLine, you can do this:

    FilteredElementCollector detailLineCollection = 
    new FilteredElementCollector(familyDoc).OfClass(typeof(CurveElement))
    .OfCategory(BuiltInCategory.OST_Lines);
    
    foreach (DetailLine x in detailLineCollection)
        {
            Line xline = x.GeometryCurve as Line;
            double xlineDirectionX = xline.Direction.X;
            double xlineDirectionY = xline.Direction.Y;
        }