我需要检测Uiview是标准打开的视图还是片材上的激活视口。查询uiview的视图Id返回激活的视口视图的Id。我没有找到直接的方法来检测uiview实际上是一个带有激活视口的工作表。
我已经在视图激活事件中跟踪打开的视图以用于其他目的。所以我考虑使用uiview哈希码存储视图ID,以便稍后在成为激活视图之前检查它确实是一个工作表视图。不幸的是,我认为与标准使用相反,uiview哈希码并不稳定。来自uiview对象的多个哈希码请求返回不同的值。
有没有人有办法检测到这种情况?我还需要能够使用uiview上的方法。所以任何帮助找到我想与uiview对象相关的实际子窗口。视图激活时,视图仍然在标题中显示“Sheet:...”。
答案 0 :(得分:0)
您可以使用ViewSheet GetAllViewports方法确定给定工作表上的所有视口。使用它,您可以组合双向字典查找系统将任何工作表映射到它承载的所有视口,反之亦然。这应该有助于解决您的任务。以下是一些示例用法:
答案 1 :(得分:0)
TaskDialog mainDialog = new TaskDialog("Hello, viewport check!");
mainDialog.MainInstruction = "Hello, viewport check!";
mainDialog.MainContent =
"Sadly Revit API doesn't automatically know if the user is in an active viewport. "
+ "Please click 'Yes' if your are, or 'No' if your not.";
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
"Yes, I am in an active viewport on a sheet.");
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
"No, I am just in an ordinary view.");
mainDialog.CommonButtons = TaskDialogCommonButtons.Close;
mainDialog.DefaultButton = TaskDialogResult.Close;
TaskDialogResult tResult = mainDialog.Show();
bool YesOrNo = true;
if (TaskDialogResult.CommandLink1 == tResult)
{
YesOrNo = true;
}
else if (TaskDialogResult.CommandLink2 == tResult)
{
YesOrNo = false;
}
else{
return;
}
答案 2 :(得分:0)
我迟到了 - 但另一种感知用户是否在视口中的方法是调查Process.MainWindow
标题。像这样(在RevitPythonShell中):
import threading, clr
from System.Diagnostics import Process
# need winform libraries for feedback form only
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form, Label
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
ui = __revit__.ActiveUIDocument
def lookAtWindow(activeView):
# Looking for one of three conditions:
# 1. User is on a sheet (ActiveView will be DrawingSheet)
# 2. User is in an active ViewPort on a sheet (ActiveView will NOT be be DrawingSheet, but MainWindowTitle will contain " - [Sheet: " string)
# 3. User is on a View (neither of the previous two conditions)
result = False
if str(activeView.ViewType) == 'DrawingSheet':
result = 'Youre on a sheet'
else:
processes = list(Process.GetProcesses())
for process in processes:
window = process.MainWindowTitle
if window and 'Autodesk Revit '+app.VersionName[-4:] in window and ' - [Sheet: ' in window and ' - '+doc.Title+']' in window:
result = 'I reckon youre in a Viewport'
if not result:
result = 'so you must be in a '+str(activeView.ViewType)
form = Form()
form.Width = 300
form.Height = 100
label = Label()
label.Width = 280
label.Height = 70
label.Text = result
label.Parent = form
form.ShowDialog()
# need to close RevitPythonShell console before checking MainWindowTitle, so run on timer
threading.Timer(1, lookAtWindow, [ui.ActiveView]).start()
__window__.Close()