VB.NET - Console Application Question

522
0
11-25-2013 10:12 PM
KeaganAllan
New Contributor III
Hi,

I am still relatively novice at VB.NET, and am in the process of trying to automate a system here whereby I set a scheduled task to run a process within an MXD.

From what I have researched, it seems a console application is the way forward.
Using VS Express 2010 I have started trialing a number of small Geoprocessing Tools, however I am falling down on Step 1.
I am trying to select all features within a shapefile called "lay" in a MXD called "Test".

I keep getting a HResult_EFAIL on the selection.
Please see an excerpt of the script below:

 Sub Main()
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)
        'ESRI License Initializer generated code.
        m_AOLicenseInitializer.InitializeApplication(New esriLicenseProductCode() {esriLicenseProductCode.esriLicenseProductCodeBasic}, _
        New esriLicenseExtensionCode() {})
        'ESRI License Initializer generated code.

        Dim docName As String = "C:\Temp\Test.mxd"

        Dim mapDoc As IMapDocument = New MapDocument
        If mapDoc.IsPresent(docName) Then
            mapDoc.Open(docName)
        End If
        Dim IActive As IActiveView
        IActive = mapDoc.ActiveView

        Dim map As IMap = mapDoc.ActiveView.FocusMap
        Dim pmxdoc As IMxDocument

        pmxdoc = m_pApp

        Dim pSelect As IFeatureSelection
        Dim player As IFeatureLayer
        Dim pFC As IFeatureClass

        Dim i As Integer
        Do Until i = map.LayerCount - 1
            
            If map.Layer(i).Name = "lay" Then

                player = map.Layer(i)

                Exit Do
            Else
            End If
            i = i + 1
        Loop
        MsgBox(player.Name)
        Dim pPlayer As IFeatureLayer
       
        pSelect = player
        ' pmxdoc = mapDoc.ActiveView.FocusMap.Layer(0)
        pSelect.SelectFeatures(Nothing, esriSelectionResultEnum.esriSelectionResultNew, False) ' <---------- HERE


I found this online and have been modifying or trying to modify it to get it to work and have not succeeded once.
Is there anything obvious in the code above that is wrong?
I am pretty confident this would work in a normal Add-In Button, but the console seems to be different?

Thanks

K

<EDIT>: If I could swear and curse on this forum I would. I have been fighting with this for days...only now has it occurred to me that I am developing this tool on a PC with an Advanced License for a PC with a Basic License.... My fault, I should have used: {esriLicenseProductCode.esriLicenseProductCodeAdvanced} ....

Oh well.

Thanks for reading.
0 Kudos
0 Replies