/*-------------------------------------------------------------------------
* 功能描述:DwgExportUtils
* 作者:xulisong
* 创建时间: 2019/7/25 9:59:03
* 版本号:v1.0
* -------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
namespace LRH.Tool
{
public static class DwgExportUtils
{
///
/// 将视图导出Dwg格式
///
/// 使用的view
/// 导出的位置
/// 设置显示的category,如果传入null,则不对category进行限制
///
public static bool ExportDwg(View view, string exportFileName, List visibleCategories)
{
List useCategories = visibleCategories;
string folder = Path.GetDirectoryName(exportFileName);
string fileName = Path.GetFileName(exportFileName);
DWGExportOptions dwgExportOptions1 = new DWGExportOptions();
dwgExportOptions1.Colors = ExportColorMode.IndexColors;
dwgExportOptions1.LineScaling = LineScaling.PaperSpace;
dwgExportOptions1.TargetUnit = ExportUnit.Millimeter;
dwgExportOptions1.FileVersion = ACADVersion.R2013;
dwgExportOptions1.SharedCoords = false;
dwgExportOptions1.PropOverrides = PropOverrideMode.ByEntity;
dwgExportOptions1.LayerMapping = "AIA";
View useView = view;
ElementId viewId = view.Id;
var document = useView.Document;
if (useCategories != null)
{
var categories = useView.Document.Settings.Categories;
foreach (Category category in categories)
{
useView.SetCategoryHidden(category.Id, true);
}
foreach (Category useCategory in useCategories)
{
useView.SetCategoryHidden(useCategory.Id, false);
}
}
return document.Export(folder, fileName, new List() { viewId }, dwgExportOptions1);
}
}
}