Create a Combined Parameter in a Schedule

Create a Combined Parameter in a Schedule

aciavardini
Participant Participant
661 Views
1 Reply
Message 1 of 2

Create a Combined Parameter in a Schedule

aciavardini
Participant
Participant

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;
        }

    }
}

 

 

 

0 Likes
662 Views
1 Reply
Reply (1)
Message 2 of 2

longt61
Advocate
Advocate

As far as I know, it is possible. You can add new combined parameter to schedule using its Definition, then add parameter IDs for that combined field. You may want to try the example code below:

ViewSchedule scheduleView = Get_your_schedule_view_here();
                    if (view != null)
                    {
                        ScheduleField field = scheduleView.Definition.AddField(ScheduleFieldType.CombinedParameter);
                        IList<TableCellCombinedParameterData> conbinedParams = field.GetCombinedParameters();

                        // create conbined field data
                        TableCellCombinedParameterData data = TableCellCombinedParameterData.Create();
                        data.ParamId = Get_your_desired_param_id_here();

                        conbinedParams.Add(data);
                    }

Hope this helps.

0 Likes