Created
June 25, 2024 06:45
-
-
Save sgrodnik/fca174a4f0b9fe657a12a7aa4e2515dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Autodesk.Revit.UI; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.UI.Selection; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows; | |
namespace SnrMacro | |
{ | |
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] | |
[Autodesk.Revit.DB.Macros.AddInId("36784927-9A88-4815-9383-0A365BC138A6")] | |
public partial class ThisApplication | |
{ | |
private void Module_Startup(object sender, EventArgs e) | |
{ | |
} | |
private void Module_Shutdown(object sender, EventArgs e) | |
{ | |
} | |
#region Revit Macros generated code | |
private void InternalStartup() | |
{ | |
this.Startup += new System.EventHandler(Module_Startup); | |
this.Shutdown += new System.EventHandler(Module_Shutdown); | |
} | |
#endregion | |
public void RestoreColumnTitlesMacro() | |
{ | |
var sel = ActiveUIDocument.Selection.GetElementIds() | |
.Select(id => ActiveUIDocument.Document.GetElement(id)) | |
.Where(el => el is ScheduleSheetInstance || el is ViewSchedule) | |
.Select(el => el is ViewSchedule | |
? el as ViewSchedule | |
: ActiveUIDocument.Document.GetElement((el as ScheduleSheetInstance).ScheduleId) as ViewSchedule ) | |
.ToList<ViewSchedule>(); | |
if (!sel.Any()) | |
{ | |
var viewSchedule = ActiveUIDocument.Document.ActiveView as ViewSchedule; | |
if (viewSchedule == null) | |
{ | |
TaskDialog.Show("Error", "No schedules selected.\nPlease select some in the project browser, on any sheet, or open one directly"); | |
return; | |
} | |
sel.Add(viewSchedule); | |
} | |
var report = new List<string>(); | |
var t = new Autodesk.Revit.DB.Transaction(ActiveUIDocument.Document, "Macro Restore Column Titles"); | |
t.Start(); | |
foreach (var viewSchedule in sel) | |
{ | |
try | |
{ | |
RestoreColumnTitles(viewSchedule); | |
report.Add("OK : " + viewSchedule.Name); | |
} | |
catch (Exception e) | |
{ | |
report.Add("Fail : " + viewSchedule.Name + " : " + e.Message); | |
} | |
} | |
t.Commit(); | |
TaskDialog.Show("Report", string.Join("\n", report.Distinct())); | |
} | |
void RestoreColumnTitles(ViewSchedule viewSchedule) | |
{ | |
for (var i = 0; i < viewSchedule.Definition.GetFieldCount(); i++) | |
{ | |
var field = viewSchedule.Definition.GetField(i); | |
if (field.IsHidden) continue; | |
field.ColumnHeading = field.GetName(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Propósito
Este macro está diseñado para restaurar los encabezados de las columnas en los tablas seleccionadas dentro de Autodesk Revit. Los encabezados renombrados por el usuario serán reemplazados con los nombres de los parámetros.
Cómo usar el código:
SnrMacro
.Purpose
This macro is designed to restore column headings in selected schedules within Autodesk Revit. User-renamed headers will be replaced with parameter names.
How to use the code:
SnrMacro
.