Revit API Schedule improvements for utilizing new categories.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Post 2021 Revit there has been an increasing number of categories. At the current time there is a need for some firms to convert schedules from Mechanical Category to Plumbing Equipment or Kitchen Equipment, etc.... This causes there to be a lot of manual rework due to API limitations. I might be missing something in the API but have had limited luck.
Its hard to ask other companies we are linking in to adjust these family categories to help use simplify view templates or other model federation needs when doing so can cause them to need to manual rework several schedules. The response can be "we don't have time for that" or "It doesn't matter"
It would be nice to be able to code something to remove the barrier to use of the new categories.
API commands that would help are as follows.
- Duplicate a Schedule view and all formatting rules while selecting a new category.
- Create Calculated Value Field via API
Setting the Stage:
We have dozens of schedules that have been built for say water heaters as mechanical equipment category. If we reload them as Plumbing Equipment, they will not talk to the schedules we have.
1) Best case scenario a command is added to convert the schedule by just swapping the mapped category of the schedule.
2) With the api I have been able to run the code below to create the schedule where there is only Parameters that are Shared or Built In along with using the InsertCombinedParameterField() method. and even some formating. But there is no way to have a Calculated Value field added. These columns are used for several things.
- Replacing Yes/No Values with symbols like ■ or ✓ via =if(Parameter , "✓", "✗")
- Replacing missing units. MBH is still not a HVAC load-based unit even in 24 with it added to the Electrical POWER unit type. Firms I have worked with take the Btu load and use formulas to convert the btu load value to say MBH. Otherwise, users use TEXT or btu values that are say 24 in place of 24000 so that they can put MBH in the header grouping and just leave the value at an unrealistic 24 btu stored value. (best fixed by adding the unit type)
- Calculating custom takeoffs/summations and . EX: volume of fluid in modeled pipe.
- Calculating User Check Values: EX putting a display value or warning in a column to allow formatting to help flag and draw focus with a custom value to something that needs adjusted in a schedule. yes, formatting rules can flag a cell red for review but its sometimes nice to be able to have a column that displays some value to help with the limited formatting logic rules.
public void ConvertScheduleCategory(UIApplication uiApp, Category newBuiltInCategory)
{
// Get the active document
Autodesk.Revit.DB.Document doc = uiApp.ActiveUIDocument.Document;
ViewSchedule soruceSchedule = uiApp.ActiveUIDocument.ActiveView as ViewSchedule;
if (soruceSchedule.ViewType != ViewType.Schedule) { return; }
// Find the category for the new schedule
FilteredElementCollector categoryCollector = new FilteredElementCollector(doc);
// Create a new schedule
ViewSchedule newSchedule = ViewSchedule.CreateSchedule(doc, newBuiltInCategory.Id);
var nDef = newSchedule.Definition;
var oldDef = soruceSchedule.Definition;
// Copy parameters from the source schedule to the new schedule
oldDef.GetFieldOrder();
Debug.Write(oldDef.GetFieldCount());
for (int i = 0; i < oldDef.GetFieldCount(); i++)
{
ScheduleField newFeild = null;
var feild = oldDef.GetField(i);
if (feild.IsCalculatedField)
{
var aaa = feild.PercentageBy;
if (aaa != null) { }
Debug.WriteLine(feild.GetName() + " - index:" + feild.FieldIndex.ToString() + " - Type:" + feild.FieldType.ToString());
}
else if (feild.FieldType == ScheduleFieldType.CombinedParameter)
{
IList<TableCellCombinedParameterData> conbinedParams = feild.GetCombinedParameters();
newFeild = nDef.InsertCombinedParameterField(conbinedParams, feild.GetName(), i);
Debug.WriteLine(feild.GetName() + " - index:" + feild.FieldIndex.ToString() + " - Type:" + feild.FieldType.ToString());
}
else { newFeild = nDef.InsertField(feild.FieldType, feild.ParameterId, i); }
var t = feild.GetFormatOptions();
newFeild.SetFormatOptions(feild.GetFormatOptions());
newFeild.SetStyle(feild.GetStyle());
newFeild.ColumnHeading = feild.ColumnHeading.ToUpper();
newFeild.GridColumnWidth = feild.GridColumnWidth;
newFeild.HeadingOrientation = feild.HeadingOrientation;
newFeild.HorizontalAlignment = feild.HorizontalAlignment;
newFeild.IsHidden = feild.IsHidden;
newFeild.MultipleValuesCustomText = feild.MultipleValuesCustomText;
newFeild.MultipleValuesDisplayType = feild.MultipleValuesDisplayType;
if (newFeild.IsCalculatedField)
{
newFeild.PercentageBy = feild.PercentageBy;
newFeild.PercentageOf = feild.PercentageOf;
}
newFeild.SheetColumnWidth = feild.SheetColumnWidth;
}
var a = nDef.GetFieldOrder();
nDef.SetFieldOrder(a);
nDef.IsItemized = oldDef.IsItemized;
if (oldDef.ShowGrandTotalTitle == true && oldDef.ShowGrandTotal == true)
{
nDef.ShowGrandTotalTitle = true;
nDef.ShowGrandTotal = true;
if (oldDef.ShowGrandTotalTitle == true)
{
nDef.GrandTotalTitle = oldDef.GrandTotalTitle;
}
else if(oldDef.ShowGrandTotal == true )
{
nDef.ShowGrandTotal = oldDef.ShowGrandTotal;
}
}
else if (nDef.ShowGrandTotalCount == true) { nDef.ShowGrandTotalCount = oldDef.ShowGrandTotalCount; }
nDef.IncludeLinkedFiles = oldDef.IncludeLinkedFiles;
nDef.IsFilteredBySheet = oldDef.IsFilteredBySheet;
nDef.ShowGridLines = oldDef.ShowGridLines;
nDef.ShowHeaders = oldDef.ShowHeaders;
nDef.ShowTitle = oldDef.ShowTitle;
newSchedule.Name = "New - " + soruceSchedule.Name;
TaskDialog.Show("Success", $"Schedule 'New - {newSchedule.Name}' created successfully.");
}
}