This commit is contained in:
GG Z
2025-05-05 17:03:49 +08:00
parent 5b6d67b571
commit 74532b77be
9 changed files with 0 additions and 345 deletions

View File

@@ -1,93 +0,0 @@
using System.IO;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace ShrlAlgo.Addin.Test
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
internal class CheckCollision : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//程序UI界面
var uiapp = commandData.Application;
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
var uidoc = uiapp.ActiveUIDocument;
//获取位置和场地 视图(多个视图)管理 获取元素Revit 项目里的全部元素)
var doc = uidoc.Document;
//当前视图
var view = doc.ActiveView;
var collector = new FilteredElementCollector(doc, view.Id)
.OfClass(typeof(MEPCurve))
.WhereElementIsNotElementType().ToList();
// 检查管线之间的碰撞
var collisions = CheckPipeCollisionsParallel(doc, collector);
// 显示碰撞结果
ShowCollisionResults(collisions);
return Result.Succeeded;
}
public List<Tuple<Element, Element>> CheckPipeCollisionsParallel(Document doc, List<Element> pipes)
{
var collisions = new List<Tuple<Element, Element>>();
// 使用 Parallel.For 并行检查碰撞
Parallel.For(0, pipes.Count, i =>
{
for (var j = i + 1; j < pipes.Count; j++)
{
var pipe1 = pipes[i];
var pipe2 = pipes[j];
// 使用 ElementIntersectsElementFilter 检查碰撞
var filter = new ElementIntersectsElementFilter(pipe1);
var collector = new FilteredElementCollector(doc, [pipe2.Id]);
collector.WherePasses(filter);
if (collector.Any())
{
// 如果检测到碰撞,记录下来
lock (collisions)
{
collisions.Add(new Tuple<Element, Element>(pipe1, pipe2));
}
}
}
});
return collisions;
}
public void ShowCollisionResults(List<Tuple<Element, Element>> collisions)
{
if (collisions.Count == 0)
{
TaskDialog.Show("碰撞检查", "未发现碰撞");
}
else
{
var message = new StringBuilder();
message.AppendLine("发现碰撞:");
foreach (var collision in collisions)
{
message.AppendLine($"管线 {collision.Item1.Id} 与管线 {collision.Item2.Id} 发生碰撞");
}
ExportCollisionResultsToFile(message.ToString());
//TaskDialog.Show("碰撞检查", message.ToString());
}
}
public void ExportCollisionResultsToFile(string content)
{
// 获取桌面路径
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// 创建文件路径
var filePath = Path.Combine(desktopPath, "碰撞检查.txt");
// 写入文件
File.WriteAllText(filePath, content);
}
}
}

View File

@@ -1,12 +0,0 @@
using Autodesk.Revit.DB;
namespace ShrlAlgo.Addin.Test;
public class InsertInfo
{
public string Name { get; set; }
public XYZ InsertPoint { get; set; }
public double Radian { get; set; }
public double Length { get; set; }
}

View File

@@ -1,20 +0,0 @@
using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Nice3point.Revit.Toolkit.External;
namespace ShrlAlgo.Addin.Test;
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class SeparateModel : ExternalCommand
{
public override void Execute()
{
SeparateModelWin win = new SeparateModelWin();
win.Show();
}
}

View File

@@ -1,31 +0,0 @@
<Window
x:Class="ShrlAlgo.Addin.Test.SeparateModelWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:AduSkin="https://github.com/aduskin"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ShrlAlgo.Addin.Test"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="拆分模型"
Width="300"
Height="300"
SizeToContent="Height"
Topmost="True"
mc:Ignorable="d">
<Grid>
<StackPanel Margin="5">
<AduSkin:MetroTextBox
x:Name="TbFileName"
Margin="5"
InputHint="文件名" />
<AduSkin:MetroTextBox
x:Name="TbFolder"
Margin="5"
InputHint="保存路径" />
<AduSkin:MetroButton
Margin="5"
Click="MetroButton_Click"
Content="拆分" />
</StackPanel>
</Grid>
</Window>

View File

