Change activedocument

Change activedocument

Anonymous
Not applicable
11,405 Views
9 Replies
Message 1 of 10

Change activedocument

Anonymous
Not applicable

Hi,

 

I'm running a command from an original drawing to open a another drawingand apply some edits to it. I open the newdrawing with;

 

Dim FileName As String = "C:\XXX.dwg"

Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim opdoc As Document = DocumentCollectionExtension.Open(acDocMgr, FileName)

 

then when I run the editing code after this code it applies the edits to original drawing, as I believe this is still the active drawing - my question is what is the best way apply these edits to the new just opened drawing? Can I switch the active document to the new drawing...? Or is there another way?

 

Thanks,

 

Harry

0 Likes
Accepted solutions (3)
11,406 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

hi

 

did u try after opening the drawing to put

 

opdoc = Application.DocumentManager.MdiActiveDocument

0 Likes
Message 3 of 10

Anonymous
Not applicable

yeh, should have said, that is the next line in the current script

0 Likes
Message 4 of 10

Anonymous
Not applicable

So i thought if I try and close the original drawing before opening the new one with;

 

Dim doccol As DocumentCollection = Application.DocumentManager

DocumentCollectionExtension.CloseAll(doccol)

 

It might automatically set the new drawing it opens as the "activedocument"

 

Buuuut that didn't work, it can't close it throwing an error saying "document is busy"

0 Likes
Message 5 of 10

Anonymous
Not applicable

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument

            CloseAndDiscard(doc)
            doc = Nothing

 

works in my skript just fine

 

but even this will work it is just a workaround and in the end would not realy serve ur goal

 

have a look on this threat http://forums.autodesk.com/t5/net/how-to-switch-between-multiple-open-documents/td-p/3724860

maybe it solves ur problem

 

it just came to my mind: did u set commandflag.session?

0 Likes
Message 6 of 10

Anonymous
Not applicable

mmm, tried a few things with this;

 

Application.DocumentManager.DocumentActivationEnabled = True

 

As I understand it this enables a new doc to be activated when a new window has been opended but doesn't seem to get any better results;

 

Here is the code im using can you see any glaring errors?;

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.Runtime
Imports System.Collections.Generic

Namespace CustomMove
Public Class Commands


<CommandMethod("copymove", CommandFlags.UsePickSet)> _
Public Shared Sub CustomMoveCmd()

 

Dim FileName As String = "C:\xxxx.dwg"

 

Application.DocumentManager.DocumentActivationEnabled = True

 

Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim opdoc As Document = DocumentCollectionExtension.Add(acDocMgr, FileName)

 

'opdoc = Application.DocumentManager.MdiActiveDocument
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor

 

 

etc....

0 Likes
Message 7 of 10

Anonymous
Not applicable

Do you think it could be something to do with the command flag?

0 Likes
Message 8 of 10

Anonymous
Not applicable
Accepted solution

yes i think so

 

u need commandflag.session when u want change something outside a specific document (if u want for ex open close or add documents)

Message 9 of 10

norman.yuan
Mentor
Mentor
Accepted solution

In your paticular case, you need to set CommandFlas.Session flag (along with others, if necessary and suitable).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 10

Anonymous
Not applicable
Accepted solution

Hi harry

 

I just found a nice way to swich between different databases!

 

use:

 

HostApplicationServices.WorkingDatabase = db 'the database u want to swich to

 

hope this solves ur problem

 

PS: u dont need to set sessionflags.session for this to work 😉

0 Likes