using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Threading;
namespace RevitGeometry
{
[Transaction(TransactionMode.Manual)]
public sealed partial class TriangulateGeometry : IExternalCommand
{
private static void GetGeometry(object commandData)
{
Document document = ((ExternalCommandData)commandData).Application.ActiveUIDocument.Document;
Element element = document.GetElement(new ElementId(2396118));
GeometryElement geometryElement = element.get_Geometry(new Options { DetailLevel = ViewDetailLevel.Fine });
foreach (GeometryObject geometryObject in geometryElement)
{
Solid solid = geometryObject as Solid;
Face face = solid.Faces.get_Item(0);
Mesh mesh = face.Triangulate(0);
}
}
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
//works
//GetGeometry(commandData);
//doesn't work
Thread secondThread = new Thread(GetGeometry);
secondThread.Start(commandData);
secondThread.Join();
}
catch (Exception)
{
return Result.Failed;
}
return Result.Succeeded;
}
}
}