Skip to content

Instantly share code, notes, and snippets.

@sgrodnik
Created June 25, 2024 06:45
Show Gist options
  • Save sgrodnik/fca174a4f0b9fe657a12a7aa4e2515dd to your computer and use it in GitHub Desktop.
Save sgrodnik/fca174a4f0b9fe657a12a7aa4e2515dd to your computer and use it in GitHub Desktop.
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();
}
}
}
}
@sgrodnik
Copy link
Author

sgrodnik commented Jun 25, 2024

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:

  1. Ve a la pestaña Manage, panel Macros, y abre Macro Manager.
  2. Presiona el botón Create Module.
  3. Pega el nombre del módulo SnrMacro.
  4. En el editor de SharpDevelop abierto, reemplaza todo el texto con el código proporcionado.
  5. Ve al menú Build y presiona Build Solution (F8).
  6. Cierra el editor de SharpDevelop y haz doble clic en el macro en el Macro Manager para ejecutarlo.

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:

  1. Go to the Manage tab, Macros panel, and open Macro Manager.
  2. Press the Create Module button.
  3. Paste the module name SnrMacro.
  4. In the opened SharpDevelop editor, replace all text with the provided code.
  5. Go to the Build menu and press Build Solution (F8).
  6. Close the SharpDevelop editor and double-click the macro in the Macro Manager to run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment