Я работаю над рутиной Revit 2015, показанной ниже. Подпрограмма предназначена для выбора элемента и создания фильтра просмотра, который автоматически скроет все элементы в этой системе. Он работает только один раз в проекте из-за того, что фильтр просмотра может быть создан только один раз в проекте, а затем повторно использован для других представлений. Кто-нибудь знает, как я могу собрать все видоискатели в модели и сравнить имя с фильтром представления, который я бы хотел создать?Revit View Filter
public void HideSystems()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
Reference r = uidoc.Selection.PickObject(ObjectType.Element,new SystemElementFilter(),"Select an element of a system");
if (r == null)
{
return;
}
Element elem = doc.GetElement(r.ElementId);
var systemNameParam =elem.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM);
if (systemNameParam == null)
{
}
var view = doc.ActiveView;
var categoriesWithSystem =
GetCategoriesApplicableForParameter(doc, BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM);
var categoriesWithoutSystemNameParameter =
GetCategoriesApplicableForParameter(doc, BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM, true);
var systemName = systemNameParam.AsString();
// An element can be assigned to the several systems
// In this case System Name parameter has a comma separated
// list of the systems
// Create several rules
IList<FilterRule> rules = new List<FilterRule>();
var systems = systemName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var system in systems)
{
rules.Add(ParameterFilterRuleFactory.CreateContainsRule(new ElementId(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM),system.Trim(),true));
}
using (var t = new Transaction(doc, "System hide"))
{
t.Start();
string sysName=string.Concat("Remove ",systemName);
// Hide elements which are in the selected system
ParameterFilterElement filter2 = ParameterFilterElement.Create(doc,sysName,categoriesWithSystem,rules);
view.AddFilter(filter2.Id);
view.SetFilterVisibility(filter2.Id, false);
vi
t.Commit();
}
}
/// <summary>
/// Returns the list of the categories what can be used in filter
/// by the specific parameter
/// </summary>
/// <param name="doc">Document on which the filter is applying</param>
/// <param name="bip">BuiltInParameter</param>
/// <param name="inverse">If true, the list will be inverted. I.e. you will get
/// the list of the categories what cannot be used in filter
/// by the specific parameter </param>
/// <returns></returns>
ICollection<ElementId> GetCategoriesApplicableForParameter(Document doc,BuiltInParameter bip,bool inverse = false)
{
// All categories available for filter
var allCategories = ParameterFilterUtilities.GetAllFilterableCategories();
allCategories.Remove(new ElementId(BuiltInCategory.OST_DuctTerminal));
allCategories.Remove(new ElementId(BuiltInCategory.OST_PlumbingFixtures));
ICollection<ElementId> retResult = new List<ElementId>();
foreach (ElementId categoryId in allCategories)
{
// get the list of parameters, compatible with the category.
var applicableParameters =
ParameterFilterUtilities.GetFilterableParametersInCommon(doc, new[] {categoryId});
// if the parameter we are interested in the collection
// add it to the result
if (applicableParameters.Contains(new ElementId(bip)))
{
retResult.Add(categoryId);
}
}
// Invert if needed.
if (inverse)
retResult =
allCategories.Where(x => !retResult.Contains(x)).ToList();
return retResult;
}
}
/// <summary>
/// Allow to select only element what has the parameter
/// 'System Name' and has value.
/// </summary>
public class SystemElementFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
var systemNameParam =
elem.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM);
return systemNameParam != null && systemNameParam.HasValue;
}
public bool AllowReference(Reference reference, XYZ position)
{
throw new NotImplementedException();
}
}
}
`