@@ -1,99 +0,0 @@
using System.IO;
using System.Windows;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External.Handlers;
using ShrlAlgoToolkit.Revit.Assists;
using Exception = System.Exception;
using UIFrameworkServices;
namespace ShrlAlgo.Addin.Test;
/// <summary>
/// SeparateModelWin.xaml 的交互逻辑
/// </summary>
public partial class SeparateModelWin
{
ActionEventHandler separate = new ActionEventHandler();
public SeparateModelWin()
{
InitializeComponent();
TbFolder.Text = "F:\\燃气改造项目\\归档";
}
private void MetroButton_Click(object sender, RoutedEventArgs e)
{
separate.Raise(
uiapp =>
{
var uidoc = uiapp.ActiveUIDocument;
var doc = uidoc.Document;
var list = uidoc.Selection.GetElementIds();
if (list.Count == 0)
{
MessageBox.Show("未选中元素", "提示");
return;
}
var walls = list.Select(id => doc.GetElement(id)).Where(e => e is Wall).Select(e => e.Id).ToList();
var others = list.Select(id => doc.GetElement(id)).Where(e => e is not Wall).Select(e => e.Id).ToList();
SpearateByIds(doc, walls, true);
SpearateByIds(doc, others, false);
using (Transaction trans = new Transaction(doc, "删除选中"))
{
try
{
trans.Start();
doc.Delete(list);
trans.Commit();
}
catch (Exception ex)
{
throw ex;
}
}
});
}
private void SpearateByIds(Document doc, System.Collections.Generic.ICollection<ElementId> list, bool isA)
{
var allOthers = doc.OfModelCollector()?
.Excluding(list)
.ToElementIds();
if (allOthers == null)
{
return;
}
var ids = doc.OfClass<ImportInstance>().ToElementIds();
var modelLineIds = doc.OfCollector().OfCategory(BuiltInCategory.OST_Lines).Select(e => e.Id).ToList();
var texts = doc.OfCollector().OfCategory(BuiltInCategory.OST_TextNotes).Select(e => e.Id).ToList();
using (Transaction trans = new Transaction(doc, "拆分模型"))
{
try
{
trans.Start();
doc.Delete(allOthers);
doc.Delete(ids);
doc.Delete(modelLineIds);
doc.Delete(texts);
trans.Commit();
}
catch (Exception ex)
{
throw ex;
}
}
if (!Directory.Exists(TbFolder.Text))
{
Directory.CreateDirectory(TbFolder.Text);
}
var fileName = isA ? TbFileName.Text + "-A" : TbFileName.Text + "-GE";
var filePath = Path.Combine(TbFolder.Text, $"{fileName}.rvt");
SaveAsOptions options = new SaveAsOptions() { OverwriteExistingFile = true, PreviewViewId = doc.ActiveView.Id, Compact = true };
doc.SaveAs(filePath, options);
QuickAccessToolBarService.performMultipleUndoRedoOperations(true, 1);
}
}

View File

@@ -1,50 +0,0 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace ShrlAlgo.Addin.Test
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class SetHeight : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//程序UI界面
var uiapp = commandData.Application;
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
var uidoc = uiapp.ActiveUIDocument;
//程序
var app = uiapp.Application;
//获取位置和场地 视图(多个视图)管理 获取元素Revit 项目里的全部元素)
var doc = uidoc.Document;
//获取所有打开文档
var docset = uiapp.Application.Documents;
//当前视图
var view = doc.ActiveView;
var ids = uidoc.Selection.GetElementIds();
using (var ts = new Transaction(doc, "设置净高"))
{
ts.Start();
try
{
foreach (var id in ids)
{
var elem = doc.GetElement(id);
var param = elem.GetParameters("h").FirstOrDefault();
var height = elem.GetParameters("净高").FirstOrDefault();
height.Set(param.AsValueString());
}
}
catch (Exception)
{
return Result.Failed;
}
ts.Commit();
}
return Result.Succeeded;
}
}
}

View File

@@ -1,13 +0,0 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
namespace WPFluent.Gallery.Services.Contracts;
public interface IWindow
{
event RoutedEventHandler Loaded;
void Show();
}

View File

@@ -1,27 +0,0 @@
namespace WPFluent.Controls;
/// <summary>
/// Used to initialize the library controls with static values.
/// </summary>
public static class ControlsServices
{
#if NET48_OR_GREATER || NETCOREAPP3_0_OR_GREATER
internal static IServiceProvider? ControlsServiceProvider { get; private set; }
/// <summary>
/// Accepts a ServiceProvider for configuring dependency injection.
/// </summary>
public static void Initialize(IServiceProvider? serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
ControlsServiceProvider = serviceProvider;
}
#endif
}