0

I am trying to use a filter to show/hide a certain element on the view. The family is from catogary GenericModel. I use the same code snippet that on the help on the autodesk site it works fine in its original state (catogary is walls) but when I changed it to GenericModel I got the following error: "One of the given rules refers to a parameter that does not apply to this filter's categories." I suspect that something wrong with the typeOf(FamilyInstance). The original code on Autodesk site is:

http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-B6FB80F2-7A17-4242-9E95-D6056090E85B

and here is my code

Transaction trans = new Transaction(doc);
         trans.Start("Hide_or_Unhide");
        //
        List<ElementId> categories = new List<ElementId>();
        categories.Add(new ElementId(BuiltInCategory.OST_GenericModel));
        ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "elementNo = 102", categories);
        FilteredElementCollector parameterCollector = new FilteredElementCollector(doc);
        Parameter parameter = parameterCollector.OfClass(typeof(FamilyInstance)).FirstElement().get_Parameter("elementNo");
        List<FilterRule> filterRules = new List<FilterRule>();
        filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(parameter.Id, 102));   
        try
        {
            parameterFilterElement.SetRules(filterRules);
        }
        catch (Exception ex)
        {
            TaskDialog.Show("", ex.Message);
        }
        OverrideGraphicSettings filterSettings = new OverrideGraphicSettings();
        // outline walls in red            
        filterSettings.SetProjectionLineColor(new Autodesk.Revit.DB.Color(255, 0, 0));
        Autodesk.Revit.DB.View curView = doc.ActiveView;
        curView.SetFilterOverrides(parameterFilterElement.Id, filterSettings);
        trans.Commit();
user3968554
  • 1
  • 1
  • 4

1 Answers1

1

I think the problem is that your code which is performing the FilteredElementCollector is not specific enough. In the ADN sample, they're filtering on a type of "Wall" - but you're filtering on a type of FamilyInstance. You're correct on the type, but FamilyInstance covers lots of categories. The FirstElement() is giving the first FamilyInstance in the collector (which is likely not a generic model).

Try this line: Parameter parameter = parameterCollector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_GenericModel).FirstElement().get_Parameter("elementNo");

That way, you should get the first element that is both a family instance AND a GenericModel.

Good Luck, Matt

Matt
  • 1,043
  • 5
  • 8
  • Thank you very much. I tried your sugesstion(I only change the BuiltInParameter to BuiltInCatogary) and it worked fine with the Comments parameter but not with any other parameter. I got error "The value can't be empty". I notice that the Comment paramter is there on the Project but not seen when I edit the family properties niether instance or type. Any ideas about that? – user3968554 Feb 05 '15 at 10:41
  • The Comments parameter is a built in parameter for all instance/categories at the project level. How are you defining your elementNo parameter? – Matt Feb 05 '15 at 12:56
  • instance paramater identity Data integer. I tried with other parameters of all types but it is the same – user3968554 Feb 05 '15 at 13:07