2017-05-16 10 views
1

나는 FamilyInstance pFamAutodesk.Revit.DB.View pView입니다. pFampView에 표시되는지 알고 싶습니다. 나는 요소가 케이스하지 않은, 숨겨진하도록되어있는 경우결정은 FamilyInstance가보기에 표시됩니다.

if (pFam.IsHidden(pView) 
    continue; 

불행하게도,이는 나에게 말한다 사용하여 시도했습니다. 그러나이 요소는 모든 View에서 볼 수 없으며 그 상황에서 나는 어떤 일이 일어나기를 원합니다. FamilyInstance에 대해 Visible 또는 IsVisible 속성이 없습니다. 이러한 상황을 처리하는 방법을 아는 사람이 있습니까?

감사합니다!

답변

1

뷰에서 요소가 표시되는지 여부를 가장 확실하게 알 수있는 방법은 해당 뷰에 특정한 FilteredElementCollector를 사용하는 것입니다. 요소의 가시성을 제어하는 ​​여러 가지 방법이 있으므로이 방법을 다른 방식으로 결정하려고 시도하는 것은 비현실적입니다.

다음은이 작업을 수행하는 데 사용하는 유틸리티 기능입니다. 이것은 가족 인스턴스뿐만 아니라 모든 요소에서 작동합니다.

public static bool IsElementVisibleInView([NotNull] this View view, [NotNull] Element el) 
    { 
     if (view == null) 
     { 
      throw new ArgumentNullException(nameof(view)); 
     } 

     if (el == null) 
     { 
      throw new ArgumentNullException(nameof(el)); 
     } 

     // Obtain the element's document 
     Document doc = el.Document; 

     ElementId elId = el.Id; 

     // Create a FilterRule that searches for an element matching the given Id 
     FilterRule idRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.ID_PARAM), elId); 
     var idFilter = new ElementParameterFilter(idRule); 

     // Use an ElementCategoryFilter to speed up the search, as ElementParameterFilter is a slow filter 
     Category cat = el.Category; 
     var catFilter = new ElementCategoryFilter(cat.Id); 

     // Use the constructor of FilteredElementCollector that accepts a view id as a parameter to only search that view 
     // Also use the WhereElementIsNotElementType filter to eliminate element types 
     FilteredElementCollector collector = 
      new FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType().WherePasses(catFilter).WherePasses(idFilter); 

     // If the collector contains any items, then we know that the element is visible in the given view 
     return collector.Any(); 
    } 

범주 필터는 느린 매개 변수 필터를 사용하여 원하는 요소를 찾기 전에 원하는 범주가 아닌 요소를 제거하는 데 사용됩니다. 필터를 영리하게 사용하여 속도를 높일 수도 있지만 실제로는 충분히 빠릅니다.

ReSharper가없는 경우 표시되는 [NotNull] 주석을 삭제하십시오.

+0

고맙습니다. 콜린! [Building Coder 샘플] (https://github.com/jeremytammik/the_building_coder_samples) [CmdViewsShowingElements] (https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdViewsShowingElements.cs)에 추가했습니다.), [요소를 보여주는 뷰 결정] (http://thebuildingcoder.typepad.com/blog/2016/12/determining-views-showing-an-element.html)에 설명되어 있습니다. –

+0

또한이 토론과 Building Coder의 이전 관련 문제에 대한 몇 가지 지침을 요약했습니다. [View에서 볼 수있는 요소 검색] (http://thebuildingcoder.typepad.com/blog/2017/05/retrieving-elements-visible-in- view.html). 다시 Thx! –