.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to test if you are in modelspace or paperspace?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
drauckman
3023 Views, 5 Replies

How to test if you are in modelspace or paperspace?

I am currently using the following to switch to modelspace:

 

 

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.SwitchToModelSpace();

 

 

However if you already are in modelspace it throws the error: eInvalidInput

 

How do I find out which space I am in so I can avoid running this when already in modelspace?

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: drauckman

Go to the Autocad .NET Developer's Guide

And go to the section Floating Viewports 

Message 3 of 6
Anonymous
in reply to: drauckman

If the CVPORT system variable is > 1 you are in model space

Message 4 of 6
cbutler1
in reply to: Anonymous

I have the same problem.  We were using CVPORT with objectARX and that seemed to work. Since then we've switched to AutoCAD 2011.  In VB .NET, when I query the CVPORT variable after switching from Model Space (tilemode = 1) to PaperSpace (Tilemode = 0) CVPORT = 2 even though it's in pspace.  I can query CVPORT from the command line and it returns 1. If I enter mspace and return to pspace from the layout, CVPORT is 1.

 

Imports AAcAs = Autodesk.AutoCAD.ApplicationServices
Imports AAcDb = Autodesk.AutoCAD.DatabaseServices

Public Class Initialize
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

    Public Sub Initialize() Implements AAcRx.IExtensionApplication.Initialize

        AddHandler AAcAs.Application.SystemVariableChanged, AddressOf _SystemVariableChanged
    End Sub

    Public Sub _SystemVariableChanged(ByVal sender As Object, ByVal e As AAcAs.SystemVariableChangedEventArgs)
        If e.Name.ToUpper = "CANNOSCALE" Or e.Name.ToUpper = "CVPORT" Or e.Name.ToUpper = "TILEMODE" Then
            'Dim Foo As New SymUtil
            Dim ScaleValue As Double
            Dim Tilemode As Integer
            Dim CVPort As Integer
            Dim CTAB As String

            ' Get the Tilemode value and CVPort value
            Tilemode = CType(AAcAs.Application.GetSystemVariable("TILEMODE"), Integer)

            ' AutoCAD returning 2 when switching from model to layout when pspace active. AutoCAD BUG???
            CVPort = CType(AAcAs.Application.GetSystemVariable("CVPORT"), Integer)

             ' Do Stuff

    End Sub
End Class

 How else can I determine if I'm in pspace or mspace?

 

Craig

 

Message 5 of 6
SRSDS
in reply to: drauckman

Old thread but another method if it helps anyone

Dim layoutMgr As LayoutManager = LayoutManager.Current
If layoutMgr.CurrentLayout = "Model" Then

 

Message 6 of 6
_gile
in reply to: SRSDS


@SRSDS  a écrit :

Old thread but another method if it helps anyone

Dim layoutMgr As LayoutManager = LayoutManager.Current
If layoutMgr.CurrentLayout = "Model" Then

 


Take care, this code evaluates if the current layout is model space not if you are in the model space of a floating viewport of an active paper space layout.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost