Jochen Reichert of the University of Stuttgart asks: How can I determine all the view ports of a drawing sheet and vice versa?
To determine the view ports of a drawing sheet, you can simply use the ViewSheet Views property.
It returns the set of all views on the sheet.
For the inverse relationship, you can create a mapping of your own as described in the discussion on
inverting the relationship
between hosted und hosting elements such as doors, windows and walls.
Here is some code demonstrating this for the viewport and view sheet relationships.
It sets up two mappings, one from each view sheet to all its contained viewports, the other from each viewport to the view sheet containing it, which we expect to be unique:
Application app = commandData.Application;
Document doc = app.ActiveDocument;
List<Element> sheets = new List<Element>();
doc.get_Elements( typeof( ViewSheet ), sheets );
// map with key = sheet element id and
// value = list of viewport element ids:
Dictionary<ElementId, List<ElementId>>
mapSheetToViewport =
new Dictionary<ElementId, List<ElementId>>();
// map with key = viewport element id and
// value = sheet element id:
Dictionary<ElementId, ElementId>
mapViewportToSheet =
new Dictionary<ElementId, ElementId>();
foreach( ViewSheet sheet in sheets )
{
int n = sheet.Views.Size;
Debug.WriteLine( string.Format(
"Sheet {0} contains {1} view{2}: ",
Util.ElementDescription( sheet ),
n, Util.PluralSuffix( n ) ) );
ElementId idSheet = sheet.Id;
foreach( View v in sheet.Views )
{
Debug.WriteLine( " Viewport "
+ Util.ElementDescription( v ) );
if( !mapSheetToViewport.ContainsKey( idSheet ) )
{
mapSheetToViewport.Add( idSheet,
new List<ElementId>() );
}
mapSheetToViewport[idSheet].Add( v.Id );
Debug.Assert(
!mapViewportToSheet.ContainsKey( v.Id ),
"expected viewport to be contained"
+ " in only one single sheet" );
mapViewportToSheet.Add( v.Id, idSheet );
}
}
Here is the output generated for a simple model with three sheets:
Sheet Drawing Sheets contains 3 views:
Viewport Views
Viewport Views
Viewport Views
Sheet Drawing Sheets contains 1 view:
Viewport Views
Sheet Drawing Sheets contains 1 view:
Viewport Views
Here is
version 1.0.0.18
of the complete Visual Studio solution with the new command CmdListViews discussed here.

Leave a Reply