Revit导出DWGExportSetting

在这里插入图片描述
今天发现Revit中并没有提供导出导出设置的按键,查阅API发现这块属于DWGExportSetting类型,如果导出就只能自己写接口进行导出。大部分导出这个位置的应该关注的是图层修改器,这里因为他的加载标准,图层修改器是无法读取,如果需要传递图层需要传递项目标准或自己写接口进行传递,这个也算是一个很鸡肋的开发了。
这里面Revit标准采用的编码并不是UTF-8而是ANSI需要注意一下,不然导入的话全部都是乱码。
整个步骤并不是很麻烦,下面是全部的代码:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using GetGeometry;
using System.Windows;
using System.Net.Mail;
using System.Windows.Controls;
using Autodesk.Revit.DB.Architecture;
using BIMTools;
using Microsoft.Win32;


namespace UnitTest
{
    [Transaction(TransactionMode.Manual)]
    public class Commad : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            var names = ExportDWGSettings.ListNames(doc);
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            var allElements = collector.WhereElementIsNotElementType().ToElements();
            var query = from e in allElements
                where e.GetType() == typeof(ExportDWGSettings)
                select e;
            
            var settings = query.FirstOrDefault(x => x.Name == "导出设置_中文") as ExportDWGSettings;
            var options = settings.GetDWGExportOptions();
            var table = options.GetExportLayerTable();
            var builder = new StringBuilder("# Revit Export Layers");
            builder.AppendLine("# Maps Categories and Subcategories to layer names and color numbers");
            builder.AppendLine("# Category <tab> Subcategory <tab> Layer name <tab> Color number <tab>");
            builder.AppendLine("# Cut layer name <tab> Cut color number");
            builder.AppendLine("# Do not remove the colon (:) after certain category names.");
            builder.AppendLine("# -----------------------------------------------------");
            foreach (var pair in table)
            {
                var key = pair.Key;
                var categoryName = key.CategoryName;
                if (!categoryName.Contains("dwg"))
                {
                    var subCategoryName = key.SubCategoryName;
                    var value = pair.Value;
                    var layerName = value.LayerName;
                    var layerColor = value.ColorNumber;
                    var cutLayerName = value.CutLayerName;
                    var cutLayerColor = value.CutColorNumber;
                    if (layerColor==-1)
                    {
                        // builder.AppendLine(categoryName + "    " + subCategoryName );
                    }
                    else if (cutLayerColor == -1 || cutLayerName == "-1")
                    {
                        builder.AppendLine(categoryName + "\t" + subCategoryName + "\t" + layerName + "\t" +
                                           layerColor);
                    }
                    else
                    {
                        builder.AppendLine(categoryName + "\t" + subCategoryName + "\t" + layerName + "\t" + layerColor + "\t" +
                                           cutLayerName + "\t" + cutLayerColor);
                    }
                }
                else
                {
                    continue;
                }
                
            }
            
            SaveFileDialog dialog = new SaveFileDialog()
            {
                FileName = settings.Name,
                DefaultExt = ".txt"
            };
            var dialogResult = dialog.ShowDialog();
            if (dialogResult == true)
            {
                var path = dialog.FileName;
                using (StreamWriter writer = new StreamWriter(path,true,Encoding.Default))
                {
                    writer.Write(builder);
                }
            }

            return Result.Succeeded;
        }
    }
}

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值