Why is Element.Location null for perfectly valid FamilyInstance objects?

Why is Element.Location null for perfectly valid FamilyInstance objects?

Anonymous
Not applicable
3,172 Views
5 Replies
Message 1 of 6

Why is Element.Location null for perfectly valid FamilyInstance objects?

Anonymous
Not applicable

In the sample model, there is a door with ElementId: `485452`.  If you retrieve this door (as a FamilyInstance object), and do `.Location`, then it return `null`. You can also see this just using the Revit Lookup tool.

 

Why is this?  How can I robustly get the location of a door?

0 Likes
Accepted solutions (1)
3,173 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support
Location L = e.Location;
                        LocationPoint Lp = L as LocationPoint;
                        TaskDialog.Show("Location", Lp.Point.X.ToString()+" ,"+Lp.Point.Y.ToString()+" "+Lp.Point.Z.ToString());

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks, but in that example, `Lp.Point`  will throw a NullReferenceException.

0 Likes
Message 4 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Could to please explain in detail about what you are trying to achieve and what kind of errors you get to reproduce the issue?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

You'll get better help from providing more detail i.e. which sample file?

 

I assume it is this one below but this is not the only sample file provided with Revit:

Capture0619.PNG

 

Origin highlighted with model lines, coordinate origin of spot coordinate set to relative

 

This is from a door family template related to curtain walls. So the origin can be found from the origin of it's Transform as below. Not sure if standard doors (those not hosted on curtain walls) fill out the location point property or not. In this case the base point relates to where the reference plane and level (which are usually set to defines origin) intersect in the family. Sometimes (as in this case) there are no ref planes with 'defines origin' set but the intersection of the named ref planes and levels that come with the template e.g. 'Center (Front/Back)' usually define the origin in those cases.  I've constructed the same point in the project with model lines to demonstrate.

 

Capture0619b.PNG

 

 

For robustness you check location for null and then use a fall back method such as above for finding origin. I always think origin in families is a bit arbitrary i.e. it is usually based on where author decides it. The family template in this instance sets it at the bottom of door (which is logical) but the 50.8mm offset not so logical. Perhaps if I understood this form of family template better it would make sense however. Doors are not my thing, holes in walls are. 

 

Message 6 of 6

Anonymous
Not applicable

Got it, thanks!  Ok, so I'm guessing the transform (and the Origin of the transform) are always non-null.
But I guess to robustly get the "location" of the door with some consistent definition of "location" such as "at the floor level, in the center of the door when closed", I will need to use geometry.

 

And yes, sorry about not specifying the particular sample project.  Will do next time!

0 Likes