Distinguished Contributor
Posts: 146
Registered: ‎04-14-2005
Message 1 of 4 (229 Views)

Setting MDIActiveDocument freezes the program

229 Views, 3 Replies
11-05-2012 06:02 AM



I'm trying to switch documents and add some text. But the program switches to the document then freezes without executing any lines after switching documents.  Ive done this before without a problem. Any help would be much appreciated.


Thanks in Advance

If flyToHandle <> "" Then
                        Dim docIsopen As Boolean = False
                        For Each doc As Document In DocumentManager
                            If doc.Name = flyToDwgName Then
                                docIsopen = True
                                acdoc = doc
                                DocumentManager.MdiActiveDocument = acdoc
                            End If
                        If docIsopen = False Then
                            acdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(flyToDwgName, False)
                            DocumentManager.MdiActiveDocument = acdoc
                            Using lockDoc As DocumentLock = acdoc.LockDocument
                                Dim dsCom As DSCCommands = New DSCCommands
                                flyToHandle = ""
                            End Using
                        End If
                    End If


Board Manager
Posts: 359
Registered: ‎05-22-2006
Message 2 of 4 (216 Views)

Re: Setting MDIActiveDocument freezes the program

11-05-2012 01:43 PM in reply to: GeeHaa

Is your code running in the 'Document' context or the 'Session' context? If the former, I'd expect your code to freeze when another document became active. That's by design.


Stephen Preston
Autodesk Developer Network
Distinguished Contributor
Posts: 146
Registered: ‎04-14-2005
Message 3 of 4 (194 Views)

Re: Setting MDIActiveDocument freezes the program

11-06-2012 06:01 AM in reply to: StephenPreston

I think I'm in document context. But I'm not sure. In my previous program -The one that works, I switched documents inserted a block with attributes then swiched back to the original drawing and inserted a block with attributes. In this program I'm first adding text to the current document then switching to another drawing. when it freezes.


How do you set up for session as opposed to document context?


Thanks Very much

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 4 of 4 (181 Views)

Re: Setting MDIActiveDocument freezes the program

11-06-2012 02:45 PM in reply to: GeeHaa

If your code is in or called from a CommandMethod that has the CommandFlags.Session flag, it runs in the ApplicationContext, otherwise it runs in the document context.


You can check by calling DocumentCollection.IsApplicationContext.


To switch documents, your code must be running in the application context, and if it modifies anything in a document it must lock the document before/after making the changes.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community