I'm baaaaack.
I'm beginning to think AutoDesk does not want people to use the .Net interface using forms. It is nothing but trouble. Unfortunately, I have no choice.
I'm still working on converting our custom Block Manager from VBA to .Net. The latest problem I've encountered is AutoCAD won't recognize commands to switch to paperspace (from modelspace) when called from code behind a modeless dialog. I have stepped through the running code and see nothing wrong. I try changing the Tilemode variable - no effect - AutoCAD just seems to ignore it. I tried using 'acDoc.Editor.SwitchToPaperSpace()' - AutoCAD gives me an error: eInvalidInput, as it would if I was already in PaperSpace.
If I call a 'toggle space' routine from a registered command using the command line, it functions like expected, so I know the codes are good. There must be something else involved.
Any ideas?
Solved! Go to Solution.
Solved by stevenelliott3894. Go to Solution.
Here is my sub:
Public Sub ChangeSpace(Optional ByVal ChangeType As String = "Toggle")
'' Tilemode = 0 : PaperSpace tab is active
'' CVPort = 2 : ModelSpace is active in a viewport
'' CVPort <>2 : PaperSpace is active
'' Tilemode = 1 : ModelSpace tab is active
'' Get the current document
Dim acDoc As Document = AcApp.DocumentManager.MdiActiveDocument
'' Get the current values of CVPORT and TILEMODE
Dim nCvports As Integer = AcApp.GetSystemVariable("CVPORT")
Dim nTilemode As Integer = AcApp.GetSystemVariable("TILEMODE")
If ChangeType = "Toggle" Then
'' Check to see if the Model layout is active, TILEMODE is 1 when
'' the Model layout is active
If nTilemode = 0 Then
'' CVPORT is 2 if Model space is active in a viewport
If nCvports = 2 Then
acDoc.Editor.SwitchToPaperSpace()
Else
acDoc.Editor.SwitchToModelSpace()
End If
Else '' Switch to the previous Paper space layout
'acDoc.Editor.SwitchToPaperSpace()
AcApp.SetSystemVariable("TILEMODE", 0)
End If
ElseIf ChangeType = "Paper" Then
If nTilemode = 0 Then
If nCvports = 2 Then
acDoc.Editor.SwitchToPaperSpace()
End If
Else
AcApp.SetSystemVariable("TILEMODE", 0)
'acDoc.Editor.SwitchToPaperSpace()
End If
Else 'ChangeType = "Model"
If nTilemode = 0 Then
If nCvports <> 2 Then
acDoc.Editor.SwitchToModelSpace()
End If
Else
AcApp.SetSystemVariable("TILEMODE", 1)
End If
End If
nTilemode = AcApp.GetSystemVariable("TILEMODE")
End Sub
The solution to this was to lock the document. Even though one would think (at least *I* thought) that switching tabs was not editing the document, the proof is in the pudding, so to speak (it now works).
Thanks to Gile over at TheSwamp (www.theswamp.org) for smacking me in the face with this (almost) obvious solution.