I am trying to select a viewport using com (since I still only have autocad 2005), The following is my code but no matter what I try I get nothing.
Right now I am trying to return just the ID of the vp, just to see if I can even pick it , but no luck.
Any ideas? Please help
Also, I am trying to do this from a form by pressing a button then hiding the form, if that has anything to do with it.
Dim COMDoc As Autodesk.AutoCAD.Interop.AcadDocument
COMDoc = COMApp.ActiveDocument
COMApp.Visible = True
COMDoc.Application.Visible = True
Dim SelSets As Autodesk.AutoCAD.Interop.AcadSelectionSets = COMDoc.SelectionSets
Dim NewSelSet As Autodesk.AutoCAD.Interop.AcadSelectionSet = Nothing
Dim ViewPort As Autodesk.AutoCAD.Interop.Common.AcadViewport
Dim ObjID As ObjectId
Try
Me.Close()
Try
NewSelSet = SelSets.Add("TempSelSet")
NewSelSet.Clear()
Catch ex As Exception
NewSelSet = SelSets.Item("TempSelSet")
NewSelSet.Clear()
End Try
Try
If Not NewSelSet Is Nothing Then
Dim Filtertype(0) As Short
Dim FilterData(0) As Object
NewSelSet.SelectOnScreen(Filtertype, FilterData)
For Each ent As Autodesk.AutoCAD.Interop.Common.AcadEntity In NewSelSet
If TypeOf ent Is Autodesk.AutoCAD.Interop.Common.AcadViewport Then
ViewPort = ent
ObjID = ent.Id
Exit For
End If
Next
End If
Catch ex As Exception
MsgBox("Unable to get Selection Set")
End Try
MsgBox("The vp id is: " & ObjID.ToString)
NewSelSet.Delete()
COMDoc = Nothing
Me.Close()
Catch ex As Exception
MsgBox("The following error occured: " & vbCrLf & ex.Message & vbCrLf & _
"Source: " & vbCrLf & ex.Source & vbCrLf & _
"Stack Trace: " & vbCrLf & ex.StackTrace)
End Try