C#在打开AutoCAD图形后将windows窗体更改为ontop
本文关键字:窗体 windows ontop AutoCAD 图形 | 更新日期: 2023-09-27 17:58:59
我为AutoCAD编写了一个C#插件,用户可以在其中输入一些信息,然后打开相应的图形。
实际的工作流程应该是:
- 我在AutoCAD中启动插件
- 用户可以在当前活动图形顶部的窗口窗体中输入一些信息
- 当用户点击输入按钮时,应打开一个新图形
- 用户输入某些信息的表单应该关闭(这很好)
- 应该打开一个新的窗口窗体来输入一些其他信息(与第一个窗口不同),但在新图纸中
问题是我可以正确地关闭第一个窗口并正确地打开新图形。像这样:
DocumentCollection documentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
if (File.Exists(absoultePathOfDrawing))
{
Document newDrawing = documentCollection.Open(absoultePathOfDrawing, false);
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = newDrawing; // this sets the new drawing as the active one ==> is on top
}
Dispose(); // closes the first form
DialogResult = DialogResult.OK; // tells my applciation that the first window was successfully closed
表单正确关闭,然后我尝试用打开新表单
if (result == DialogResult.OK)
{
MessageBox.Show("Test");
}
但现在新的画在上面,后面是旧的画。当我切换回旧图形时,将显示新的MessageBox,但实际上它应该显示在新图形中,因为我将活动文档设置为新图形。我做错了什么?
我找到了解决方案。
我不得不用以下选项加载我的插件:
[CommandMethod("PluginName", Autodesk.AutoCAD.Runtime.CommandFlags.Session)]
如果没有这个,我的插件只在一个文档中有效(我启动插件的那个文档)