Cflux
Cflux

Reputation: 1532

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.

Upvotes: 0

Views: 1678

Answers (2)

Cflux
Cflux

Reputation: 1532

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;
    }

Upvotes: 2

Jeremy Tammik
Jeremy Tammik

Reputation: 8339

Congratulations on using RevitLookup and discovering the correct path to the data you are after. As you may have noticed, you have the full source code for RevitLookup at your disposal, so you can simply run it in the debugger to see for yourself step by step how to access the data you are after.

The path is something like GeometryCurve --> Curve --> GetEndPoint. The latter takes an index argument; 0 for the start and 1 for the end point. The difference between the two gives you the direction.

Upvotes: 0

Related Questions