The CommandMethod
attribute can have some flags.
Use the session
flag to make the method be independent of an open document and be managed by the autocad application main window.
AutoCAD crashes trying to open a Modal Dialog from .Net command
-
31-05-2022 - |
题
I'm developing an AutoCAD .Net plugin which contains a command that opens a modal window. The window should display a web page.
But it has a strange bug, here is a simple code to reproduce it:
[CommandMethod("TEST_BROWSER")]
public void TestBrowserCommand()
{
var window = new Window();
var browser = new WebBrowser();
window.Content = browser;
browser.Source = new Uri("http://google.com");
window.ShowDialog();
}
Or even simpler:
[CommandMethod("TEST_BROWSER")]
public void TestBrowserCommand()
{
Application.ShowModalWindow(new Uri("http://google.com"));
}
Here is the sequence of steps after which AutoCAD crashes:
- Call the command from the command line (TEST_BROWSER).
- Close the appeared window.
- Call the same command once again
- The error message appears: http://i.stack.imgur.com/sFWMX.png
It works fine if to open non-modal (modeless) windows, or not to use web browser, or to call the code without using the command.
But I need a modal window with a browser called from the command line.
Did anyone else encounter the same issue?
解决方案
其他提示
You can create WPF browser application and launch with the given url when required. or try passing the shell command using AutoCAD
you can open a website in a browser of your choice from CMD like this chrome.exe "zcodia.com.au"
I can't test at the moment but I think you need to change your CommandMethod
statement to: [CommandMethod("TEST_METHOD", CommandFlags.Modal)]