TheSwamp

Code Red => .NET => Topic started by: Jeff H on September 08, 2010, 04:53:38 PM

Title: PaperSpace Viewport
Post by: Jeff H on September 08, 2010, 04:53:38 PM
Is the best way to distinguish the PaperSpace viewport from a "Floating Viewport" is the Viewport.Number

If so if safe to assume that for a PaperSpace Layout with one Floating Viewport

The Paperspace viewport  Viewport.Number = 1
And the  "Floating viewport" Viewport.Number = 2

Or if it has multiple floating viewports
The Paperspace viewport  Viewport.Number = 1
And the  "Floating viewport's" Viewport.Number >= 2



Title: Re: PaperSpace Viewport
Post by: David Hall on September 08, 2010, 06:34:09 PM
i haven't checked, but what about Layout2?  Would it be #2 or 4? or is it Layout.Viewport.Number?
Title: Re: PaperSpace Viewport
Post by: Bryco on September 08, 2010, 07:41:05 PM
The paperspace viewport always has the lowest objectid
and the first item in the paperspace block
using(Transaction tr = db.TransactionManager.StartTransaction())       
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord PaperSpace = tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead) as BlockTableRecord;
                Viewport PaperSpaceVp=null;
                foreach(ObjectId id in PaperSpace)
                {
                    PaperSpaceVp = tr.GetObject(id, OpenMode.ForRead) as Viewport; 
                    break;
                }
                ed.WriteMessage(Environment.NewLine + PaperSpaceVp.Number.ToString());     
                tr.Commit();       
            }
Title: Re: PaperSpace Viewport
Post by: gile on September 09, 2010, 02:07:14 AM
Hi,

I think the Viewport.Number is the right way to distinguish paperspace and floating viewports. It the way I use to use with LISP.
You can deal with this within a selection filter.

Code: [Select]
[CommandMethod("TEST")]
        public void Test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            TypedValue[] filter = { new TypedValue(0, "VIEWPORT"),
                                      new TypedValue(-4, "!="),
                                      new TypedValue(69, 1) };
            PromptSelectionResult psr = ed.SelectAll(new SelectionFilter(filter));
            ed.WriteMessage("\nThis drawing contains {0} floating viewport(s)",
                psr.Status == PromptStatus.OK ? psr.Value.GetObjectIds().Length : 0);
        }
Title: Re: PaperSpace Viewport
Post by: Jeff H on September 09, 2010, 06:02:35 AM
Thanks gile, Bryco, and CmdrDuh for the pointers this is what I have come up with so far. I only tested the mentioned below with a couple of different scenarios

The Viewport.Number is tied to the CVPORT sytem variable so
If model space is active you get a -1 for each Viewport number

If you get the PaperSpace ViewPort ObjectId by Database.PaperSpaceVportId
You can check if the viewport objectid is assinged the Database.PaperSpaceVportId to weed it out
This only for the last active or active PaperSpace Layout or if only one Paperspace Layout it does not Matter

You can get the LayoutDictionary and for each Layout you obtain an ObjectIdCollection with Layout.GetViewports
The PaperSpace Viewport will always be the first one

If you create a new drawing the ViewPorts numbers are null until you activate the layout
You can obtain the PaperSpace ViewPort ObjectId with Layout.Intialize but that will only create an ObjectId for the Paperspace ViewPort not any floating Viewports.
You can use the LayerManager.CurrentLayout to go through all the Layouts to activate and get floating Viewports Ids

There is a Editor.ViewportIdFromNumber, ClientViewInfo.ViewPortId and couple others I have not tried


Title: Re: PaperSpace Viewport
Post by: kaefer on September 09, 2010, 07:06:34 AM
You can get the LayoutDictionary and for each Layout obtain an ObjectIdCollection with Layout.GetViewports
The PaperSpace Viewport will always be the first one

Hi fro2001,

there's no need to filter out paperspace viewports or even to obtain ViewportIds if you use Database.GetViewports(false).

From RTFM:
Quote
Input flag indicating whether to return paperspace viewports associated with layouts.

Cheers, Thorsten
Title: Re: PaperSpace Viewport
Post by: Jeff H on September 09, 2010, 07:29:19 PM
Thanks alot kafer that was much eaiser