GetEntity Not working after changing active document with MdiActiveDocument

GetEntity Not working after changing active document with MdiActiveDocument

startupCCYLP
Explorer Explorer
856 Views
5 Replies
Message 1 of 6

GetEntity Not working after changing active document with MdiActiveDocument

startupCCYLP
Explorer
Explorer

Hello,

 

 

The problem I have is that GetEntity does not work after changing active document with MdiActiveDocument.


At the end of the code you see there are 2 getentity: the first (TEST1) works, that is before the document changes.
The second (TEST2) does not work, that is before the document changes. 

 

To try this you have to:
1) open a drawing called "BEAMS.dwg". Any drawing with that name will do.
2) Create a new drawing and choose it manually as the current active drawing.
3) Run the TestGetEntity command.

 

Please Help me.

 

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;

[CommandMethod("TestGetEntity", CommandFlags.Session)]
public static void TestGetEntity()
{

// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;

DocumentCollection acDocMgr = Application.DocumentManager;

Document acNewDoc3 = null;
bool lFound = false;

foreach (Document doc in acDocMgr)
{
string cNombre = doc.Name;
if (cNombre.Contains("BEAMS"))
{
acNewDoc3 = doc;
lFound = true;
}
}
if (lFound)
{

//THIS WORKS
PromptEntityOptions peo = new PromptEntityOptions("TEST1");
PromptEntityResult per = acDocMgr.MdiActiveDocument.Editor.GetEntity(peo);

// Set the new document current
acDocMgr.MdiActiveDocument = acNewDoc3;

//THIS DOES NOT WORK
peo = new PromptEntityOptions("TEST2");
per = acDocMgr.MdiActiveDocument.Editor.GetEntity(peo);
}
}

0 Likes
857 Views
5 Replies
Replies (5)
Message 2 of 6

norman.yuan
Mentor
Mentor

Well, since Acad2015, in general, switch active drawing would cancel the running command with the current active drawing when the switching occurs.

 

However, it is still possible to switch active document while keep you code execution continuing. A previous discussion in this forum may be of help:

 

https://forums.autodesk.com/t5/net/executeincommandcontextasync-use-in-vb-net/td-p/6987596

 

Here are my 2 articles referred in that discussion:

 

https://drive-cad-with-code.blogspot.com/2017/04/asking-user-to-select-entity-in-other.html

https://drive-cad-with-code.blogspot.com/2017/04/asking-user-to-select-entity-in-other_4.html

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 6

startupCCYLP
Explorer
Explorer

Thank you very much for your help.

 

You say: 

<<Well, since Acad2015, in general, switch active drawing would cancel the running command with the current active drawing when the switching occurs.>>

 

First: I am trying it with autocad 2019

 

I would like to point out that the running command is not "canceled" 100% since everything works except user interaction. This sample I posted is very simple. In my application I do many things after switching the active drawing and everything is done except the user interaction: getentity, etc.

 

 Do you still think it is due to the problem you are talking about ?

0 Likes
Message 4 of 6

norman.yuan
Mentor
Mentor

@startupCCYLP wrote:

Thank you very much for your help.

...

 Do you still think it is due to the problem you are talking about ?


Yes, the issue is due to the change introduced by Acad2015. And I did say "in general" that switching document would cancel executing command; and with custom code, one might be able to work around it, such as the approaches described in my articles (and there may be other ways, too) especially if you only want user to be able to pick from another drawing.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 6

startupCCYLP
Explorer
Explorer

Thank you very much.

0 Likes
Message 6 of 6

viporpa
Contributor
Contributor

I was wondering if there was a way to be able to bounce between multiple tabs(open drawings) without autocad canceling the active command in the current tab that you are working in ? I have multiple drawings open , on top of the one i am working on , for reference. I use to be able to have a command active and tab between any of these drawings to look at what info i needed , only to tab back to my active drawing and my command was still active. I know autodesk removed this at 2015 , but is there anything dealing with your code that can return this to pre-2015 ?

0 Likes