This is a small function that will take into account if you are in a view port or not.
Function GetSpace() As Variant
If IsModelspace Then
Set GetSpace = ThisDrawing.ModelSpace
Else
Set GetSpace = ThisDrawing.PaperSpace
End If
End Function
Public Function IsModelspace() As Boolean
Dim document As AcadDocument
For Each document In Documents
If document.Active = True Then
If document.ActiveSpace = acPaperSpace Then
IsModelspace = document.MSpace
Exit For
Else
IsModelspace = True
Exit For
End If
End If
Next
End Function
---------------------------
(defun botsbuildbots() (botsbuildbots))