Files

54 lines
2.0 KiB
C#
Raw Permalink Normal View History

2025-09-16 16:06:41 +08:00
using System.Linq;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace Szmedi.Test
{
/// <summary>
/// Revit执行命令
/// </summary>
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class CoutCmd : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//程序UI界面
UIApplication uiapp = commandData.Application;
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
UIDocument uidoc = uiapp.ActiveUIDocument;
//程序
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
//获取位置和场地 视图(多个视图)管理 获取元素Revit 项目里的全部元素)
Document doc = uidoc.Document;
//获取所有打开文档
DocumentSet docset = uiapp.Application.Documents;
//当前视图
View view = doc.ActiveView;
var sheets = doc.OfClass<ViewSheet>().Cast<ViewSheet>().OrderBy(sheet => sheet.SheetNumber);
StringBuilder sb = new StringBuilder();
sb.AppendLine("序号,图名,样板出图");
foreach (var sheet in sheets)
{
bool b = true;
foreach (var item in sheet.GetAllPlacedViews())
{
if (doc.GetElement(item) is View3D)
{
b = false;
break;
}
}
var str = b ? "已出图" : "仅示意";
sb.AppendLine($"{sheet.SheetNumber.TrimStart('0')},{sheet.Name},{str}");
}
LogAssists.WriteCSVFile($"{doc.Title}", sb.ToString());
return Result.Succeeded;
}
}
}