One of the most exciting areas of potential API development is checking the building… Whether trying to determine if the egresses are short enough, or whether there is a nurses station close enough to each room, or just understanding how buildings, floors and rooms are modeled – there are a lot of things to check for. Historically, these things have been hard to check for – it was far easier to just look at a drawing than to try and figure it out.
But all that is beginning to change with some neat new APIs in 2010, which give you some tools to help understand the building and spatial relationships between objects.
One of the classic CAD solutions to these kinds of problems is “shooting rays” through your model… That is, set a point and a vector, then see what that “ray” hits. This was kind of possible with some creative math prior to 2010 – but it’s both better and easier now in 2010.
The new mechanism:
Document.FindReferencesByDirection( origin, direction, View3D)
The new method returns back an array of references – and the reference class has been upgraded to include:
- Type of Reference (Surface hit, Element hit, Edge, Foreign, Mesh)
- GeometryObject of the hit
- XYZ location of the hit
- Distance of the hit from the origin (“Proximity Parameter”), UV location of the hit on a surface (if appropriate)
Important Note: The View3d that you specify controls a few things – first, if you’ve got elements or categories hidden, those do not seem to be “hit”… Also, remember that if you’ve got model phases, the ray will follow the phase of the view.
Still, it’s a great new feature for those who are trying to use the API for any kind of building analysis.
Where am I?
The other enhancements in the category of spatial awareness relate to being inside a particular architectural room or MEP space. If you want to test if a given point is in a known room or space, you now have:
- Room.IsPointInRoom( xyz )
- Space.IsPointInSpace( xyz )
Conversely – if you don’t know where a particular XYZ point is at all, you can ask:
- Document.GetRoomAtPoint (xyz)
- Document.GetSpaceAtPoint (xyz)
I think these enhancements are also critical… while FamilyInstances have long known which room they were in – these API enhancements give a great variety of additional power for analyzing buildings.