How do i retrieve the start and end points of an element?

How do i retrieve the start and end points of an element?

jmadeley37KVE
Contributor Contributor
375 Views
2 Replies
Message 1 of 3

How do i retrieve the start and end points of an element?

jmadeley37KVE
Contributor
Contributor

Hi all,

 

I've inserted an Adaptive Family Instance in my model using the Revit API and now need to add some annotations on a view. The adaptive family required a start and end point (P1 and P2) to insert, is there a way I can convert the element.Location prooperty to a LocationCurve in Revit 2023?

 

I have tried casting:

 

var locationCurve = element.Location as LocationCurve;

 

but this throws a Null Reference Exception. If anyone knows a way to do this in my version of Revit I would really appreciate the help 🙂

 

Thanks

Jack

0 Likes
Accepted solutions (1)
376 Views
2 Replies
Replies (2)
Message 2 of 3

jmadeley37KVE
Contributor
Contributor

Hi Marty,

 

Thanks for the above. I have previously tried casting to a LocationCurve property, but this seems to throw a NullReferenceException. I have checked that the element.Location property exists and is not null, so it looks like the issue is the actual casting.

 

Is there any other way i could do this?

 

Thanks

Jack

0 Likes
Message 3 of 3

jmadeley37KVE
Contributor
Contributor
Accepted solution

After doing some digging through the documentation, I think I have come up with a way to get the co-ordinates.

 

If you use the method GetFamilyPointPlacementReferences() on the element, you are returned an IList<FamilyPointPlacementReference> object. With this list you can use a Linq Select statement to get the Location object and inside the transform is the origin XYZ.

 

The code looks like this:

 

var references = element.GetFamilyPointPlacementReference().Select(x => x.Location.Origin)

 

The references object is a series of XYZ points that we can then use for any further logic. It looks like the FamilyPointPlacementReference's that are returned from the GetFamilyPointPlacementReference() method have a name which in my case were "END1" and "END2". In my case this worked perfectly for finding the start and end points.

0 Likes