Community
I've duplicated a schedule with come code, but now i would like to change a filter in the schedule that filters by a shared parameter. IE shared parameter "Unit #" equals "//user input"
Ive search up and down the REVITSDK schedule creation sample. But, i cant figure it out from there.
Thanks!
public void UnitCopy() { Document doc = this.ActiveUIDocument.Document; // Filter views that match the required criteria FilteredElementCollector collector = new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)); // Get the specific view(s) IEnumerable<ViewSchedule> views = from Autodesk.Revit.DB.ViewSchedule f in collector where (f.ViewType == ViewType.Schedule && f.ViewName.Equals("Unit Default")) select f; using (Transaction trans = new Transaction(doc, "ViewDuplicate")) { trans.Start(); foreach (ViewSchedule vw in views) { // Duplicate the existing ViewPlan view ViewSchedule newView = doc.GetElement(vw.Duplicate(ViewDuplicateOption.Duplicate)) as ViewSchedule; // Assign the desired name if (null != newView) newView.ViewName = "MyViewName";//to be user input later. // this is just my attempt. string sfield = "Unit #"; ScheduleField unit = newView.Definition.GetField(fieldId); if (unit.ParameterId == new ElementId(BuiltInParameter.SCHEDULE_FIELDS_PARAM)) { ScheduleFilter filter = new ScheduleFilter(unit.FieldId, ScheduleFilterType.Equal, sfield); newView.Definition.AddFilter(filter); }
public static void AddFilterToSchedule(Document doc, ViewSchedule schedule) { string field = "Wood - Stud Layer"; string filterby = "MATERIAL_NAME"; string filterType = "Equal"; BuiltInParameter filterByParameter = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), filterby); ScheduleFilterType scheduleFilterType = (ScheduleFilterType)Enum.Parse(typeof(ScheduleFilterType), filterType); using (Transaction transaction = new Transaction(doc, "Filter Schedule")) { transaction.Start(); if (schedule.Name == "wall-material-takeoff") { ScheduleDefinition definition = schedule.Definition; ScheduleField scheduleField = FindField(viewSchedule, filterByParameter); // If field not present, add it if (scheduleField == null) { scheduleField = definition.AddField(ScheduleFieldType.Instance, new ElementId(filterByParameter)); } //scheduleField.IsHidden = false; ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, scheduleFilterType, field); definition.AddFilter(filter); } transaction.Commit(); } }
Can't find what you're looking for? Ask the community or share your knowledge.