BIM建筑网
更专业的BIM技术学习网站!


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

GPT-有问必答,有求必应
永久免费使用!写文案、做设计、找答案,回答你的所有问题。
试一试

在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文件夹中,如下图所示:
Revit二次开发--屏幕截图/图片导出

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

微信公众号:xuebim
关注建筑行业BIM发展、研究建筑新技术,汇集建筑前沿信息!
← 微信扫一扫,关注我们+
赞(0) 打赏
BIM建筑网 » Revit二次开发--屏幕截图/图片导出
100套内部BIM资料,限时领!
付费搞来的,大家都在学!
领取资料 AI解答

评论 抢沙发

评论前必须登录!

 

BIM建筑网,更专业的BIM技术学习网站!

关注建筑新动态,分享建筑新技术

联系我们关于BIM建筑网

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

扫码登录

微信「关注」,快捷登录
扫码关注后会自动登录
注册登录代表您已同意《用户许可协议》
账号登录 | 其他登录

|登录

找回密码

|账号登录注册