.NET

Reply
Active Member
johnsnow
Posts: 10
Registered: ‎07-01-2005
Message 1 of 5 (508 Views)
Accepted Solution

How to switch between multiple open documents?

508 Views, 4 Replies
12-05-2012 03:01 PM

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!

Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 2 of 5 (495 Views)

Re: How to switch between multiple open documents?

12-05-2012 09:47 PM in reply to: johnsnow

AutoCAD VBA to VB.NET Migration Basics


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Member
johnsnow
Posts: 10
Registered: ‎07-01-2005
Message 3 of 5 (401 Views)

Re: How to switch between multiple open documents?

04-11-2013 08:08 AM 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.

Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 4 of 5 (392 Views)

Re: How to switch between multiple open documents?

04-11-2013 10:01 AM 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
Moderator
Alexander.Rivilis
Posts: 1,388
Registered: ‎04-09-2008
Message 5 of 5 (385 Views)

Re: How to switch between multiple open documents?

04-11-2013 11:05 AM in reply to: jeff

You also need to enable switching:

Application.DocumentManager.DocumentActivationEnabled = True

Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community