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

Change activedocument

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
harrykeen18
8730 Views, 9 Replies

Change activedocument

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

9 REPLIES 9
Message 2 of 10
j.oehrli
in reply to: harrykeen18

hi

 

did u try after opening the drawing to put

 

opdoc = Application.DocumentManager.MdiActiveDocument

Message 3 of 10
harrykeen18
in reply to: j.oehrli

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

Message 4 of 10
harrykeen18
in reply to: harrykeen18

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"

Message 5 of 10
j.oehrli
in reply to: harrykeen18

            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?

Message 6 of 10
harrykeen18
in reply to: j.oehrli

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

Message 7 of 10
harrykeen18
in reply to: harrykeen18

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

Message 8 of 10
j.oehrli
in reply to: harrykeen18

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
in reply to: harrykeen18

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
j.oehrli
in reply to: harrykeen18

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 😉

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