+ Reply to Thread
Results 1 to 3 of 3

Thread: Remove layer from TOC depending on its path

  1. #1
    Priyanka Mehta
    Join Date
    Apr 2010
    Posts
    54
    Points
    1
    Answers Provided
    0


    0

    Default Remove layer from TOC depending on its path

    Hi all,
    I have like 2 layers in my TOC. both have exactly the SAME name. but both are in different locations.

    like : "C:\temp\Original.mdb\FD\RoadFeature"

    and another is "C:\Updated.mdb\FD\RoadFeature"

    Is there a way to remove only the "RoadFeature" feature class that is located in Original.mdb from TOC

    Thanks,
    Priyanka Mehta

  2. #2
    Alagappan AL
    Join Date
    Apr 2010
    Posts
    30
    Points
    0
    Answers Provided
    0


    0

    Default Removing the layer from TOC by comparing the path of the layer

    Hi,

    Hope the below code solves your problem, which loops through the layers in TOC, compares the path of each layer to the required layer path that is to be removed and then remove that layer from TOC.

    Public Overrides Sub OnClick()
    Try
    Dim pMxdoc As IMxDocument = m_application.Document
    Dim pMap As IMap = pMxdoc.FocusMap
    Dim pEnumLayer As IEnumLayer = pMap.Layers
    Dim pLayer As ILayer = pEnumLayer.Next
    While Not player Is Nothing
    Dim pFeatClass As IFeatureClass = CType(pLayer, IFeatureLayer).FeatureClass
    Dim pDataset As IDataset = CType(pFeatClass, IDataset)
    'obtaining the path of the layer in TOC
    Dim strPath As String = pDataset.Workspace.PathName
    'comparing the path of the layer with the required path to be removed
    If strPath = "C:\temp\Original.mdb" Then
    'if yes, remove the layer from TOC
    pMap.DeleteLayer(pLayer)
    Exit While
    End If
    pLayer = pEnumLayer.Next
    End While
    End Sub


    Regards,
    Alagappan

  3. #3
    Priyanka Mehta
    Join Date
    Apr 2010
    Posts
    54
    Points
    1
    Answers Provided
    0


    0

    Default

    Hey thanks a lot !.. It works well

    Thanks and Regards,
    Priyanka

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts