72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
|
|||
|
|
namespace Sai.Toolkit.Revit.Helpers;
|
|||
|
|
/// <summary>
|
|||
|
|
/// 已经打开文档
|
|||
|
|
/// </summary>
|
|||
|
|
public class HasActiveDocument : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) => applicationData.ActiveUIDocument != null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 命令在平面视图可用
|
|||
|
|
/// </summary>
|
|||
|
|
public class EnableInViewPlan : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
|
|||
|
|
{
|
|||
|
|
return applicationData.ActiveUIDocument?.Document.ActiveView is ViewPlan
|
|||
|
|
&& applicationData.ActiveUIDocument?.Document.IsFamilyDocument == false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 项目文档可用
|
|||
|
|
/// </summary>
|
|||
|
|
public class OnProjectDocument : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
|
|||
|
|
{
|
|||
|
|
var doc = applicationData?.ActiveUIDocument?.Document;
|
|||
|
|
if (doc != null) { return !doc.IsFamilyDocument; }
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 图纸视图可用
|
|||
|
|
/// </summary>
|
|||
|
|
internal class EnableInViewSheet : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) =>
|
|||
|
|
applicationData.ActiveUIDocument?.Document.ActiveView is ViewSheet && applicationData.ActiveUIDocument?.Document.IsFamilyDocument == false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 三维视图可用
|
|||
|
|
/// </summary>
|
|||
|
|
internal class EnableInView3D : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) =>
|
|||
|
|
applicationData.ActiveUIDocument?.Document.ActiveView is View3D && applicationData.ActiveUIDocument?.Document.IsFamilyDocument == false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 命令在剖面、立面可用
|
|||
|
|
/// </summary>
|
|||
|
|
internal class EnableInViewSection : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) =>
|
|||
|
|
applicationData.ActiveUIDocument?.Document.IsFamilyDocument == false && applicationData.ActiveUIDocument.Document.ActiveView is ViewSection;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 族文档可用
|
|||
|
|
/// </summary>
|
|||
|
|
internal class EnableInFamilyDocument : IExternalCommandAvailability
|
|||
|
|
{
|
|||
|
|
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) =>
|
|||
|
|
applicationData.ActiveUIDocument?.Document.IsFamilyDocument == true;
|
|||
|
|
}
|