Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选择元素时不会引发Idling和ExternalEvent_C#_Wpf_Revit Api - Fatal编程技术网

C# 选择元素时不会引发Idling和ExternalEvent

C# 选择元素时不会引发Idling和ExternalEvent,c#,wpf,revit-api,C#,Wpf,Revit Api,我正在使用WPF无模式对话框构建Revit加载项,并希望使用ExternalEvent检索用户选择的图元。我正在做的事情可行吗?我需要做什么改变才能让它工作 因为我没有有效的API文档上下文,所以当单击按钮以检索当前所选元素的唯一ID时,我会引发一个ExternalEvent 以下是相关的类(我尽量减少代码): 公共类应用程序:IExternalApplication{ 内部静态应用程序_App=null; 公共静态应用程序实例=>\u应用程序; 启动时的公共结果(uicontrolLED应用程

我正在使用WPF无模式对话框构建Revit加载项,并希望使用ExternalEvent检索用户选择的图元。我正在做的事情可行吗?我需要做什么改变才能让它工作

因为我没有有效的API文档上下文,所以当单击按钮以检索当前所选元素的唯一ID时,我会引发一个ExternalEvent

以下是相关的类(我尽量减少代码):

公共类应用程序:IExternalApplication{
内部静态应用程序_App=null;
公共静态应用程序实例=>\u应用程序;
启动时的公共结果(uicontrolLED应用程序){
_app=这个;
返回结果。成功;
}
public void ShowWin(UIU应用程序ui\U应用程序){
var eventHandler=new CustomEventHandler();
var externalEvent=externalEvent.Create(eventHandler);
var window=newwpfwindow(eventHandler,externalEvent);
Process proc=Process.GetCurrentProcess();
WindowInteropHelper helper=新的WindowInteropHelper(窗口){
所有者=proc.MainWindowHandle
};
window.Show();
}
}
公共类加载项:IExternalCommand{
公共结果执行(ExternalCommandData commandData、ref字符串消息、ElementSet元素){
App.Instance.ShowWin(commandData.Application);
返回结果。成功;
}
}
公共类CustomEventHandler:IExternalEventHandler{
公共事件行动CustomEventHandlerDone;
公共作废执行(UIApplication ui\U app){
UIDocument ui\u doc=ui\u app.ActiveUIDocument;
如果(ui_doc==null){
回来
}
单据单据=用户界面\单据.单据;
列表元素_id=null;
var ui_view=ui_doc.GetOpenUIViews().Where(x=>x.ViewId==doc.ActiveView.Id).FirstOrDefault();
如果(doc.ActiveView是View3D-View3D&&ui\u-view!=null){
使用(交易发送=新交易(单据)){
tx.Start();
element_id=ui_doc.Selection.GetElementIds().Select(x=>doc.GetElement(x)?.UniqueId)。其中(x=>x!=null)。ToList();
tx.Commit();
}
}
this.CustomEventHandlerDone?.Invoke(元素ID);
}
}
公共部分类WPFWindow{
私有CustomEventHandler\u eventHandler;
私有外部事件_ExternalEvent;
公共WPFWindow(CustomEventHandler eventHandler,ExternalEvent ExternalEvent){
这。_eventHandler=eventHandler;
this.\u eventHandler.CustomEventHandlerDone+=this.WPFWindow\u CustomEventDone;
这个.\u externalEvent=externalEvent;
}
私有无效按钮\u单击(对象发送者,路由目标e){
此._externalEvent.Raise();
}
私有void WPFWindow\u CustomEventDone(列表元素\u id){
//选择图元时,永远不会达到此点
}
}
选择元素时,ExternalEvent标记为挂起,但仅在用户清除选择时执行

UIControlledApplication.Idling
也会发生同样的情况


我希望即使在选择了元素时也能执行它,或者使用一种替代方法来执行,并且不涉及PickObject。

我遇到了同样的问题

我能够确定,如果选择了相同族的图元,则会出现问题。此外,有一个特定的阈值,在10到20或更多的范围内,这一点得到了体现


在调用
ExternalEvent.Raise()
之前,我可以通过取消对元素
UIDocument.selection.SetElementIds(new List())
的选择来解决这个问题。然后在最后返回所选内容(如有必要)。

您真的是说,当Revit中当前选定并高亮显示的图元集为非空时,将永远不会触发“空闲”事件吗?我必须纠正这一点。它不是永远不会被解雇的。但是,在某些配置中,事件“持续不触发”。这似乎与选择哪些元素有关。如果我以“rac_basic_sample_project.rvt”文件为例,当我的WPF窗口在屏幕上时,在选择屋顶(ID 243274)时不会触发Idling事件。我有完全不同的用例,但我可以确认,在某个时刻调用Raise不会导致执行外部事件处理程序,不管它是否具有零意义,在调用raise之前清除选择后,问题似乎消失了