Forgive me, I am a total beginner at this vb.net thing. I have a vba routine that I have used for years to execute a lisp routine on an open document, then switch to the next already open document, and continue until the routine has been performed on each already open documents. For the life of me, I cannot figure out how in vb.net to get a document collection and make each document the active document so that I can execute the lisp routine.
Dim objAcadApp As AcadApplication 'Acad application object
Dim objAcadDocs As AcadDocuments 'Acad documents collection
Dim objAcadDoc As AcadDocument 'Acad document object
Dim i As Integer
Public Sub FixAllIds()
'Get Acad objects
Set objAcadApp = GetObject(, "autoCAD.application") 'get Acad object
Set objAcadDocs = objAcadApp.Documents 'get Acad Documents collection
'step through open drawings
For i = 0 To (objAcadDocs.Count - 1)
'for each drawing run c:fix-id15
Set objAcadDoc = objAcadDocs.Item(i)
'load the routine
objAcadDoc.SendCommand "lo" & vbCr & "fix-id15" & vbCr
'run the routine
objAcadDoc.SendCommand "fix-id15" & vbCr
Thanks in advance for any advice or pointers!
Solved! Go to Solution.
I watched the video, but as far as I can tell he only shows how to get the event flag showing that the user has switched the active document. He doesn't show the code for how to switch focus from one open drawing to another already open drawing.
My goal is to perform various actions on a subset of drawings, which will vary from project to project. All of the examples I have looked at show how to open, change, then close specific drawings by file name. I don't want to hard-code the file names into my .net project, I just want to perform an action on files already open, one-by-one.
If you execute the following code without the CommandsFlags.Session after it switches to another document the code will not continue until to you activate the document that the command was started in. So you have Drawing1-Drawing10 and Drawing1 is active. Without the Sessions flag Drawing2 will become active and your no longer in the "Document Context" of Drawing1. Once you switch back to Drawing1 then the code will continue executing and Drawing3 would become active, etc........
By specifying Sessions flag it will execute in "Application context" and only pause until the alert box is closed so to modify any of the documents you would have to explicitly lock them.
Sorry for not giving a more complete exampe but after I write about 10 lines of VB I start to throw up in my mouth.
<CommandMethod("MyCommand", CommandFlags.Session)> _ Public Sub MyCommand() ' This method can have any name Dim docMgr As DocumentCollection = Application.DocumentManager For Each doc As Document In docMgr Application.DocumentManager.MdiActiveDocument = doc Application.ShowAlertDialog(doc.Name) Next End Sub