.NET

Reply
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 1 of 7 (163 Views)

how to active a document?

163 Views, 6 Replies
06-21-2005 06:46 PM
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;
*Albert Szilvasy
Message 2 of 7 (163 Views)

Re: how to active a document?

06-21-2005 09:22 PM 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;
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 3 of 7 (163 Views)

Re: how to active a document?

06-22-2005 07:22 AM 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 .
*Albert Szilvasy
Message 4 of 7 (163 Views)

Re: how to active a document?

06-22-2005 08:00 AM 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 .
*Tony Tanzillo
Message 5 of 7 (163 Views)

Re: how to active a document?

06-22-2005 08:22 AM 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 .
*Tony Tanzillo
Message 6 of 7 (163 Views)

Re: how to active a document?

06-22-2005 01:25 PM 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 .
Valued Contributor
netcai
Posts: 66
Registered: ‎07-22-2004
Message 7 of 7 (163 Views)

Re: how to active a document?

06-22-2005 05:59 PM 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.
}
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.