activate specific opened drawing

activate specific opened drawing

Anonymous
Not applicable
3,010 Views
4 Replies
Message 1 of 5

activate specific opened drawing

Anonymous
Not applicable

Hello,

 

I need a little kick in the right direction, because I can't get it:

I have several dwg's open in AutoCAD and start a script which opens another file, does some stuff and closes the file.

After closing, I want to get back / reactivate the drawing where I started from and not activate the ltest opened file.

But how do I get it? (Especially I don't get how to set the active / start dwg as activeDwg)

The code

...

Dim ActiveDwg as AcadDocument

ActiveDwg = ThisDrawing '<---- the missing / wrong step, I think

' ...open another dwg

'..do some stuff

' ...close dwg

ThisDrawing.ActiveLayout = ThisDrawing(ActiveDwg)

….

It would be nice, if someone could give mi an advice 🙂

 

thanks and kind regards

 

 

0 Likes
Accepted solutions (2)
3,011 Views
4 Replies
Replies (4)
Message 2 of 5

BestFriendCZ
Advocate
Advocate
Accepted solution

What about this ... save index your start document and use this

Sub Test()
    Dim activeDoc As AcadDocument
'    0 index of document which you want 0..1..2
    Set activeDoc = ThisDrawing.Application.Documents(0)
    activeDoc.Activate
End Sub
...
0 Likes
Message 3 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

A sample workflow for your subroutine:

 

Sub MyWorkProcess()
   Dim lastDwg As AcadDocument
   Set lastDwg = ThisDrawing
   ' Open new dwg and work on it
   lastDwg.Activate
End Sub

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 4 of 5

Anonymous
Not applicable

Both ways work - thanks a lot! Man Happy

 

kind regards

0 Likes
Message 5 of 5

Anonymous
Not applicable

Stumbled across this solution, it's a good one, but I'm thinking if you can let the user decide where the right drawing is (because it might change each day you use it), like this:

 

Sub cycleDwgs()
Dim activeDoc As AcadDocument
Dim i As Long, docTot As Long
docTot = ThisDrawing.Application.Documents.Count
For i = 1 To docTot
Set activeDoc = ThisDrawing.Application.Documents(i - 1)
Debug.Print activeDoc.Name
If MsgBox("Is this the document you're looking for?" & vbCrLf & vbCrLf & activeDoc.Name, vbYesNo + vbQuestion, "This dwg?") = vbYes Then
activeDoc.Activate
Exit For
End If
Next i

'Continue using the correct document here, but call it as "activeDoc"

End Sub

 

0 Likes