Revit二次开发–屏幕截图/图片导出

image_print阅读模式

在Revit API中有一个方法Document.ExportImage(),可以将单个或多个视图导出为图片。
该方法需要传递一个ImageExportOptions类型的参数,在参数中你可以自定义需要导出的视图、图片地址、图片大小等。

单视图导出

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace ScreenShot
{
 [Transaction(TransactionMode.Manual)]
 public class Command : IExternalCommand
 {
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
 ImageExportOptions options = new ImageExportOptions();
 options.ZoomType = ZoomFitType.FitToPage;
 options.ExportRange = ExportRange.CurrentView;
 options.FilePath = @"C:UsersAdministratorDesktopCurrentViewImg";
 options.FitDirection = FitDirectionType.Horizontal;
 options.HLRandWFViewsFileType = ImageFileType.JPEGMedium;
 options.ShadowViewsFileType = ImageFileType.JPEGMedium;
 options.PixelSize = 1920;
 commandData.Application.ActiveUIDocument.Document.ExportImage(options);

 return Result.Succeeded;
 }
 }
}

上面代码将当前视图以JPG图片的形式导出到桌面上;如果只想截取当前视窗中可见的部分(截图),可将options.ExportRange设置为VisibleRegionOfCurrentView

多视图导出

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;

namespace ScreenShot
{
 [Transaction(TransactionMode.Manual)]
 public class Command : IExternalCommand
 {
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
 Document doc = commandData.Application.ActiveUIDocument.Document;
 FilteredElementCollector views = new FilteredElementCollector(doc).OfClass(typeof(View));
 views.OfCategory(BuiltInCategory.OST_Views);
 IList<ElementId> ImageExportList = new List<ElementId>();
 foreach (View view in views)
 {
 if (view.IsTemplate) continue;
 ImageExportList.Add(view.Id);
 }
 var options = new ImageExportOptions
 {
 ZoomType = ZoomFitType.FitToPage,
 PixelSize = 1920,
 FilePath = @"C:UsersAdministratorDesktopViews",
 FitDirection = FitDirectionType.Horizontal,
 HLRandWFViewsFileType = ImageFileType.JPEGMedium,
 ShadowViewsFileType = ImageFileType.JPEGMedium,
 ImageResolution = ImageResolution.DPI_300,
 ExportRange = ExportRange.SetOfViews
 };
 options.SetViewsAndSheets(ImageExportList);
 doc.ExportImage(options);

 return Result.Succeeded;
 }
 }
}

上面代码将项目中所有视图以JPG图片形式导出到桌面Views文件夹中,如下图所示:

内容或有偏颇之处,还请指正,不胜感激!

0

评论0

请先
高清无水印 通桥(2023)2322A-Ⅰ-a 时速350公里高速铁路 预制无砟轨道后张法预应力混凝土简支箱梁(双线)(跨度23.5m,梁高3.0m) 铁路工程建设通用参考图.pdf
高清无水印 通桥(2023)2322A-Ⅰ-a 时速350公里高速铁路 预制无砟轨道后张法预应力混凝土简支箱梁(双线)(跨度23.5m,梁高3.0m) 铁路工程建设通用参考图.pdf
6分钟前 有人购买 去瞅瞅看
没有账号?注册  忘记密码?

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录网站