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.
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.
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
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.
@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
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.