.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MdiActiveDocument not changing

6 REPLIES 6
Reply
Message 1 of 7
mohnston
763 Views, 6 Replies

MdiActiveDocument not changing

This subject has been discussed in other threads but none solve my problem.

I broke it down to the simplest form I could with this code:

 

#region Namespaces
using System;
using System.Xml;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
#endregion

namespace AutoCADCodeSample
{
    public class Commands
    {
        [CommandMethod("Test",CommandFlags.Session)]
        public static void Test()
        {
            string fileName = string.Empty;
            System.Windows.Forms.OpenFileDialog ofd = 
                new System.Windows.Forms.OpenFileDialog();
            ofd.Filter = "AutoCAD drawing files|*.dwg";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                fileName = ofd.FileName;
                MessageBox.Show("Before opening drawing active document is " + 
                    acadApp.DocumentManager.MdiActiveDocument.Name);
                // Open a file
                Document doc = acadApp.DocumentManager.Open(fileName);
                MessageBox.Show("After opening " + fileName + " active document is " + 
                    acadApp.DocumentManager.MdiActiveDocument.Name);
                // Set the opened document to be the active document
                acadApp.DocumentManager.MdiActiveDocument = doc;
                MessageBox.Show("After setting " + doc.Name + 
                    " to be the active document the actual active document is " +
                    acadApp.DocumentManager.MdiActiveDocument.Name);
            }
        }
    }
}

 

When I run this MdiActiveDocument is the same in all three messages.

How can I get it to change?

 

VS 2012 - Acad 2013 - 32 bit

 

Same code in 2011 works as expected.

CAD Programming Solutions
6 REPLIES 6
Message 2 of 7

Hi,

 

Your code works fine at my end in AutoCAD 2012 SP2. Do you have SP2 installed? http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=19500680&linkID=9240618

I also checked in AutoCAD 2014. Code works fine. MdiActiveDocument do changes the active document.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 7

Try to set acadApp.DocumentManager.DocumentActivationEnabled to true

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 7

Thank you for the replies.

Alexander, I got your suggestion. I opened my test project and before making any changes decided to run it. (just to be sure)

This time it worked properly. I changed nothing in the project.

I did apply a Windows update in the last few days.(KB2861208)

Any chance that had something to do with this behaviour?

Any other ideas as to why this happened? It stopped me from working on an important project.

CAD Programming Solutions
Message 5 of 7


@mohnston wrote:
This time it worked properly. I changed nothing in the project.

May be other application/event handler was disabled document activation. Do I understand correctly that now everything is fine and the code is running as it should?

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 7

You understand correctly. It works as it should now.
It doesn't make any sense. I didn't touch the code or the project in any way.
I have been working on other projects in the mean time.
CAD Programming Solutions
Message 7 of 7
jeff
in reply to: mohnston

Whar is FIBERWORLD set to or FIBERWORLDNEXT?

 

 

http://www.theswamp.org/index.php?topic=45176.msg506745#msg506745

 

If it set to 0 then it will not change until the command ends in the document it is started in.

You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost