修复bug和新增部分功能

This commit is contained in:
GG Z
2024-10-08 16:21:39 +08:00
parent 082b781808
commit b6647218be
44 changed files with 1709 additions and 1390 deletions

View File

@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
namespace RvAddinTest
@@ -19,22 +14,18 @@ namespace RvAddinTest
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//程序UI界面
UIApplication uiapp = commandData.Application;
var uiapp = commandData.Application;
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
UIDocument uidoc = uiapp.ActiveUIDocument;
//程序
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
var uidoc = uiapp.ActiveUIDocument;
//获取位置和场地 视图(多个视图)管理 获取元素Revit 项目里的全部元素)
Document doc = uidoc.Document;
//获取所有打开文档
DocumentSet docset = uiapp.Application.Documents;
var doc = uidoc.Document;
//当前视图
View view = doc.ActiveView;
List<Element> collector = new FilteredElementCollector(doc, view.Id)
var view = doc.ActiveView;
var collector = new FilteredElementCollector(doc, view.Id)
.OfClass(typeof(MEPCurve))
.WhereElementIsNotElementType().ToList();
// 检查管线之间的碰撞
List<Tuple<Element, Element>> collisions = CheckPipeCollisionsParallel(doc, collector);
var collisions = CheckPipeCollisionsParallel(doc, collector);
// 显示碰撞结果
ShowCollisionResults(collisions);
@@ -42,18 +33,18 @@ namespace RvAddinTest
}
public List<Tuple<Element, Element>> CheckPipeCollisionsParallel(Document doc, List<Element> pipes)
{
List<Tuple<Element, Element>> collisions = new List<Tuple<Element, Element>>();
var collisions = new List<Tuple<Element, Element>>();
// 使用 Parallel.For 并行检查碰撞
Parallel.For(0, pipes.Count, i =>
{
for (int j = i + 1; j < pipes.Count; j++)
for (var j = i + 1; j < pipes.Count; j++)
{
Element pipe1 = pipes[i];
Element pipe2 = pipes[j];
var pipe1 = pipes[i];
var pipe2 = pipes[j];
// 使用 ElementIntersectsElementFilter 检查碰撞
ElementIntersectsElementFilter filter = new ElementIntersectsElementFilter(pipe1);
FilteredElementCollector collector = new FilteredElementCollector(doc, new ElementId[] { pipe2.Id });
var filter = new ElementIntersectsElementFilter(pipe1);
var collector = new FilteredElementCollector(doc, [pipe2.Id]);
collector.WherePasses(filter);
if (collector.Any())
@@ -77,9 +68,9 @@ namespace RvAddinTest
}
else
{
StringBuilder message = new StringBuilder();
var message = new StringBuilder();
message.AppendLine("发现碰撞:");
foreach (Tuple<Element, Element> collision in collisions)
foreach (var collision in collisions)
{
message.AppendLine($"管线 {collision.Item1.Id} 与管线 {collision.Item2.Id} 发生碰撞");
}
@@ -90,10 +81,10 @@ namespace RvAddinTest
public void ExportCollisionResultsToFile(string content)
{
// 获取桌面路径
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// 创建文件路径
string filePath = Path.Combine(desktopPath, "碰撞检查.txt");
var filePath = Path.Combine(desktopPath, "碰撞检查.txt");
// 写入文件
File.WriteAllText(filePath, content);