AutoCAD 2014. MdiActiveDocument return null.

AutoCAD 2014. MdiActiveDocument return null.

galaxyblazer
Enthusiast Enthusiast
760 Views
5 Replies
Message 1 of 6

AutoCAD 2014. MdiActiveDocument return null.

galaxyblazer
Enthusiast
Enthusiast

I try get Active AutoCAD document inside handler of custom event which run when data updated on server. Inside this handler I try call CommandMethod by command name.

public static void API_DataUpdate(ServerKey arg1, ServerData arg2)
        {
cmdName="TestCommand";
cmdName = cmdName.TrimEnd() + " ";
                 document = AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
document.SendStringToExecute(cmdName, true, false, true);

        }

But inside this handler MdiActiveDocument return null also DocumentCollection contains document in which I try run command, and also document is active inside AutoCAD. Why it's hapened ? Identical code with this handler perfectly works via AutoCAD 2015/2016.

0 Likes
761 Views
5 Replies
Replies (5)
Message 2 of 6

BrentBurgess1980
Collaborator
Collaborator

Hi GalaxyBlazer,

 

I am not sure which version it came in with (I know it is in 2015), but the Document.SendCommand has been replaced with Editor.Command and Editor.CommandAsync.

 

Have you considered posting this in the .NET forum? You may get some better responses than mine from the experts.

0 Likes
Message 3 of 6

FRFR1426
Collaborator
Collaborator

Your event handler is not running in the main thread. You need to use a synchronization mechanism to call your code in the main thread.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes
Message 4 of 6

galaxyblazer
Enthusiast
Enthusiast

But why it's hapaned in AutoCAD 2014 ?  What the different between AutoCAD 2014 and 2015/2016?

0 Likes
Message 5 of 6

FRFR1426
Collaborator
Collaborator

This is the nature of synchronization issues to be unpredictable. It can work on one PC and not on another. It can work on one version and not another. There's nothing specific to the 2014 version.

 

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes
Message 6 of 6

FRFR1426
Collaborator
Collaborator

Also in 2015 and later versions, fibers have been disabled by default.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes