how to active a document?

how to active a document?

Anonymous
Not applicable
1,129 Views
6 Replies
Message 1 of 7

how to active a document?

Anonymous
Not applicable
the following code works well ,but nothing changed ,the active document in autocad still doesn't change.
Document doc = AcadArxApp.DocumentManager.Open(newName1, false);
Database curdb = HostApplicationServices.WorkingDatabase;
HostApplicationServices.WorkingDatabase = doc.Database;
0 Likes
1,130 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
If you want to change the active document in AutoCAD then you should use
DocumentManager.MdiActiveDocument property. But in this case this is
unnecessary since Open will make the newly opened document active. BTW, make
sure that you doing this from a session command. Something like this:
[CommandMethod("active",CommandFlags.Session)]

static public void activate()


wrote in message news:4881365@discussion.autodesk.com...
the following code works well ,but nothing changed ,the active document in
autocad still doesn't change.
Document doc = AcadArxApp.DocumentManager.Open(newName1,
false);
Database curdb = HostApplicationServices.WorkingDatabase;
HostApplicationServices.WorkingDatabase = doc.Database;
0 Likes
Message 3 of 7

Anonymous
Not applicable
I trid DocumentManager.MdiActiveDocument property,but when codes run to this line(DocumentManager.MdiActiveDocument = doc ) ,autocad is actived, and the following code doesn't run .
0 Likes
Message 4 of 7

Anonymous
Not applicable
Are you doing this in a session command? Can you post some
compilable/runnable code?

Albert
wrote in message news:4881770@discussion.autodesk.com...
I trid DocumentManager.MdiActiveDocument property,but when codes run to this
line(DocumentManager.MdiActiveDocument = doc ) ,autocad is actived, and the
following code doesn't run .
0 Likes
Message 5 of 7

Anonymous
Not applicable
You need to read up on execution contexts.

When you run code in the document context, the
code runs only when the associated document is
active. Hence, if your code switches to a different
document, it is suspended until the original
document is active again.

To switch documents and retain control, you must
execute your code in the application context.

Modeless dialogs and Palettes do not execute in
the document context. registered command handlers
run in the document context when they are registered
with "CommandFlags.Session".

Keep in mind that there are other significant
differences between the rules that govern what
code running in the application context can do
(for example, code running in the application
context must lock the document before it can
do many things, including modify the database).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4881770@discussion.autodesk.com...
I trid DocumentManager.MdiActiveDocument property,but when codes run to this line(DocumentManager.MdiActiveDocument = doc )
,autocad is actived, and the following code doesn't run .
0 Likes
Message 6 of 7

Anonymous
Not applicable
Correction:

"registered command handlers run in the
document context when they are registered
with "CommandFlags.Session"

is wrong. It should be:

"registered command handlers run in the
application context when they are registered
with "CommandFlags.Session"


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Tony Tanzillo" wrote in message news:4881901@discussion.autodesk.com...
You need to read up on execution contexts.

When you run code in the document context, the
code runs only when the associated document is
active. Hence, if your code switches to a different
document, it is suspended until the original
document is active again.

To switch documents and retain control, you must
execute your code in the application context.

Modeless dialogs and Palettes do not execute in
the document context. registered command handlers
run in the document context when they are registered
with "CommandFlags.Session".

Keep in mind that there are other significant
differences between the rules that govern what
code running in the application context can do
(for example, code running in the application
context must lock the document before it can
do many things, including modify the database).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4881770@discussion.autodesk.com...
I trid DocumentManager.MdiActiveDocument property,but when codes run to this line(DocumentManager.MdiActiveDocument = doc )
,autocad is actived, and the following code doesn't run .
0 Likes
Message 7 of 7

Anonymous
Not applicable
I found the answer, DocumentManager.Open(newName) and DocumentManager.MdiActiveDocument = doc can't use together,but another problem appear(the file path is correct), see the codes:

[CommandMethod("Cai_Active1", CommandFlags.Session)]
public static void Active1()
{
string refName = @"C:\Ref_S_foot.dwg";
Document doc = AcadArxApp.DocumentManager.Open(newName);
ObjectId xrefId = doc.Database.AttachXref(refName, "RefPlan");
// when run this line, a error appear: Autodesk.AutoCAD.Runtime.Exception: eFileAccessErr
// autocad give a note: File C:\Ref_S_foot.dwg isn't a valid drawing.
}
0 Likes