该文是学习了https://blog.csdn.net/The_Eyes/article/details/78105342博主的博文,对ImageExportOptions类及ImageView类学习后,做的测试,记录下来
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
using (Transaction trans = new Transaction(doc))
{
trans.Start("Export ImageView");
ImageExportOptions options = new ImageExportOptions();
options.ExportRange = ExportRange.CurrentView;
options.FitDirection = FitDirectionType.Horizontal;
options.ImageResolution = ImageResolution.DPI_72;
options.PixelSize = 255;
options.HLRandWFViewsFileType = ImageFileType.PNG;
options.ZoomType = ZoomFitType.Zoom;
options.Zoom = 10;
options.FilePath = @"F:\test.png";
doc.ExportImage(options);
trans.Commit();
}
TaskDialog.Show("Information","保存完毕");
return Result.Succeeded;
}
本来想通过此种方法,保存族文档中的视图,但是此方法好像不能保存族文件视图
二、导出多个视图:
private void ExportSetOfViews(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> views = collector.OfClass(typeof(View)).OfCategory(BuiltInCategory.OST_Views).ToElements();
IList<ElementId> viewExport = new List<ElementId>();
foreach (Element ele in views)
{
View view = ele as View;
if (view == null || view.IsTemplate)
continue;
viewExport.Add(view.Id);
}
using (Transaction trans = new Transaction(doc))
{
trans.Start("Export set of views");
ImageExportOptions options = new ImageExportOptions
{
ZoomType = ZoomFitType.FitToPage,
PixelSize = 255,
FilePath = @"F:\Views\",
FitDirection = FitDirectionType.Horizontal,
HLRandWFViewsFileType = ImageFileType.PNG,
ImageResolution = ImageResolution.DPI_72,
ExportRange = ExportRange.SetOfViews
};
options.SetViewsAndSheets(viewExport);
doc.ExportImage(options);
trans.Commit();
}
}