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

ModelSpace vs. PaperSpace Viewport

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
junoj
1234 Views, 11 Replies

ModelSpace vs. PaperSpace Viewport

Hi, is there a way to be able to distinguish if the ModelSpace from PaperSpace Viewport. ‘.CurrentSpaceId’ points to the model space when looking at the model space via paperspace viewport.

11 REPLIES 11
Message 2 of 12
_gile
in reply to: junoj

Hi,

 

Look at the TILEMODE and CVPORT sytem variables.

 

The TileMode sysvar (or Database property) indicates if the Model layout si active (1) or any other layout 0.

If TileMode = 0, the CVPORT sysvar returns the current viewport number, 1 is the number of the layout viewport and indicates the Paper space is active. Values greater than 1 indicates a floating viewport is active (Model space through the viewport).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 12
BlackBox_
in reply to: junoj

Quick example:

 

// <snip>

// using transaction (tr) ObjectId spaceId; if (1 == System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"))) spaceId = SymbolUtilityServices.GetBlockPaperSpaceId(db); else spaceId = SymbolUtilityServices.GetBlockModelSpaceId(db); BlockTableRecord btr = tr.GetObject(spaceId, OpenMode.ForWrite) as BlockTableRecord;
// do something useful

// commit()
// <snip>

 



"How we think determines what we do, and what we do determines what we get."

Message 4 of 12
junoj
in reply to: junoj

Thank you very much Gilles and BlackBox. Both of your methods will work providing that I have the drawing open with Autocad. Unfortunately I am accessing the dwg remotely without opening the application, so the application object is not available to me.

Message 5 of 12
_gile
in reply to: junoj

You can use the Database.TileMode property to know if the current layout is the Model Layout or any other layout

You can use the Database.CurrentSpaceId to get the current space and compare it to theobjectId return by SymbolUtilityServices.GetBlockModelSpaceId()

 

            if (db.TileMode)
            {
                // The Model layout is active
            }
            else if (db.CurrentSpaceId == SymbolUtilityServices.GetBlockModelSpaceId(db))
            {
                // A floating viewport in a paper space layout is active
            }
            else
            {
                // A paper space is active
            }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 12
junoj
in reply to: _gile

Thank you very much Gilles!!!
Message 7 of 12
junoj
in reply to: _gile

One more quick question Gilles, Is it possible to get the ID of the Layout when a viewport is active - looking at the model space? When I try 'CurrentSpaceId' i get the ID of the model space.
Message 8 of 12
BlackBox_
in reply to: junoj


@junoj wrote:
One more quick question Gilles, Is it possible to get the ID of the Layout when a viewport is active - looking at the model space? When I try 'CurrentSpaceId' i get the ID of the model space.

Perhaps this excerpt from the developer documentation will help:

 

 

 http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-2CEED409-0E15-4F48-9AA1-D12D246E27DB...

 


Identify and Manipulate the Active Viewport (.NET) :

 

The active viewport is represented in the Viewports table by a record named "*Active", which is not a unique name as all tiled viewports currently displayed on the Model tab are named "*Active". Each tiled viewport that is displayed is assigned a number. The number of the active viewport can be obtained by:

 

  • Retrieving the value of the CVPORT system variable
  •  
  • Using the ActiveViewportId property of the Editor object to get the object id for the active viewport and then open the Viewport object to access its Number property
Once you have the active viewport, you control its display properties, enable drafting aids for the viewport such as grid and snap, as well as the size of the viewport itself. Tiled viewports are defined by two corner points: lower-left and upper-right. The LowerLeftCorner and UpperRightCorner properties represent the graphic placement of the viewport on the display.


"How we think determines what we do, and what we do determines what we get."

Message 9 of 12
junoj
in reply to: junoj

Thank you BlackBox. My understanding is that the CVPORT variable is for viewports. What I am trying to obtain is the CTAB system variable. The CTAB variable has the name of the current tab regardless if one of the viewports is active.

 

I am able to obtain the CTAB  variable via the GetSystemVariable , but I am having a hard time finding a way to access same variable without opening the drawing.

 

I think CTAB is a very elegant solution, providing I can find a way to obtain the variable.

Message 10 of 12
BlackBox_
in reply to: junoj

Sorry for my misunderstanding... Consider LayoutManager.Current.CurrentLayout as Viru demonstrates in this DevBlog article:

 

http://adndevblog.typepad.com/autocad/2012/06/identifying-active-space-and-active-layout.html

 

 

[Edit] - Forgot to mention using the LayoutManager's GetLayoutId() Method (using CurrentLayout as the string parameter)

 

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 11 of 12
junoj
in reply to: BlackBox_

Thank you BlackBox for the response.  The link to the code that you provided works nice only if one is in the Model Tab or in the Layout Tab.

 

However if you are in the Layout Tab (Paper Space) and you are looking via the viewport at the Model Space then the code will return the Model Space ID.

Message 12 of 12
BlackBox_
in reply to: junoj

I overlooked your earlier statement that you're attempting to identify the active space from a side Database... The only other thing I can think to suggest without Googling, is for you to consider Database.CurrentSpaceId as Kean suggests here:

 

http://through-the-interface.typepad.com/through_the_interface/2007/09/accessing-the-a.html

 

 

 

... Perhaps someone much smarter than I will be along shortly, to better suggest a solution. Sorry I could not be of more help.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

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