Finding element location by using Bounding Box in Dynamo

Most of the times Revit element location can be easily found in Dynamo with a help of some standard nodes – such as FamilyInstance.Location. There are some element categories however, that can cause a bit of a problem. For instance walls will return their location as a curve rather than a point. Elements that are generated by a sketched boundary (eg. floors) will not return a location at all. If we want to find a location midpoint of such elements we can do so by finding their Bounding Box. It is the smallest possible orthogonal box that can fit our element inside. By calculating a geometrical centre of such a box we can also find a centre of the questioned element. We have to be careful though, as the location point acquired this way might not be always precise. For instance if the object’s boundary is concave, it’s midpoint might even be located outside of the object. To get the Bounding Box of an element in Python we use a following method:

element.get_BoundingBox(View) 

It can happen that the Bounding Box’s range would change depending on a view element is displayed in (view can be cropped for instance). Therefore the function takes a parameter pointing to a view. However we can also pass a ‘None’ value and get a Bounding Box without any modifications. Bounding Box objects have Min and Max properties, that are 3D points defining the box shape in space. Using their (points) coordinates we can calculate a centre point of the box. The entire Python code could look like so:

    import clr
    clr.AddReference("RevitAPI")
    from Autodesk.Revit.DB import *
    #The inputs to this node will be stored as a list in the IN variables.
    elements = UnwrapElement(IN[0])
    points =[]
    for e in elements:
      bb = e.get_BoundingBox(None)
      if not bb is None:
        centre = bb.Min+(bb.Max-bb.Min)/2
        points.append(centre)
    #Assign your output to the OUT variable.
    OUT = points
Posts created 30

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top