12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*-------------------------------------------------------------------------
- * 功能描述: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
- {
- /// <summary>
- /// 将视图导出Dwg格式
- /// </summary>
- /// <param name="view">使用的view</param>
- /// <param name="exportFileName">导出的位置</param>
- /// <param name="visibleCategories">设置显示的category,如果传入null,则不对category进行限制</param>
- /// <returns></returns>
- public static bool ExportDwg(View view, string exportFileName, List<Category> visibleCategories)
- {
- List<Category> 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<ElementId>() { viewId }, dwgExportOptions1);
- }
- }
- }
|