[英]python for revit - collect views in active view
I'm trying to use a FilteredElementCollector inside my pyRevit script to collect all views (sections, elevations, plan callouts etc.) in the active view. 我正在尝试在pyRevit脚本中使用FilteredElementCollector来收集活动视图中的所有视图(截面,立面,平面标注等)。
from pyrevit.framework import clr
from pyrevit import revit, DB
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from pyrevit import forms
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView
AllStuff = FilteredElementCollector(doc,doc.ActiveView.Id).WhereElementIsNotElementType().ToElements()
AllViews = []
try:
for x in AllStuff:
if "View" in x.Category.Name:
AllViews.append(x)
This will return some, but not all of the views. 这将返回一些视图,但不是全部视图。 For example, some sections are included but others are not and I can't tell why.
例如,包括了一些部分,但没有包括其他部分,我不知道为什么。
If I add ".OfCategory(BuiltInCategory.OST_Views)" I get nothing at all. 如果我添加“ .OfCategory(BuiltInCategory.OST_Views)”,我什么也收不到。 Do I need to break it down into several more specific categories?
我是否需要将其细分为几个更具体的类别? Thanks for any help.
谢谢你的帮助。
There is no view in FilteredElementCollector(doc, doc.ActiveView.Id), you can see it by doing : FilteredElementCollector(doc,doc.ActiveView.Id)中没有任何视图,您可以通过执行以下操作查看它:
for el in FilteredElementCollector(doc, doc.ActiveView.Id):
print(el)
There is an Element which is not of category OST_Views and is not a view even if it has the same name as your view. 有一个不属于OST_Views类别的元素,即使它与您的视图具有相同的名称,也不是一个视图。 To see this you can use RevitLookUp .
要查看此内容,可以使用RevitLookUp 。
I found a way to retrieve the actual view (I don't know any other way at the moment) by looking at VIEW_FIXED_SKETCH_PLANE BuiltInParameter which refer to the SketchPlane whiche reference the actual view as Element.OwnerViewId. 通过查看VIEW_FIXED_SKETCH_PLANE BuiltInParameter,我找到了一种检索实际视图的方法(目前我不知道其他任何方法),该参考指向SketchPlane,后者将实际视图作为Element.OwnerViewId引用。 Then you can make sure that the element is of class View :
然后,您可以确保该元素属于View类:
for el in FilteredElementCollector(doc,doc.ActiveView.Id):
sketch_parameter = el.get_Parameter(BuiltInParameter.VIEW_FIXED_SKETCH_PLANE)
# If parameter do not exist skip the element
if not sketch_parameter:
continue
view_id = doc.GetElement(sketch_parameter.AsElementId()).OwnerViewId
view = doc.GetElement(view_id)
if isinstance(view, View):
print(view)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.