.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to active a document?

6 REPLIES 6
Reply
Message 1 of 7
netcai
362 Views, 6 Replies

how to active a document?

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;
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: netcai

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;
Message 3 of 7
netcai
in reply to: netcai

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 .
Message 4 of 7
Anonymous
in reply to: netcai

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 .
Message 5 of 7
Anonymous
in reply to: netcai

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 .
Message 6 of 7
Anonymous
in reply to: netcai

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 .
Message 7 of 7
netcai
in reply to: netcai

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.
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost