Add a tin to ArcMap using ArcObjects


This article contains a code sample that shows how to add a tin to ArcMap using VBA and ArcObjects


  1. Open ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Code in ThisDocument code module will only run in the current map document. To store the code in all map documents, open the code in the Normal.mxt ThisDocument code module.

  4. Paste the following code into the code module.

    Sub AddATin()
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pLayer As ITinLayer
    Dim pWSF As IWorkspaceFactory
    Dim pWS As ITinWorkspace
    Dim pTin As ITin
    Dim pDataset As IDataset

    'Open the tin workspace
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pWSF = New TinWorkspaceFactory
    Set pWS = pWSF.OpenFromFile("c:\testdata\tin", 0)
    Set pTin = pWS.OpenTin("testtin")

    'Add the tin to ArcMap
    Set pLayer = New TinLayer
    Set pLayer.Dataset = pTin
    Set pDataset = pTin
    pLayer.Name = pDataset.Name 'Name layer to match dataset
    pMap.AddLayer pLayer 'Add the tin layer to the map.
    End Sub

  5. Modify the workspace path and tin name to apply to your data.
  6. Close the Visual Basic Editor.
  7. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000004976

  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic