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:

  1. Call the command from the command line (TEST_BROWSER).
  2. Close the appeared window.
  3. Call the same command once again
  4. 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?

有帮助吗?

解决方案

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.

其他提示

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)]

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top