.NET

Reply
Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 1 of 12 (488 Views)
Accepted Solution

ModelSpace vs. PaperSpace Viewport

488 Views, 11 Replies
08-18-2013 10:32 PM

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.

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
}

 

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 2 of 12 (479 Views)

Re : ModelSpace vs. PaperSpace Viewport

08-18-2013 11:03 PM 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
Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 3 of 12 (452 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-19-2013 05:50 AM 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>

 



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 4 of 12 (440 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-19-2013 08:37 AM 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.

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 5 of 12 (428 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-19-2013 11:00 AM 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
Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 6 of 12 (424 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-19-2013 12:17 PM in reply to: _gile
Thank you very much Gilles!!!
Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 7 of 12 (413 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-19-2013 03:14 PM 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.
Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 8 of 12 (365 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-20-2013 05:41 AM 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.


"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 9 of 12 (351 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-20-2013 07:56 AM 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.

Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 10 of 12 (339 Views)

Re: ModelSpace vs. PaperSpace Viewport

08-20-2013 11:36 AM 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



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.