1

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: https://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?

Owen Wengerd
  • 1,628
  • 1
  • 11
  • 11
reinwolf
  • 13
  • 3
  • If the problem occurs only at the second call, I'd suggest you try to clean everything about that browser window after done. Try to dispose it properly at the end of the command. – Daniel Möller Jun 18 '13 at 12:18
  • @Daniel I tried to call the WebBrowser.Dispose method on the Window.Close event, but it doesn't help. Maybe some uncleaned data is really the case, but I don't know how to clean everything properly. – reinwolf Jun 25 '13 at 13:02
  • Another thing you could try is to add flags to the `CommandMethod` attribute. There are lots of flags such as `session` (command works independent open documents, in autocad main window). There is probably a `modal` flag as well. I cannot tell what each flag does, but maybe some of them can be useful. – Daniel Möller Jun 25 '13 at 15:37
  • I'd try the `session` flag. – Daniel Möller Jun 25 '13 at 15:45
  • @Daniel Good, the `Session` flag works, though `Modal` doesn't. Post it as an answer and I'll accept it. – reinwolf Jun 25 '13 at 16:21

3 Answers3

2

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.

Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • I had the same problem, and this fixed it for me as well. (I had to add DocumentLock using statements to all my transactions, but I'll happily live with that to make it work!) – Matt Jun 28 '13 at 16:05
  • I just hate transactions. I keep using `Interop`. Hope Autodesk doesn't decide to make it obsolete. – Daniel Möller Jun 28 '13 at 16:54
0

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"

  • Shell commands are not what I need, because they are launched as a separate application whereas I need a modal window in AutoCAD. Non-modal windows work fine anyway, but modal windows don't. – reinwolf Jun 14 '13 at 08:12
0

I can't test at the moment but I think you need to change your CommandMethod statement to: [CommandMethod("TEST_METHOD", CommandFlags.Modal)]

JayP
  • 809
  • 7
  • 9