清理ColorPicker,进度条。修复UI问题

This commit is contained in:
2026-02-23 16:49:34 +08:00
parent 1d939d52ed
commit 18174b404c
29 changed files with 1028 additions and 576 deletions

View File

@@ -9,24 +9,55 @@ using Autodesk.Revit.UI.Selection;
using Nice3point.Revit.Toolkit.External;
using ShrlAlgoToolkit.Core.Assists;
using ShrlAlgoToolkit.RevitCore.Base;
namespace ShrlAlgo.Addin.Test;
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class RevitAddin : ExternalCommand
public class RevitAddin : BaseCommand
{
public override void Execute()
protected override void ExecuteCommand()
{
try
// 获取文档中所有的墙
var walls = new FilteredElementCollector(Document)
.OfClass(typeof(Wall))
.ToElements();
if (walls.Count == 0) return;
// 直接调用我们的进度条管理器!
ProgressManager.Run("批量修改墙参数", (reporter, token) =>
{
}
catch (Exception)
{
throw;
}
// 利用之前封装的 TransactionExtensions 开启事务
Document.InvokeInTransaction(() =>
{
for (int i = 0; i < walls.Count; i++)
{
// 1. 检查用户是否点击了“取消”
token.ThrowIfCancellationRequested();
var wall = walls[i];
// 2. 你的 Revit API 操作 (例如修改参数)
var commentsParam = wall.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
if (commentsParam != null && !commentsParam.IsReadOnly)
{
commentsParam.Set($"自动写入 - {i}");
}
// 3. 报告进度 (内置了防卡顿机制,每秒调用几万次都不会卡)
reporter.Report(i + 1, walls.Count, $"正在处理墙: {wall.Name}");
// 如果逻辑非常非常耗时可以考虑在这里短暂休眠让出一点点CPU通常不用加
// Thread.Sleep(1);
}
}, "Batch Update Walls");
});
// 任务结束(无论完成还是取消),后续代码继续执行
TaskDialog.Show("提示", "操作结束或已被取消!");
}
}