Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

set Schedule Filter

2 REPLIES 2
Reply
Message 1 of 3
Ryan
2557 Views, 2 Replies

set Schedule Filter

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

 

 

 

2 REPLIES 2
Message 2 of 3
Aaron.Lu
in reply to: Ryan

Can you let us know what is the problem of your code? thanks.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 3 of 3
Anonymous
in reply to: Ryan

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.

Post to forums  

Rail Community


Autodesk Design & Make Report