Message 1 of 2
Create a Combined Parameter in a Schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I am creating an add-in that automatically creates a schedule for rooms. I would like to add the room name and number together by combining the parameters. This is possible to do manually by using the "Combine Parameters" when adding new fields to the schedule. Is it possible to automate this step?
I included the code I have so far.
Thanks,
Anthony
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace BIM360Locations
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
BuiltInParameter[] BiParams = new BuiltInParameter[] { BuiltInParameter.ROOM_LEVEL_ID,
BuiltInParameter.ROOM_NAME, BuiltInParameter.ROOM_NUMBER };
public Result Execute(ExternalCommandData edata, ref string message, ElementSet elementSet)
{
UIDocument uidoc = edata.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Transaction t = new Transaction(doc, "Create Schedule");
t.Start();
ElementId roomCategoryId = new ElementId(BuiltInCategory.OST_Rooms);
ViewSchedule schedule = ViewSchedule.CreateSchedule(doc, roomCategoryId);
schedule.Name = "ROOM LOCATIONS";
ScheduleSortGroupField FamilyTypeSorting = null;
foreach (SchedulableField sf in schedule.Definition.GetSchedulableFields())
{
if (CheckField(sf))
{
ScheduleField scheduleField = schedule.Definition.AddField(sf);
// schedule's group sorting (by Room level)
if (sf.ParameterId == new ElementId(BuiltInParameter.ROOM_LEVEL_ID))
{
FamilyTypeSorting = new ScheduleSortGroupField(scheduleField.FieldId);
schedule.Definition.AddSortGroupField(FamilyTypeSorting);
}
}
}
schedule.Definition.SetSortGroupField(0, FamilyTypeSorting);
t.Commit();
uidoc.ActiveView = schedule;
return Result.Succeeded;
}
public bool CheckField(SchedulableField vs)
{
foreach (BuiltInParameter bip in BiParams)
{
if (new ElementId(bip) == vs.ParameterId)
return true;
}
return false;
}
}
}