+ Reply to Thread
Results 1 to 1 of 1

Thread: VB .Net : Layer Adds Ok But No Data .. then arcmap crashes

  1. #1
    Neil Sang
    Join Date
    Jan 2012
    Posts
    11
    Points
    4
    Answers Provided
    1


    0

    Default VB .Net : Layer Adds Ok But No Data .. then arcmap crashes

    Hi,

    I am trying to simply add a layer in programatically. The layer appears in ArcMap, but there is no data there in. If I try to look at layer properties, ArcMap crashes.

    I've tried both shape and Access workspacefactory , and various shape files in various paths (no spaces etc..) but the same problem. Refreshing the data doesn't make any difference.

    I can see from the featurelayer properties that the correct data has been found, with the correct number of fields. What am I doing wrong?

    Thanks

    Neil

    Private Sub AddShapefile(ByRef m_Application)
    Dim mapDoc As IMapDocument = m_Application.Document
    ' Create a ShapefileWorkspaceFactory object and
    ' open a shapefile folder. The path works with a standard 9.3 installation.
    Dim AccworkspaceFactory As IWorkspaceFactory = New AccessWorkspaceFactoryClass()
    Dim featureWorkspace As IFeatureWorkspace = TryCast(AccworkspaceFactory.OpenFromFile("C:\WindaWorkSpace\Data\WindaPGdb.mdb", 0), IFeatureWorkspace)


    ' Create a FeatureLayer and assign a shapefile to it.
    Dim featureLayer As IFeatureLayer = New FeatureLayerClass
    featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass("winda")
    Dim layer As ILayer = featureLayer
    layer.Name = featureLayer.FeatureClass.AliasName
    ' Add the layer to the focus map.
    Dim pMap As ESRI.ArcGIS.Carto.IMap = mapDoc.ActiveView.FocusMap
    pMap.AddLayer(featureLayer)
    mapDoc.ActiveView.Refresh()
    Dim t As Integer
    t = 1
    End Sub


    EDIT : Once again Neil Clemmens saves the day.. When automating from an external application you need to use the IObjectsFactory :

    http://help.arcgis.com/en/sdk/10.0/a...000001nn000000

    Given that most people must now be using VS 2010 or similar to develop, this should be written in big red letters the first page of the esri user help pages!
    Last edited by AnserGIS; 03-30-2012 at 01:18 AM. Reason: resolved

+ Reply to 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