I found today that Revit does not provide an export button for Export Settings. Checking API found that this piece belongs to DWGExportSetting type. If exporting, can only write interface to export by myself. Most exports of this position should concern layer modifier. Here because of its loading standard, layer modifier cannot be read. If need to transfer layers, need to transfer project standards or write interface to transfer by yourself. This can also be considered a very tasteless development.
Note that coding adopted by Revit standard here is not UTF-8 but ANSI. Pay attention, otherwise imports will be all garbled. The whole step is not very troublesome. Below is the full code:
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;
namespaceUnitTest { [Transaction(TransactionMode.Manual)] publicclassCommad : IExternalCommand { public Result Execute(ExternalCommandData commandData, refstring 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 == "Export Settings_Chinese") 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; varvalue = 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 ); } elseif (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); } }