2

I have created an ArcMap add-in for browsing data layers and adding them to the TOC. I would like to add a button that when clicked will open the selected layers item description (before it is added to the TOC) however I can't seem to find any documentation on how to accomplish this.

Basically I want the same functionality as the 'View Item Description...' in the 'Data' menu when right clicking a layer in the TOC. So when the button is pressed the item description window is opened. Any one have any ideas I thought for sure there would be an easy way to do this?

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Jun 16, 2016 at 18:22
0

1 Answer 1

2

Below is some VBA code that shows you how to open the Item Description window from the first layer in the TOC.

Public Sub OpenItemDescription()
 ' Get Application
 Dim pApp As IApplication
 Set pApp = Application
 ' Get Map document
 Dim pMXD As IMxDocument
 Set pMXD = ThisDocument
 ' Get Map
 Dim pmap As IMap
 Set pmap = pMXD.FocusMap
 ' Get first layer in TOC
 Dim pLayer As ILayer
 Set pLayer = pmap.Layer(0)
 ' Get Dataset
 Dim pDataset As IDataset
 Set pDataset = pLayer
 Dim pName As IName
 Set pName = pDataset.FullName
 Dim pFeatureClassName As IFeatureClassName
 Set pFeatureClassName = pName
 ' Get Metadata for dataset
 Dim pMetaData As IMetadata
 Set pMetaData = pFeatureClassName
 ' Open window
 Dim pMetadataViewWindow As IMetadataViewWindow2
 Set pMetadataViewWindow = New MetadataViewWindow
 With pMetadataViewWindow
 Set .Application = pApp
 Set .Layer = pLayer
 Set .Metadata = pMetaData.Metadata
 .Show True
 End With
End Sub

Edit

Here is the code in c#.

 private void viewMetadataButton_Click(object sender, EventArgs e)
 {
 IGxLayer gxLayer = new GxLayerClass();
 IGxFile gxFile = gxLayer as IGxFile;
 gxFile.Path = @lyrPath;
 ILayer layer = gxLayer.Layer as ILayer;
 IDataset pDataSet = (IDataset)layer;
 IName pName = (IName)pDataSet.FullName;
 IFeatureClassName pFeatureClassName = (IFeatureClassName)pName;
 IMetadata pMetadata = (IMetadata)pFeatureClassName;
 IMetadataViewWindow2 pMetadataViewWindow = (IMetadataViewWindow2) new MetadataViewWindow();
 pMetadataViewWindow.Application = ArcMap.Application;
 pMetadataViewWindow.Layer = layer;
 pMetadataViewWindow.Metadata_2 = pMetadata.Metadata;
 pMetadataViewWindow.Show(true);
 }
answered Jun 16, 2016 at 21:14
2
  • Thanks for this it looks like the IMetadataViewWindow classes are what I am looking for. I'll test it and update. Commented Jun 17, 2016 at 12:32
  • I basically used the code from 'Get Dataset' down and it worked great thanks. Aside from my code being in c# the only difference was that since my layer isn't yet in the TOC so I define ILayer differently. Commented Jun 17, 2016 at 15:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.