English

How To: Return the data source name of an SDE raster layer

Summary

Note:
This article pertains to ArcGIS versions 8.x and 9.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

In ArcMap, you can right-click on a layer to display its properties. The source tab displays the source name of the layer even when the layer has been renamed in the Table of Contents (TOC). This article illustrates how to return the source name for a raster layer using ArcObjects.

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
Note:
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy the following code into the UIButtonControl's click event.
Dim pApp As IApplication
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Dim pRasterLayer As IRasterLayer

Dim pRaster As IRaster
Dim pRasterBandColl As IRasterBandCollection
Dim pEnumRasterBand As IEnumRasterBand
Dim pRasterBand As IRasterBand
Dim pRasterDataset As IRasterDataset
Dim pDataset As IDataset

Set pApp = Application
Set pMxDoc = pApp.Document
Set pMap = pMxDoc.FocusMap
Set pLayer = pMap.Layer(0)
Set pRasterLayer = pLayer  ' QI

Debug.Print "LayerName: " & pLayer.Name
Set pRaster = pRasterLayer.Raster
Set pRasterBandColl = pRaster  ' QI

Set pEnumRasterBand = pRasterBandColl.Bands
pEnumRasterBand.Reset

'Set pRasterBand = pRasterBandColl.BandByName("Band_1")
Set pRasterBand = pEnumRasterBand.Next

Do Until pRasterBand Is Nothing
   
    Set pRasterDataset = pRasterBand.RasterDataset
    Set pDataset = pRasterDataset  ' QI
    Debug.Print "Dataset.Name: " & pDataset.Name
    
    Set pRasterBand = pEnumRasterBand.Next
Loop
  1. Click AddData to load an SDE raster into the TOC.
  2. Right-click on the layer and select the General tab. Provide a new layer name, and click OK.
  3. Click on the button to run the code.
  4. Open the Visual Basic Editor. In ArcMap, select Tools > Macros > Visual Basic Editor.
  5. From the View menu click Immediate Window to review the values returned by the code.