TheSwamp
Code Red => .NET => Topic started 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
-
i haven't checked, but what about Layout2? Would it be #2 or 4? or is it Layout.Viewport.Number?
-
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();
}
-
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.
[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);
}
-
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
-
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:
Input flag indicating whether to return paperspace viewports associated with layouts.
Cheers, Thorsten
-
Thanks alot kafer that was much eaiser