Points in Dynamo and Revit API are misaligned

Hello everyone, I am working on a tool for creating opening holes based on an idea by Gavin Crump in this video: Create Wall Penetrations using Dynamo! - YouTube

The idea of rotating geometry to get the dimensions of the opening hole is really interesting. I have successfully implemented it in Dynamo. Now, I am trying to create a pyRevit button. The issue I am facing is that the dimensions of the opening hole in Dynamo and Revit API are slightly different (as shown in image 1).


I tried using DirectShape to create the union solid block after rotating and noticed it was misaligned compared to the union solid block in Dynamo (image 2).

Upon further investigation, I discovered that it might be due to the solid centroid between Dynamo and Revit API not aligning (image 3), which could cause the solid block to shift after rotation.

Is there any way for me to achieve the same result as in Dynamo? Because I find the result in Dynamo to be more accurate. The Google Drive link below contains all my code, the Revit file, and the Dynamo file. I hope you can take a look and help me out.
(Wall Opening.7z - Google Drive)

On the Dynamo script:
Using a BoundingBox.ByMinimumVolume will create the required size and rotation
You may have to use Cuboid.Length instead of width

Comments in the Revit API

Calculates the centroid of the solid using an approximation, with an accuracy suitable for architectural purposes. This will correspond only with the center of gravity if the solid represents a homogeneous structure of a single material.

See Jeremy Tammik’s comment on minimal bounding boxes here

hi @Mike.Buttery , thank you for replying. Can you tell me which package the BoundingBox.ByMinimumVolume belongs to? Because I can’t find it.

It is a standard node released with Dynamo 2.13 I believe.

Edit: 2.16 released the non-axis aligned bounding boxes.

I’m using Dynamo 2.13 and can’t find it either.


As I understand it, you guys are suggesting a way to get the dimensions of the bounding box without rotating the solid, right? The discrepancy occurs after rotating the union solid, which is caused by the centers of the solid in Revit API and Dynamo not matching each other.

Edited the post - it’s in 2.16.

1 Like

@Luffy11 I’ve had a bit of a dig and I am able to get an equivalent centroid with the following code

import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager


def intersect_union(solid_a, solids):
    if not isinstance(solids, list):
        solids = [solids]
    solids = [
        BooleanOperationsUtils.ExecuteBooleanOperation(
            solid_a, sld, BooleanOperationsType.Intersect
        )
        for sld in solids
    ]
    union = solids.pop()
    while solids:
        union = BooleanOperationsUtils.ExecuteBooleanOperation(
            union, solids.pop(), BooleanOperationsType.Union
        )
    return union


doc = DocumentManager.Instance.CurrentDBDocument

# Project Units
LENGTH_UNIT = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
LU_LABEL = LabelUtils.GetLabelForUnit(LENGTH_UNIT)  # Human readable

wall = UnwrapElement(IN[0])
services = UnwrapElement(IN[1]) if isinstance(IN[1], list) else [UnwrapElement(IN[1])]

options = Options()
wall_geom = list(wall.get_Geometry(options))[0]
services = [list(s.get_Geometry(options))[0] for s in services]

union = intersect_union(wall_geom, services)

scale = Transform.Identity.ScaleBasisAndOrigin(
    UnitUtils.ConvertFromInternalUnits(1, LENGTH_UNIT)
)

centroid = union.ComputeCentroid()
unit_centroid = scale.OfPoint(centroid)

OUT = unit_centroid

Dynamo
image

Revit
image

You can also get the reverse angle to rotate solids onto axis with the following

wall_angle = wall.Orientation.CrossProduct(XYZ.BasisZ).AngleTo(XYZ.BasisX) # Radians!!!

The Revit API Bounding Box is not as accurate as Dynamo Geometry BoundingBox which is a known ‘feature’

1 Like

Hi @Mike.Buttery , I tried your code but still don’t get the correct result like in Dynamo. Maybe I will use the Dynamo graph instead of trying to code for this task. And it’s so weird to know that the Revit API Bounding Box is not as accurate as Dynamo Bounding Box. Anyway, thanks a lot for your help.