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

Setting MDIActiveDocument freezes the program

3 REPLIES 3
Reply
Message 1 of 4
GeeHaa
506 Views, 3 Replies

Setting MDIActiveDocument freezes the program

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

 

3 REPLIES 3
Message 2 of 4
StephenPreston
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
Message 3 of 4
GeeHaa
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

Message 4 of 4
DiningPhilosopher
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.

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