-
-
Save ricaun/35baa2ed9f33de3487e46e4217b5e8bd to your computer and use it in GitHub Desktop.
TessellatedShapeCreatorUtils Revit sample code with Command to create a D4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autodesk.Revit.Attributes; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.UI; | |
using System; | |
using System.Collections.Generic; | |
namespace RevitAddin.Commands | |
{ | |
[Transaction(TransactionMode.Manual)] | |
public class CommandTessellatedD4 : IExternalCommand | |
{ | |
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet) | |
{ | |
UIApplication uiapp = commandData.Application; | |
Document document = uiapp.ActiveUIDocument.Document; | |
var shapeBuilder = TessellatedShapeCreatorUtils.Create(builder => | |
{ | |
var points = new List<XYZ>(4); | |
points.Add(new XYZ(0, 0, 0)); // 0 origin | |
points.Add(new XYZ(1, 0, 0)); // 1 right | |
points.Add(new XYZ(0, 1, 0)); // 2 back | |
points.Add(new XYZ(0, 0, 1)); // 3 top | |
var materialId = ElementId.InvalidElementId; | |
builder.AddFace(new TessellatedFace(new[] { points[2], points[1], points[0] }, materialId)); // bottom face | |
builder.AddFace(new TessellatedFace(new[] { points[0], points[1], points[3] }, materialId)); // front face | |
builder.AddFace(new TessellatedFace(new[] { points[1], points[2], points[3] }, materialId)); // diagonal face | |
builder.AddFace(new TessellatedFace(new[] { points[2], points[0], points[3] }, materialId)); // left face | |
}); | |
using (Transaction transaction = new Transaction(document)) | |
{ | |
transaction.Start("Create"); | |
var ds = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel)); | |
ds.SetName(ds.Category.Name); | |
ds.SetShape(shapeBuilder.GetGeometricalObjects()); | |
transaction.Commit(); | |
} | |
return Result.Succeeded; | |
} | |
} | |
public static class TessellatedShapeCreatorUtils | |
{ | |
public static TessellatedShapeBuilderResult Create(Action<TessellatedShapeBuilder> actionBuilder) | |
{ | |
TessellatedShapeBuilder builder = new TessellatedShapeBuilder(); | |
builder.Target = TessellatedShapeBuilderTarget.AnyGeometry; | |
builder.Fallback = TessellatedShapeBuilderFallback.Mesh; | |
builder.OpenConnectedFaceSet(true); | |
actionBuilder?.Invoke(builder); | |
builder.CloseConnectedFaceSet(); | |
builder.Build(); | |
TessellatedShapeBuilderResult result = builder.GetBuildResult(); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revit Api Forum: https://forums.autodesk.com/t5/revit-api-forum/brepbuilder-fails-on-very-simple-example/m-p/12017850