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.D
ocumentManager.Open(flyToDwgName, False) DocumentManager.MdiActiveDocument = acdoc Using lockDoc As DocumentLock = acdoc.LockDocument Dim dsCom As DSCCommands = New DSCCommands dsCom.getConnect() dsCom.Init_Conn(HostApplicationServices.WorkingDat abase) flyToHandle = "" End Using End If End If
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.
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
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.