資源簡介
通過過濾器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
評論
共有 條評論