52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
|
|
using Autodesk.Revit.Attributes;
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
|
|||
|
|
using eTransmitForRevitDB;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.ModelManager;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Revit执行命令
|
|||
|
|
/// </summary>
|
|||
|
|
[Transaction(TransactionMode.Manual)]
|
|||
|
|
|
|||
|
|
public class PureModelCmd : ExternalCommand
|
|||
|
|
{
|
|||
|
|
public override void Execute()
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(Document.PathName))
|
|||
|
|
{
|
|||
|
|
System.Windows.MessageBox.Show("请先保存文件");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var options = new SaveAsOptions()
|
|||
|
|
{
|
|||
|
|
Compact = true,
|
|||
|
|
OverwriteExistingFile = true,
|
|||
|
|
MaximumBackups = 3
|
|||
|
|
};
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Purge(Document);
|
|||
|
|
Document.SaveAs(Document.PathName, options);
|
|||
|
|
System.Windows.MessageBox.Show("清理完成", "提示");
|
|||
|
|
}
|
|||
|
|
catch (System.Exception)
|
|||
|
|
{
|
|||
|
|
System.Windows.MessageBox.Show("清理失败", "提示");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public bool Purge(Document doc)
|
|||
|
|
{
|
|||
|
|
eTransmitUpgradeOMatic eTransmitUpgradeOMatic
|
|||
|
|
= new(doc.Application);
|
|||
|
|
|
|||
|
|
UpgradeFailureType result
|
|||
|
|
= eTransmitUpgradeOMatic.purgeUnused(doc);
|
|||
|
|
|
|||
|
|
return result == UpgradeFailureType.UpgradeSucceeded;
|
|||
|
|
}
|
|||
|
|
}
|