Author Topic: PaperSpace Viewport  (Read 5345 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
PaperSpace Viewport
« 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




David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: PaperSpace Viewport
« Reply #1 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?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: PaperSpace Viewport
« Reply #2 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();       
            }
« Last Edit: September 08, 2010, 08:11:13 PM by Bryco »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: PaperSpace Viewport
« Reply #3 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);
        }
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 6150
Re: PaperSpace Viewport
« Reply #4 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


« Last Edit: September 22, 2010, 01:50:14 AM by fro2001 »

kaefer

  • Guest
Re: PaperSpace Viewport
« Reply #5 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

Jeff H

  • Needs a day job
  • Posts: 6150
Re: PaperSpace Viewport
« Reply #6 on: September 09, 2010, 07:29:19 PM »
Thanks alot kafer that was much eaiser