Good day all.
Explanation of Issue: I am using a modeless form as a block library insertion tool. Everything about it works great except when there is more than one drawing open in the session. In that case it always when activated switches back to the drawing in which it was originally opened instead of staying on the current drawing. How do I disconnect the drawing in which the modeless from was opened in and reassociate it with the current active drawing?
Ron
Solved! Go to Solution.
Solved by mcicognani. Go to Solution.
Have you specified the CommandFlag.Session attribute on the starting command?
Since Modeless dialog does nto block AutoCAD process until it is dismissed, user can switch current document, as you experienced. Therefore, the the data shown in the modeless dialog is somehow related to given drawing, then you need to do something, such as either close the modeless dialog when the associated document becomes not current; or change the data shown iin the dialog box to the data associated to the new current document.
Either way, you need to handle DocumentBecameCurrent and/or DocumentActivated event (usually DocumentBecameCurrent), so that what current document changes, you do somethign accordingly.
This link might be of help:
http://drive-cad-with-code.blogspot.ca/2014/02/showing-and-closing-modeless-formdialog.html
Norman Yuan
I have a very similar application, mine use a palette and is istantiated on startup. I have no problem with multiple drawings, this is a snippet of the insertion code:
private void InsertBlock(String szFileName) { if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Count == 0) return; // no documents if (!Autodesk.AutoCAD.ApplicationServices.Application.IsQuiescent) return; // AutoCAD busy // get current document ACAD.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; if (doc == null) return; // programmer's paranoia String szName = Path.GetFileNameWithoutExtension(szFileName); String szPath = Path.GetDirectoryName(szFileName); String szFullPath = szPath + "\\" + szName + ".dwg"; if (File.Exists(szFullPath)) { // lock document and set focus on graphics window ACAD.DocumentLock docLock = doc.LockDocument(ACAD.DocumentLockMode.Write, "-insert", "-insert", true); csTools.ActivateEditor();
// send command and let user finish it interactively csTools.GenericSendCommand("_-insert " + szFullPath + "\r _s 1 "); if (doc.LockMode(true) != ACAD.DocumentLockMode.NotLocked) docLock.Dispose(); // unlock document } }