Message 1 of 5
ExtrusionAnalyzer does not produce correct results - some geometry is missed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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);
}