ExtrusionAnalyzer does not produce correct results - some geometry is missed

ExtrusionAnalyzer does not produce correct results - some geometry is missed

harrymattison
Advocate Advocate
626 Views
4 Replies
Message 1 of 5

ExtrusionAnalyzer does not produce correct results - some geometry is missed

harrymattison
Advocate
Advocate

Run the macro in the attached Revit 2025 file

Select the direct shape

Only one loop of lines are created from the ExtrusionAnalyzer - GetExtrusionBase 

There should be two loops of lines for both "halves" of the direct shape.

extrusionanalyzer.png

 

 

		public void ExtrusionAnalyzerTest()
		{
			Document doc = ActiveUIDocument.Document;
			UIDocument uidoc = ActiveUIDocument;
			Element e = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
			GeometryElement ge = e.get_Geometry(new Options());
			foreach (GeometryObject geomObj in ge)
			{
			    if (geomObj is Solid solid)
			    {
			    	ExtrusionAnalyzer ea = ExtrusionAnalyzer.Create(solid, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero), XYZ.BasisZ);
			    	List<CurveLoop> loops = ea.GetExtrusionBase().GetEdgesAsCurveLoops().ToList();
			    	foreach (CurveLoop loop in loops)
			    	{
			    		foreach (Curve curve in loop)
			    		{
			    			makeLine(doc, curve.GetEndPoint(0), curve.GetEndPoint(1));
			    		}
			    	}
			    }
			}
		}
		
	public static ModelLine makeLine(Document doc, XYZ pt1, XYZ pt2)
    {
        if (pt1 == null || pt2 == null)
            return null;

        if (pt1.DistanceTo(pt2) < 0.01)
            return null;

        ModelLine ret = null;
        using (Transaction t = new Transaction(doc, "g"))
        {

            bool started = false;
            try
            {
                t.Start();
                started = true;
            }
            catch
            { }

            ret = (ModelLine)doc.Create.NewModelCurve(Line.CreateBound(pt1, pt2), SketchPlane.Create(doc, makePlane(doc.Application, pt1, pt2)));

            if (started)
                t.Commit();
        }
        return ret;
    }

    private static Plane makePlane(Autodesk.Revit.ApplicationServices.Application app, XYZ pt1, XYZ pt2)
    {
        XYZ v = pt1.Subtract(pt2);
        double dxy = Math.Abs(v.X) + Math.Abs(v.Y);
        XYZ w = (dxy > 0.0001) ? XYZ.BasisZ : XYZ.BasisY;
        XYZ norm = v.CrossProduct(w).Normalize();
        return Plane.CreateByNormalAndOrigin(norm, pt1);
    }

 

 

627 Views
4 Replies
Replies (4)
Message 2 of 5

Moustafa_K
Collaborator
Collaborator

 

When retrieving a GeometryElement from instances such as Families or DirectShapes, it appears that the solids within are merged or combined. DirectShapes, for instance, return a collection of faces as a single solid, even if multiple solids are contained within. However, an intriguing observation arises when creating a Model in Place component with three geometric shapes: using GeometryInstance.GetGeometry() results in two solids. One solid contains all the necessary information, still combined with the faces of all three geometries, and possesses a non-zero volume. The second solid, however, comprises empty faces with zero volume."

 

Moustafa_K_0-1714210773301.png

 

Digging deeper into this interesting case, I recall a static function, SolidUtil.SplitVolumes(Solid), which indeed returns separated transformed solids. When used with ExtrusionAnalyzer, it returns the expected result.

 

Moustafa_K_1-1714210773302.png

 

so the revised part of the could would be

 

 

 

 

foreach (GeometryObject geomObj in ge)
{
	if (geomObj is Solid combinedSolids)
	{
		if (combinedSolids.Volume == 0)
			continue;
		var solidSplits = SolidUtils.SplitVolumes(combinedSolids);
		foreach (var solid in solidSplits)
		{ 
			ExtrusionAnalyzer ea = ExtrusionAnalyzer.Create(solid, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero), XYZ.BasisZ);
			List<CurveLoop> loops = ea.GetExtrusionBase().GetEdgesAsCurveLoops().ToList();
			foreach (CurveLoop loop in loops)
			{
				foreach (Curve curve in loop)
				{
					makeLine(doc, curve.GetEndPoint(0), curve.GetEndPoint(1));
				}
			}
		}
	}
}

 

 

 

 

While this explanation could be a resolution for your task, it fails to address why the ExtrusionAnalyser is unable to identify all solid geometries but instead only selects the initial one.

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 5

harrymattison
Advocate
Advocate

Thank you very much for your response @Moustafa_K - that is a great workaround!

@jeremytammik Can you please file a bug on this too? The development team should know about this, at least to add this limitation to the ExtrusionAnalyzer documentation.

Message 4 of 5

jeremy_tammik
Alumni
Alumni

Dear Harry and Moustafa,

 

Thank you for your report, research and sample material. Sorry to hear about this.

 

I logged the issue REVIT-222328 [ExtrusionAnalyzer misses some geometry] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

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

jeremy_tammik
Alumni
Alumni

The development team analysed and discussed the issue in some depth:

 

This feels "by design"-ish to me, perhaps with some extra documentation. Thoughts?

 

The extrusion analyzer constructs the profile by partitioning all silhouettes of the Solid in the extrusion plane to construct a set of non-intersecting edges. It then identifies one starting edge that is known to be an exterior edge of the profile and subsequently traces the profile by connecting edges end-to-end in a counterclockwise fashion. This is a greedy approach obviously fails when the Solid comprises anything other than a single connected component. Attempting to recover multiple profiles in this case would require quite a bit of extra work that would probably come with a performance hit. I'd say that this is by design, but there is a potential improvement here: add a validator that would check whether the solid is a single connected component. However, there may be significant usage within Revit's regression suite that fails such validation. Taking that approach a step further, we could partition the Solid into its individual connected components (essentially, this is what the workaround of using SolidUtil.SplitVolumes is doing), and combine their individual profiles. However, there is some ambiguity in the case that the profiles overlap – should the total profile be the concatenation of the various profiles, or their boolean union? Arguably, it's inappropriate to consider such geometry as an "extrusion" in the first place.

   

I've updated the ExtrusionAnalyzer documents to make this behavior less confusing. I do not think that it would be advisable to add validation to disallow Solids that comprise multiple connected components, since it's currently possible to use the ExtrusionAnalyzer in cases where the Solid may appear to be an extruded solid, while it is in actuality two or more open and complementary open shells, touching at their free edges. Adding validation would limit behavior in this case.

 

The issue has now been closed as 'By Design'.

  

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