public static void ExecuteSolid2(ExternalCommandData commandData)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
var app = uiapp.Application;
Document doc = uidoc.Document;
IList<Reference> references = uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Face);
IList<IList<IList<XYZ>>> all = new List<IList<IList<XYZ>>>();
foreach (Reference reference in references)
{
Face face = doc.GetElement(reference).GetGeometryObjectFromReference(reference) as Face;
IList<IList<XYZ>> loopVertices = new List<IList<XYZ>>();
PlanarFace planarFace = face as PlanarFace;
if (!planarFace.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ))
{
EdgeArrayArray edgeArrayArray = planarFace.EdgeLoops;
foreach (EdgeArray ea in edgeArrayArray)
{
IList<XYZ> loops = new List<XYZ>();
foreach (Edge e in ea)
{
Curve c = e.AsCurve();
loops.Add(c.GetEndPoint(0));
}
loopVertices.Add(loops);
}
}
all.Add(loopVertices);
}
CreateTessellatedShape(doc, all, ElementId.InvalidElementId);
// return Result.Succeeded;
}
public static void CreateTessellatedShape(Document doc, IList<IList<IList<XYZ>>> all, ElementId materialId)
{
TessellatedShapeBuilder builder = new TessellatedShapeBuilder();
builder.OpenConnectedFaceSet(true);
foreach (IList<IList<XYZ>> loopVertices in all)
{
TessellatedFace tessellatedFace = new TessellatedFace(loopVertices, materialId);
if (builder.DoesFaceHaveEnoughLoopsAndVertices(tessellatedFace))
{
builder.AddFace(tessellatedFace);
}
}
builder.CloseConnectedFaceSet();
builder.Target = TessellatedShapeBuilderTarget.AnyGeometry;
builder.Fallback = TessellatedShapeBuilderFallback.Mesh;
builder.Build();
TessellatedShapeBuilderResult result = builder.GetBuildResult();
using (Transaction t = new Transaction(doc, "Create tessellated direct shape"))
{
t.Start();
DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Floors));
ds.ApplicationId = "Application id";
ds.ApplicationDataId = "Geometry object id";
ds.SetShape(result.GetGeometricalObjects());
t.Commit();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น