Bounding Boxes Axis Alignment and Transformation

Today we look at some aspects axis-aligned bounding boxes, bounding box transformation and AI news:

<!–
#### All Categories and Parameters
Roman [Nice3point](https://github.com/Nice3point), principle maintained of RevitLookup, presents a new discovery; in his own words:
I made a new discovery for me.
As far as I know, it is impossible to get a list of all built-in parameters using the public Revit API.
We are offered an `enum`, but we cannot get the `Parameter` itself from it.
By exploring private unmanaged code using reflection and pointers, I managed to do it, as described in
the [RevitLookup discussion 183 – retrieve all parameters and categories](https://github.com/jeremytammik/RevitLookup/discussions/183):

Get all built-in parameters

#### Summary
I recently came across a problem from my business partner who wanted to get all the built-in Revit parameters to extract metadata such as data type, units, storage type, etc. As we know, this is not possible using the Autodesk Revit public API.
Similar situation with categories; we can’t get all the built-in categories; so far, the only known available way is to get them from the document settings, but it contains a very truncated list:

Only some categories

By the way,
[The Building Coder samples](https://github.com/jeremytammik/the_building_coder_samples/tree/master) include
some related naive attempts in
the [module `CmdCategories.cs`](https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/CmdCategories.cs).
#### Solution
We can use private code with reflection and pointers; we only need a document.
The point of the method is not to get them but create it.
Example code to get all parameters:
38eee7e926fdef5ad8046b8d6bf6e7a6
Example code to get all categories:
6d806d448ebf5d8e657e0233380fd6af
#### Result
As a result, we have created all the parameters and all the categories of the entire `Enum`:

All built-in parameters
4396f96adfcacd78b3c8292717a01c20
All built-in categories
dfa7791780f87ff3a2b5657ef2c6ad37

#### Limitations
Created parameters have no binding to any element, and consequently have no value, only metadata.
Many thanks to Roman for this interesting in-depth research and documentation!
–>

BoundingBox is Axis-Aligned

Let’s move on to the more mundane question
of how to get the BoundingBox that corresponds to the shape of the family:

Question: I would like to inquire about BoundingBox.
In the left image, the area of the BoundingBox is similar to the shape of the pipe;
however, in the right one, the BoundingBox is much larger than its pipe:

Pipe bounding box

It seems that this happens only for Pipes (probably for System Families).
For FamilyInstance, it seems that they always have a same size for BoundingBox, even if they are rotated.

Is there a way to know the area of the Family, which always corresponds to its shape, regardless of it being rotated or not?

Answer: No, this does not only happen for pipes.
This happens for all kinds of objects that have different dimensions in different directions and are placed at an angle to the cardinal axes.
For instance, a vertical wall at a 45-degree angle in the XY plane will exhibit the exact same behaviour.
This behaviour is intentional.
The Revit bounding box is always aligned with the cardinal axes.
That makes it extremely fast and efficient to work with.
Wikipedia calls this
an axis-aligned bounding box.

BoundingBox Transformation

That question leads over nicely to the explanation why
the transform of linked element creates an empty outline,
solved by appropriately transforming the bounding box:

Question: I want to create an outline from a linked element’s bounding box to use in a BoundingBoxIntersectsFilter.
My approach below works for some cases, but where a link or element is rotated beyond a certain limit, the bounding box goes askew and the Outline(XYZ, XYZ) method returns an empty outline.
I’ve tried scaling the bounding box up with an offset which fixes some cases, but not all of them.
Some advice on solutions would be appreciated.

Non-rotated link

Non-rotated link

Rotated link

Rotated link


# get the elements bounding box
s_BBox = element.get_BoundingBox(doc.ActiveView)
# apply the link documents transform
s_BBox_min = link_trans.OfPoint(s_BBox.Min)
s_BBox_max = link_trans.OfPoint(s_BBox.Max)
# make the outline
new_outline = Outline(s_BBox_min, s_BBox_max)
# make the filter
bb_filter = BoundingBoxIntersectsFilter(new_outline)

Answer: Yes.
You can corrupt the bounding box by transforming it.
I would suggest the following:

  • Extract all eight corner vertices of the bounding box
  • Transform all eight vertices as individual points
  • Create a new bounding box from the eight transformed results

The Building Coder samples include
the method ExpandToContain to
create and enlarge a bounding box point by point that will come in handy for the last step:


/// <summary>
///   Expand the given bounding box to include
///   and contain the given point.
/// </summary>
public static void ExpandToContain(
this BoundingBoxXYZ bb,
XYZ p)
{
bb.Min = new XYZ(Math.Min(bb.Min.X, p.X),
Math.Min(bb.Min.Y, p.Y),
Math.Min(bb.Min.Z, p.Z));
bb.Max = new XYZ(Math.Max(bb.Max.X, p.X),
Math.Max(bb.Max.Y, p.Y),
Math.Max(bb.Max.Z, p.Z));
}

Response: Hi Jeremy, this solution works well, thanks.

Interactive Explanation of SVG Path

I made good use of and learned to love SVG paths working on
the room polygon and furniture picker in SVG and
implementing 2D SVG editing on mobile device with Raphael.

If you would like to enjoy a much nicer explanation of the concepts of SVG paths than I had access to back then, take a quick dive
into understanding SVG paths.

Claude.AI

ChatGPT has a new competitor,
claude.ai.

Eric Boehlke of truevis BIM Consulting pointed it out to me, saying:

You can create an account in the USA or UK, or use VPN to get there.
A competitor to OpenAI. Can upload big files. Any better for coding?

I tested it myself by asking it to summarise
my last blog post,
evaluate a German architectural contract without providing any hint of what it might be, and discuss
the German HOAI.
The results were completely satisfying in all three cases:

Claude.AI analyses blog post

Claude.AI analyses blog post

Claude.AI analyses a German architectural contract

Claude.AI analyses a German architectural contract

Claude.AI discusses the HOAI

Claude.AI discusses the HOAI

Eric suggests:

You could batch that blog post analysis to summarise all of your blog posts programmatically for SEO.

Relativising the Impact of AI

Let’s close with some wise and pertinent thoughts – not following the hype – on the possible impact of AI on our life and economy, presented in the explanation
of why transformative AI is really, really hard to achieve.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading