.NET

Reply
Valued Contributor
Ron_M
Posts: 61
Registered: ‎12-09-2013
Message 1 of 5 (102 Views)
Accepted Solution

Modeless Form & Mutliple Drawings Open

102 Views, 4 Replies
07-02-2014 06:25 AM

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

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 2 of 5 (95 Views)

Re: Modeless Form & Mutliple Drawings Open

07-02-2014 06:34 AM in reply to: Ron_M

Have you specified the CommandFlag.Session attribute on the starting command?

*Expert Elite*
norman.yuan
Posts: 987
Registered: ‎04-27-2009
Message 3 of 5 (93 Views)

Re: Modeless Form & Mutliple Drawings Open

07-02-2014 06:36 AM in reply to: Ron_M

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

 

Valued Contributor
Ron_M
Posts: 61
Registered: ‎12-09-2013
Message 4 of 5 (87 Views)

Re: Modeless Form & Mutliple Drawings Open

07-02-2014 06:59 AM in reply to: mcicognani

CommandFlag.Session set.

Distinguished Contributor
mcicognani
Posts: 125
Registered: ‎12-01-2004
Message 5 of 5 (81 Views)

Re: Modeless Form & Mutliple Drawings Open

07-02-2014 07:09 AM in reply to: Ron_M

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 == nullreturn;    // 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     } }

 

 

 

 

Announcements
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 or visit the Installation and Licensing Forum to get help installing your software.