[英]Find a view filter Revit Api
I am trying to use a filter to show/hide a certain element on the view. 我正在尝试使用过滤器来显示/隐藏视图上的某个元素。 The family is from catogary GenericModel.
该家族来自分类法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."
我使用的代码段与在Autodesk网站上的帮助中的代码段一样,可以在其原始状态下正常运行(类别是墙),但是当我将其更改为GenericModel时,出现以下错误:“给定规则之一指的是不适用于此过滤器的类别。” I suspect that something wrong with the typeOf(FamilyInstance).
我怀疑typeOf(FamilyInstance)出了点问题。 The original code on Autodesk site is:
Autodesk网站上的原始代码为:
http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-B6FB80F2-7A17-4242-9E95-D6056090E85B 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();
I think the problem is that your code which is performing the FilteredElementCollector is not specific enough. 我认为问题在于执行FilteredElementCollector的代码不够具体。 In the ADN sample, they're filtering on a type of "Wall" - but you're filtering on a type of FamilyInstance.
在ADN示例中,它们正在对“ Wall”类型进行过滤-但您正在对FamilyInstance类型进行过滤。 You're correct on the type, but FamilyInstance covers lots of categories.
您在类型上是正确的,但是FamilyInstance涵盖了很多类别。 The FirstElement() is giving the first FamilyInstance in the collector (which is likely not a generic model).
FirstElement()在收集器中提供了第一个FamilyInstance(可能不是通用模型)。
Try this line: Parameter parameter = parameterCollector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_GenericModel).FirstElement().get_Parameter("elementNo"); 尝试以下行:参数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. 这样,您应该获得的第一个元素既是家族实例又是GenericModel。
Good Luck, Matt 祝你好运,马特
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.