Author Topic: MdiActivedocument not changing  (Read 2719 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
MdiActivedocument not changing
« on: April 25, 2013, 06:59:19 PM »
This is the worst kind of problem. Where something has worked, should work and does work and then stops working. . . in certain circumstances.
I have an app that is all of a sudden giving me an "eNotApplicable" error when I try to select entities.
The error is because the system thinks that the drawing is not in the active editor.

When I step through this code on a 64 bit development machine the messagebox shows this:
Code: [Select]
            string mess = string.Empty;
            Autodesk.AutoCAD.ApplicationServices.Document odoc = acadApp.DocumentManager.Open(finFile, false);
            // acadApp.DocumentManager.MdiActiveDocument = odoc;
            mess = "1-" + odoc.Database.Filename + "\n";
            mess += "2-" + acadApp.DocumentManager.MdiActiveDocument.Name + "\n";
            mess += "3-" + HostApplicationServices.WorkingDatabase.Filename;
            MessageBox.Show(mess);

On a 32 bit system this happens:


Any ideas as to why this strange behaviour?
Is there a way to force MdiActiveDocument to match WorkingDatabase?

VS 2010
Windows 7 (32/64)
AutoCAD 2013 (32/64)
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Jeff H

  • Needs a day job
  • Posts: 6144
Re: MdiActivedocument not changing
« Reply #1 on: April 25, 2013, 07:12:01 PM »
Why do you comment out the line that assigns MidiActiveDocument to odoc?
I did not think Open internally assigned MidiActiveDocument to the Document it returned or did it differently on platforms

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: MdiActivedocument not changing
« Reply #2 on: April 25, 2013, 08:27:21 PM »
I meant to note that.
I tried it with and without that line. Same result.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: MdiActivedocument not changing
« Reply #3 on: April 25, 2013, 09:27:34 PM »
I recently had an issue of a similar type, what context are you doing this in?  I know this is of little help given that this has only been tested on a x64 system (I don't know anybody who still runs x86 lol) but it works great for me.
Code - C#: [Select]
  1.         [CommandMethod("CustomPaletteOpen", CommandFlags.Session)]
  2.         public void OpenNewDocument()
  3.         {
  4.             DocumentCollection docs = AutoCAD.ApplicationServices.Application.DocumentManager;
  5.             Editor ed = docs.MdiActiveDocument.Editor;
  6.             PromptResult pr = ed.GetString("");
  7.             if (pr.Status == PromptStatus.OK)
  8.             {
  9.                 bool existed = false;
  10.                 foreach (Document doc in docs)
  11.                 {
  12.                     if (doc.Name == pr.StringResult)
  13.                     {
  14.                         docs.MdiActiveDocument = doc;
  15.                         existed = true;
  16.                         break;
  17.                     }
  18.                 }
  19.                 if (!existed)
  20.                 {
  21.                     if (File.Exists(pr.StringResult))
  22.                         docs.Open(pr.StringResult, false);
  23.                     else
  24.                         ed.WriteMessage("\nFile does not exist!");
  25.                 }
  26.             }
  27.         }