BoundingBoxIntersectsFilter with linked model

BoundingBoxIntersectsFilter with linked model

Pei_LiuQ5B9P
Contributor Contributor
384 Views
3 Replies
Message 1 of 4

BoundingBoxIntersectsFilter with linked model

Pei_LiuQ5B9P
Contributor
Contributor

Hi,

 

I'm trying to build a code that checks if an element in the current model (host model) clashes with any elements in a linked model.

 

However, the code seems only to capture the intersection between the element and the 3D view camera in the linked model, which makes sense as the 3D view is very large.

 

Does anyone know the potential reason? I tried both transform and transform.inverse without success. Has anyone successfully used this filter to identify clashes with elements in a linked model? Thank you.

 

 

                    var element_bbox = element.get_BoundingBox(null);

                    // Transform the points to the linked model's coordinate system
                    XYZ point_min_transformed = linkInstance.GetTransform().Inverse.OfPoint(element_bbox.Min);
                    XYZ point_max_transformed = linkInstance.GetTransform().Inverse.OfPoint(element_bbox.Max);

                    //XYZ point_min_transformed = element_bbox.Min;
                    //XYZ point_max_transformed = element_bbox.Max;

                    // Ensure min and max points are valid
                    double minX = Math.Min(point_min_transformed.X, point_max_transformed.X);
                    double minY = Math.Min(point_min_transformed.Y, point_max_transformed.Y);
                    double minZ = Math.Min(point_min_transformed.Z, point_max_transformed.Z);

                    double maxX = Math.Max(point_min_transformed.X, point_max_transformed.X);
                    double maxY = Math.Max(point_min_transformed.Y, point_max_transformed.Y);
                    double maxZ = Math.Max(point_min_transformed.Z, point_max_transformed.Z);

                    // Create new XYZ points with corrected coordinates
                    XYZ correctedMin = new XYZ(minX, minY, minZ);
                    XYZ correctedMax = new XYZ(maxX, maxY, maxZ);

                    Outline myOutLn_transformed = new Outline(correctedMin, correctedMax);

                    // Create the bounding box filter
                    BoundingBoxIntersectsFilter element_bbox_filter = new BoundingBoxIntersectsFilter(myOutLn_transformed);

                    FilteredElementCollector collector = new FilteredElementCollector(linkInstance.GetLinkDocument());
                    IList<Element> potentiallyClashingLinkElements = collector.WhereElementIsNotElementType().WherePasses(element_bbox_filter).Where(e => e.Category != null && e.Category.CategoryType == CategoryType.Model).ToList();

 

 

0 Likes
385 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

Your approach makes total sense to me, and your code looks OK too. Have you searched for previous discussions on collision testing with linked models? The topic has come up regularly in the past, and solution were found. Here is a summary of one such discussion:

   

https://thebuildingcoder.typepad.com/blog/2020/06/set-crop-to-section-box-linked-boundaries-and-inte...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

ewano
Advocate
Advocate

Just a thought, perhaps you could also investigate the ActiveView Transform as well? This stuff has been tricky for me in the past too.

ActiveView = Doc.ActiveView;
ActiveViewBox = (ActiveView as View3D)?.GetSectionBox();
ActiveViewTransform = ActiveViewBox?.Transform;

Have you output something to Revit to identify the extent of your assessment various assessment Outlines?

Cheers,


Ewan



Autodesk ITF 2018-2020 / Senior Project Drafter / Technical & Computational Modelling Specialist / Dynamo Enthusiast

0 Likes
Message 4 of 4

TripleM-Dev.net
Advisor
Advisor

Hi @Pei_LiuQ5B9P,

 

This is tricky, I solved it a couple of years ago with a lot of testing.

First advise is to print out the points used for the outline and see where they are located inside the llinked file, will it clash with anything and does it correctly represent the elements in the host file (untransformed).

 

I ended up using a Solid (SolidUtils) and generating 2 directshapes (to visualize it) one transformed (for the link) and one normal (to check if host elements positions were correctly taken.)

 

It might be off due to: The min/max coordinates from the BoundingBoxXYZ box are propably not representing the viewed element. See it's documentation ("Coordinates determined by it's transform"), this will also depend on how the BoundingBoxXYZ is retrieved.

So I ended up using the Box transform to edit the min/max point. (because the box is always aligned with the x/y, using the Transform.origin to correct the min/max would be enough)

 

Using BoundingBoxIntersectsFilter is correct, but not enough. (btw Inverse of the Linkinstance transform is correct to use)

Using BoundingBoxIntersectsFilter is only usefull to reduce the elements to check for interference, after this you actually need a Solid of the host element to detect actual intersecting elements in the link.

 

Use ElementIntersectsSolidFilter for this, with a inverse transformed solid of the host element

Use SolidUtils.CreateTransformed to create a transformed solid of the host solid element

 

First using BoundingBoxIntersectsFilter  and then ElementIntersectsSolidFilter speeds up the addin as the elements BoundingBox is fast.

 

Hope it makes sense...

- Michel

 

ps. My own intersection detect with a link went from 30min to seconds with this optimalization.

Also, with the Outline creation I always take a little extra (a Fuzz) to make sure it doesn't just miss something.

0 Likes