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

How to switch between multiple open documents?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
johnsnow
6190 Views, 5 Replies

How to switch between multiple open documents?

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.

 

VBA code:

=====================================================

Option Explicit
    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)
        objAcadDoc.Activate
        'load the routine

        objAcadDoc.SendCommand "lo" & vbCr & "fix-id15" & vbCr
        'run the routine

        objAcadDoc.SendCommand "fix-id15" & vbCr
        
        Next i
        
End Sub

=====================================================

 

Thanks in advance for any advice or pointers!

5 REPLIES 5
Message 2 of 6

AutoCAD VBA to VB.NET Migration Basics

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 6
johnsnow
in reply to: johnsnow

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.

Message 4 of 6
jeff
in reply to: johnsnow

Note:

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

 

You can also find your answers @ TheSwamp
Message 5 of 6
Alexander.Rivilis
in reply to: jeff

You also need to enable switching:

Application.DocumentManager.DocumentActivationEnabled = True

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 6

Hi Alex do you think you could take a look at this thread?

 

http://forums.autodesk.com/t5/net/change-activedocument/m-p/5464181/highlight/false#M42929

 

It seems to be in the same vain as this thread but the same solution doesn't 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