Revit快速开发工具拓展包 xml.Revit.Toolkit.
$ dotnet add package xml.Revit.ToolkitAutodesk Revit 2020 - 2024
安装 2024 <PackageReference Include="xml.Revit.Toolkit" Version="2024.*-*" />
安装 2023 <PackageReference Include="xml.Revit.Toolkit" Version="2023.*-*" />
安装 2022 <PackageReference Include="xml.Revit.Toolkit" Version="2022.*-*" />
安装 2021 <PackageReference Include="xml.Revit.Toolkit" Version="2021.*-*" />
安装 2020 <PackageReference Include="xml.Revit.Toolkit" Version="2020.*-*" />
可使用取消任务令牌 CancellationTokenSource
/* 作 者: xml
** 创建时间: 2024/2/16 20:26:06
**
** Copyright 2024 by zedmoster
** Permission to use, copy, modify, and distribute this software in
** object code form for any purpose and without fee is hereby granted,
** provided that the above copyright notice appears in all copies and
** that both that copyright notice and the limited warranty and
** restricted rights notice below appear in all supporting
** documentation.
*/
using System.Diagnostics;
using Autodesk.Revit.DB;
using xml.Revit.Toolkit.Attributes;
using xml.Revit.Toolkit.Extensions;
using xml.Revit.Toolkit.Utils;
namespace xml.Revit.Dev
{
[Xml("TaskRevit", "测试 TaskRevit")]
[Transaction(TransactionMode.Manual)]
public class Cmd : XmlExternalCommand
{
protected override void Execute(ref string message, ElementSet elements)
{
Task.Run(async () =>
{
var source = new CancellationTokenSource(80);
var token = source.Token;
try
{
await XmlDoc.Instance.RevitTask.RunAsync(
() =>
{
var doc = uidoc.Document;
doc.Transaction(
t =>
{
for (int i = 0; i < 100; i++)
{
if (token.IsCancellationRequested)
return;
var detailArc = doc.CreateDetailArc(XYZ.BasisX * i);
Debug.Write(detailArc.Id);
}
},
"Task token"
);
},
token
);
}
finally
{
source.Dispose();
}
});
}
}
}
如何使用简单的任务进度条
/* 作 者: xml
** 创建时间: 2024/4/19 20:26:06
**
** Copyright 2024 by zedmoster
** Permission to use, copy, modify, and distribute this software in
** object code form for any purpose and without fee is hereby granted,
** provided that the above copyright notice appears in all copies and
** that both that copyright notice and the limited warranty and
** restricted rights notice below appear in all supporting
** documentation.
*/
using Autodesk.Revit.DB;
using xml.Revit.Toolkit.Attributes;
using xml.Revit.Toolkit.Extensions;
using xml.Revit.Toolkit.Utils;
using xml.Revit.Toolkit.Views;
namespace xml.Revit.Dev
{
[Xml("测试进度条")]
[Transaction(TransactionMode.Manual)]
public sealed class Cmd : XmlExternalCommand
{
protected override void Execute(ref string message, ElementSet elements)
{
var doc = uidoc.Document;
using var progressBarView = new ProgressBarWindow();
doc.TransactionGroup(tg =>
{
progressBarView.Run(
Enumerable.Range(0, 100),
i =>
{
var pnt = XYZ.BasisX * i;
doc.Transaction(t => doc.CreateDetailArc(pnt));
Thread.Sleep(50);
}
);
});
}
}
}