.NET

.NET

Reply
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 1 of 4 (255 Views)

Setting MDIActiveDocument freezes the program

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

Hi

 

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
                        Next
                        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
                                dsCom.getConnect()
                                dsCom.Init_Conn(HostApplicationServices.WorkingDatabase)
                                flyToHandle = ""
                            End Using
                        End If
                    End If

 

ADN Support Specialist
StephenPreston
Posts: 422
Registered: ‎05-22-2006
Message 2 of 4 (242 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.

Cheers,

Stephen Preston
Autodesk Developer Network
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 3 of 4 (220 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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 4 (207 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.