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
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
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"
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?
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....
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)
In your paticular case, you need to set CommandFlas.Session flag (along with others, if necessary and suitable).
Norman Yuan
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.