How to create SchedulableField field?

How to create SchedulableField field?

nur91m
Advocate Advocate
1,848 Views
1 Reply
Message 1 of 2

How to create SchedulableField field?

nur91m
Advocate
Advocate

I want to create multi category schedule with Wall and Room fields. I wrote this -->

 

 ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.INVALID));

 

after this i need add some schedulable fields of Wall and Room categories? How can I do this? Please help me. Man Wink

 

 

thx

0 Likes
1,849 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Here is how I create schedules, just need to filter for the parameters you want to schedule and within which BuiltInCategory (OST.Walls, etc.)

 

            using (Transaction t = new Transaction(document, "Create Schedules"))
            {
                t.Start();

                List<ViewSchedule> schedules = new List<ViewSchedule>();

                //Create an empty view schedule of wall category.
                ViewSchedule schedule = ViewSchedule.CreateSchedule(document, new ElementId(BuiltInCategory.OST_Walls), ElementId.InvalidElementId);
                schedule.Name = "SCHEDULE NAME";
                schedules.Add(schedule);

                //Iterate all the schedulable field gotten from the walls view schedule.
                foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields())
                {
                    //Judge if the FieldType is ScheduleFieldType.Instance.
                    if (schedulableField.FieldType == ScheduleFieldType.Instance)
                    {
                        //Get ParameterId of SchedulableField.
                        ElementId parameterId = schedulableField.ParameterId;

                        //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class.
                        string fieldName = schedulableField.GetName(_doc);

                        if (fieldName == "TEST" || fieldName == "TEST2" || fieldName == "TEST3") //Lots of ORs
                        {
                            ScheduleField field = schedule.Definition.AddField(schedulableField);
                            field.HorizontalAlignment = ScheduleHorizontalAlignment.Left;

                            //Group and sort the view schedule by type
                            if (field.ParameterId == new ElementId(BuiltInParameter.ELEM_TYPE_PARAM))
                            {
                                ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
                                sortGroupField.ShowHeader = true;
                                schedule.Definition.AddSortGroupField(sortGroupField);
                            }
                        }
                    }
                }

                t.Commit();
                uiDocument.ActiveView = schedule;

 

 

 

0 Likes