Show hidden autocad applications again after parallel processing

Show hidden autocad applications again after parallel processing

Anonymous
Not applicable
446 Views
3 Replies
Message 1 of 4

Show hidden autocad applications again after parallel processing

Anonymous
Not applicable

I use VBA (excel) to control several autocad instances at same time to do a parallel processing, (i can´t believe acad is not multithread). I start the applications and make them invisible, but if some error occur, the apps stay invisible.

How can I make them invisible again, since the code stop and I lose the object associated with the app?

Of course there are some tuff ways like: http://forums.autodesk.com/t5/visual-basic-customization/shuffeling-application-windows/m-p/300534/h...

But I wonder if there is a tricky one…

Regards,

0 Likes
447 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I use Immediate Window with statements:

Set Acad = GetObject(, "AutoCAD.Application")
Acad.Visible = True

I guess you could use them in a Sub, too.

0 Likes
Message 3 of 4

Anonymous
Not applicable
The problem is that I have four or more acad applications running at same
time (4 or more different instances). How to get each one?
(of course I can do it using Windows API... but my code is very simple and I
don?t want to extend it...)
Regards,

Leonardo
0 Likes
Message 4 of 4

Anonymous
Not applicable

I guess you could act the same way more times, everytime closing (quitting) the running instance

 

should you want to get all open drawings back without the aid of Windows API, you could use a sub that loops through all autocad running instances one by one and lists each open document full name in a listbox. To do this you still have to close each Autocad running instance by the end of the loop

 

then you could use that list to open as many brand new autocad sessions as you want by the use of CreatObject() and open the drawings whose name you have just saved in the list

 

something like this (I assume you have a UserForm named UF1 with a Listbox named OpenDwgsLB)

Option Explicit
Sub GetAutocadDrawings()

Dim Acad As AcadApplication
Dim DwgDoc As AcadDocument

Dim OpenDwgsLB As MSForms.ListBox

'set and clear ListBox
Set OpenDwgsLB = UF1.OpenDwgsLB
OpenDwgsLB.Clear

'for every Autocad instance running process all open drawings
Call set_Acad(Acad) ' get running instance of Autocad, if any
Do While Not Acad Is Nothing

    Acad.Visible = True

    'add all open drawings name to listbox
    For Each DwgDoc In Acad.Documents
        OpenDwgsLB.AddItem DwgDoc.FullName
    Next DwgDoc
    
    ' close all open drawings
    For Each DwgDoc In Acad.Documents
        DwgDoc.Close (False)
    Next DwgDoc
    
    Acad.Quit ' close Autocad running session
    Set Acad = Nothing ' get next running instance of Autocad, if any
    Call set_Acad(Acad)
Loop

With UF1
    .Show
' here you can code whatever you need to handle the drawings list.
' for instance you could have the user select which drawing to open.
    Unload UF1
End With

End Sub

Sub set_Acad(Acad As AcadApplication)
      
On Error Resume Next 'This tells VBA to ignore errors
Set Acad = GetObject(, "AutoCAD.Application") 'Get a running instance of the class AutoCAD.Application
On Error GoTo 0

End Sub

 

0 Likes