-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathSoildIntersectCommand.cs
More file actions
58 lines (56 loc) · 2.28 KB
/
SoildIntersectCommand.cs
File metadata and controls
58 lines (56 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Diagnostics.Contracts;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace Test;
[Transaction(TransactionMode.Manual)]
public class SoildIntersectCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// select a extrusion element
Reference reference =
commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element,
new ExtrusionFaceSelectionFilter(),
"Select a extrusion element");
var doc = commandData.Application.ActiveUIDocument.Document;
var e1 = doc.GetElement(reference);
var r2 = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element,
new ExtrusionFaceSelectionFilter(), "Select another extrusion element");
var e2 = doc.GetElement(r2);
// try see intersect soild
var solid1 = GetSolid(e1 as Extrusion);
var solid2 = GetSolid(e2 as Extrusion);
if (solid1 != null && solid2 != null)
{
Solid operation = BooleanOperationsUtils.ExecuteBooleanOperation(solid1, solid2, BooleanOperationsType.Intersect);
// create direct shape
using Autodesk.Revit.DB.Transaction trans = new Transaction(doc, "Create DirectShape");
trans.Start();
DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.ApplicationId = "ApplicationId";
ds.ApplicationDataId = "ApplicationDataId";
ds.SetShape(new GeometryObject[] { operation });
trans.Commit();
}
return Result.Succeeded;
}
Solid? GetSolid(Extrusion? element)
{
Options options = new Options();
options.ComputeReferences = true;
options.DetailLevel = ViewDetailLevel.Fine;
options.IncludeNonVisibleObjects = false;
GeometryElement geomElem = element.get_Geometry(options);
foreach (GeometryObject geomObj in geomElem)
{
Solid? solid = geomObj as Solid;
if (solid != null)
{
return solid;
}
}
return null;
}
}