资源简介
通过过滤器ElementIntersectsElementFilter可以获取到与某构件相交的构件,但是不能获取到与其接触但未相交的元素,如果想获取到与其只是接触或者有一定间隔的构件,可以利用ElementIntersectsSolidFilter

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace IntersectionDemo
{
[Transaction(TransactionMode.Manual)]
public class InterTest : IExternalCommand
{
UIApplication uiApp;
UIDocument uiDoc;
Document doc;
public Result Execute(ExternalCommandData commandData ref string message ElementSet elements)
{
uiApp = commandData.Application;
uiDoc = commandData.Application.ActiveUIDocument;
doc = uiDoc.Document;
Element elem = doc.GetElement(uiDoc.Selection.Pickobject(objectType.Element “Select element“));
try
{
Solid solid = GetElementSolid(elem);
List faces = GetFacesFromSolid(solid);
foreach (Face face in faces)
{
PlanarFace planarFace = face as PlanarFace;
//忽略掉顶面和底面
if (planarFace.FaceNormal.IsAlmostEqualTo(new XYZ(0 0 1))
|| planarFace.FaceNormal.IsAlmostEqualTo(new XYZ(0 0 -1)))
{
continue;
}
IList proiles = planarFace.GetEdgesAsCurveLoops();//由face转变为拉伸所需要的截面profile
Solid solidNew = GeometryCreationUtilities.CreateExtrusionGeometry(proiles planarFace.FaceNormal 20/304.8);//生成拉伸体Solid
using (Transaction trans = new Transaction(doc“Create“))
{
trans.Start();
//DirectShape ds = DirectShape.CreateElement(doc new ElementId(BuiltInCategory.OST_GenericModel));
//ds.SetShape(new Geometryobject[] { solidNew });//生成形状
FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Wall));
ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solidNew);
collector.WherePasses(solidFilter);
foreach (Element elemInter in collector)
{
ChangeColor(elemInter);//碰撞改变颜色
}
trans.Commit();
}
}
return Result.Succeeded;
}
catch (Exception exc)
{
message = exc.Message;
return Result.Failed;
}
}
///
/// Change color for intersection obj
///
///
private void ChangeColor(Element element)
{
FilteredElem
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 47616 2020-06-03 16:17 IntersectionDemo\.vs\IntersectionDemo\v14\.suo
文件 8704 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\bin\Debug\IntersectionDemo.dll
文件 15872 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\bin\Debug\IntersectionDemo.pdb
文件 2803 2020-06-02 17:12 IntersectionDemo\IntersectionDemo\IntersectionDemo.csproj
文件 5501 2020-06-03 16:12 IntersectionDemo\IntersectionDemo\InterTest.cs
文件 6852 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 716 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj\Debug\IntersectionDemo.csproj.FileListAbsolute.txt
文件 8704 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj\Debug\IntersectionDemo.dll
文件 15872 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj\Debug\IntersectionDemo.pdb
文件 0 2020-06-02 15:56 IntersectionDemo\IntersectionDemo\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2020-06-02 15:56 IntersectionDemo\IntersectionDemo\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2020-06-02 15:56 IntersectionDemo\IntersectionDemo\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 1358 2020-06-02 15:56 IntersectionDemo\IntersectionDemo\Properties\AssemblyInfo.cs
文件 1015 2020-06-03 16:17 IntersectionDemo\IntersectionDemo.sln
目录 0 2020-06-02 15:56 IntersectionDemo\IntersectionDemo\obj\Debug\TempPE
目录 0 2020-06-03 16:17 IntersectionDemo\.vs\IntersectionDemo\v14
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\bin\Debug
目录 0 2020-06-02 15:57 IntersectionDemo\IntersectionDemo\bin\Release
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj\Debug
目录 0 2020-06-03 16:17 IntersectionDemo\.vs\IntersectionDemo
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\bin
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\obj
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo\Properties
...D.H. 0 2020-06-03 16:17 IntersectionDemo\.vs
目录 0 2020-06-03 16:17 IntersectionDemo\IntersectionDemo
目录 0 2020-06-03 16:18 IntersectionDemo
----------- --------- ---------- ----- ----
115013 26
相关资源
- Revit二次开发源码大全之二
- 2018revit二次开发论文参考
- Autodesk Revit二次开发基础教程 pdf
- revit二次开发读取cad信息并生成构件
- Revit二次开发实现BIM盈利.pdf
- Autodesk Revit二次开发基础教程
- Revit二次开发安装包制作Demo
- Teigha_NET 包含各种版本的TD_Mgd.rar
- Autodesk Revit二次开发基础教程pdf.pdf
- Revit 2018.2 二次开发官方案例+源代码,
- revit二次开发——普通钢筋(revitAPI钢
- revit二次开发
- Revit二次开发-取到楼板轮廓
- Revit二次开发TestBIM工具集源代码
评论
共有 条评论