2

I am trying to run the code that on the Autodesk help

http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-B6FB80F2-7A17-4242-9E95-D6056090E85B but it seem not to work. The code "FirstElement ().get_Parameter("Comments");" don't work. No such function.

I got the following error:

Revit encoutered a System.MissingMethodException; Method not found:'AutoDesk.Revit.DB.Parameter Autodesk.Revit.DB.Element.get_Parameter(System.String)

What is the wrong with this code?

  private void CreateViewFilter(Autodesk.Revit.DB.Document doc, View view)
    {
    List<ElementId> categories = new List<ElementId>();
    categories.Add(new ElementId(BuiltInCategory.OST_Walls));
    ParameterFilterElement parameterFilterElement = 
    ParameterFilterElement.Create(doc, "Comments = foo", categories);

    FilteredElementCollector parameterCollector = new FilteredElementCollector
    (doc);
    Parameter parameter = parameterCollector.OfClass(typeof(Wall)).FirstElement
    ().get_Parameter("Comments");

    List<FilterRule> filterRules = new List<FilterRule>();
    filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule  
    (parameter.Id, "foo", true));
      parameterFilterElement.SetRules(filterRules);


     OverrideGraphicSettings filterSettings = new OverrideGraphicSettings();
    // outline walls in red            
    filterSettings.SetProjectionLineColor(new Color(255, 0, 0));
    view.SetFilterOverrides(parameterFilterElement.Id, filterSettings);
    }
PRMoureu
  • 12,817
  • 6
  • 38
  • 48
uakam
  • 27
  • 6
  • Can you provide more information such as, error message, etc? – DiskJunky Oct 03 '17 at 16:27
  • 1
    I got the following error:"Revit encoutered a System.MissingMethodException; Method not found:'AutoDesk.Revit.DB.Parameter Autodesk.Revit.DB.Element.get_Parameter(System.String)" – uakam Oct 03 '17 at 16:45
  • Thanks it works with lookupparameter but I get another error when I repeate the command more than once. The error says: Revit encounterd a argumentException. The given value for name is already in use as a filter element name parmeter name: name at ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Comments= foo", categories); – uakam Oct 06 '17 at 18:37

1 Answers1

0

I guess you are using a version of Revit different from the help version (2014) ?

I think get_Parameter is deprecated since a couple of versions.

You can try with LookupParameter :

...FirstElement().LookupParameter("Comments");

or eventually GetParameters, but careful, this one returns a collections :

...FirstElement().GetParameters("Comments");

(The links refer to the last version but you can easily check for another one on the same site, and the 2 methods looks unchanged since Revit 2015.)

PRMoureu
  • 12,817
  • 6
  • 38
  • 48
  • Thanks it works with lookupparameter but I get another error when I repeate the command more than once. The error says: Revit encounterd a argumentException. The given value for name is already in use as a filter element name parmeter name: name at ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Comments= foo", categories); – uakam Oct 07 '17 at 10:30
  • Interesting, I'm not sure why this error happens, how do you repeat the code exactly ? This kind of error should happen when you're giving the same name for 2 filters (`name` is the second parameter `"Comments= foo"`). It could be better to write another question about that, with the code, the exception... this is what will help other people. (BTW you should accept some answers you got here, it helps the next visitors to spot the solutions and it makes authors happy ;-)) – PRMoureu Oct 07 '17 at 11:52
  • Thank you! I wonder what do you mean by accept answer? I couldn't find a button or alike to mark the "right" answer but I did mention that your answer worked. Is there any other way? – uakam Oct 07 '17 at 12:45
  • 1
    I found the answer. When I tried to run the program again there is a filter in the view with that name that is created byt the first run of mine. – uakam Oct 07 '17 at 13:09