Bounding Box Graphic


A scene can contain graphics in addition to layers. Graphics can be created by tools and commands in ArcScene, or may be created in ArcMap and then pasted into the scene. In order to manage these graphics, ArcScene supports graphics layers. Every scene has at least one graphics layer: the basic graphics layer. It can be retrieved through IScene's BasicGraphicsLayer property.

In the following example, a graphic element is created representing the extent, or bounding box of the scene. It is then added to the graphics container of the scene.

How to use:
  1. Add a layer to ArcScene.
  2. Copy-paste this procedure and run it.
Public Sub AddBoundingBoxGraphicToScene()

    ' get the basic graphics layer from the document
    Dim pSxDoc As ISxDocument
    Set pSxDoc = Application.Document
    Dim pGLayer As IGraphicsLayer
    Set pGLayer = pSxDoc.Scene.BasicGraphicsLayer

    ' get the container interface from the layer
    Dim pGCon3D As IGraphicsContainer3D
    Set pGCon3D = pGLayer
    ' get the active viewer
    Dim pSG As ISceneGraph
    Set pSG = pSxDoc.Scene.SceneGraph
    Dim pViewer As ISceneViewer
    Set pViewer = pSG.ActiveViewer
    ' create point collection to store bounding box points
    Dim pC As IPointCollection
    Set pC = New Polygon
    ' add four points to point collection representing scene's bounding box
    Dim pMapPoint As IPoint
    Set pMapPoint = New Point
    pMapPoint.x = pSG.Extent.XMin
    pMapPoint.y = pSG.Extent.YMin
    pC.AddPoint pMapPoint
    Set pMapPoint = New Point
    pMapPoint.x = pSG.Extent.XMax
    pMapPoint.y = pSG.Extent.YMin
    pC.AddPoint pMapPoint
    Set pMapPoint = New Point
    pMapPoint.x = pSG.Extent.XMax
    pMapPoint.y = pSG.Extent.YMax
    pC.AddPoint pMapPoint
    Set pMapPoint = New Point
    pMapPoint.x = pSG.Extent.XMin
    pMapPoint.y = pSG.Extent.YMax
    pC.AddPoint pMapPoint
    ' create a polygon geometry and have it use the point collection
    Dim pBox As IPolygon
    Set pBox = pC
    'create a color and set it to represent an RGB color
    Dim pColor As IRgbColor
    Set pColor = New RgbColor
    pColor.RGB = 329215
    'create the line symbol to outline the bounding box
    Dim pLSym As ISimpleLineSymbol
    Set pLSym = New SimpleLineSymbol
    pLSym.Width = 4
    pLSym.Color = pColor
    pLSym.Style = esriSLSSolid
    ' create simple bounding box graphic element
    Dim pGElement As IElement
    Set pGElement = New PolygonElement
    ' create FillShapeElement
    Dim pPolyElement As IFillShapeElement
    Set pPolyElement = New PolygonElement
    ' create a simple fill symbol to use as symbol for bounding box
    Dim pFSym As ISimpleFillSymbol
    Set pFSym = New SimpleFillSymbol
    pFSym.Color = pColor
    pFSym.Style = esriSFSHollow
    pFSym.Outline = pLSym
    ' use this FillShapeElement interface to set the symbol for the bounding box
    Set pPolyElement = pGElement
    pPolyElement.Symbol = pFSym
    ' let the graphic element use the bounding box for geometry
    pGElement.Geometry = pBox
    ' add the graphic element to the 3D graphic container
    pGCon3D.AddElement pGElement
    ' unselect all other elements, select this one and show selection handles
    Dim pGS As IGraphicsSelection
    Set pGS = pGCon3D
    pGS.SelectElement pGElement
    ' update the viewers so the change is visible

End Sub