arcpy.conversion.ExportFeatures to vb.net

203
1
Jump to solution
a month ago
SigurdurGesr
New Contributor

 

Hi 

I was try to use convert arcpy.conversion.ExportFeatures to VB:NET
when I run the code nothing happened I see the Progress dialog then I don't get the shapefile


 

 

  count1 = int(arcpy.GetCount_management("LAYERNAME").getOutput(0)) 
if count1 > 0:
     #print('Layer has a selection')
        arcpy.conversion.ExportFeatures(
    in_features="LAYERNAME",
    out_features=r"C:\PATH\file.shp",
    where_clause="TYPE = 80",
    use_field_alias_as_name="NOT_USE_ALIAS",    
    sort_field=None
)
else:
    print('Layer has no selection')  

 

 

 

 
  Try


       Dim currentLayer = GetBasicFeaturLayer(layerpath)
       If currentLayer.ConnectionStatus = ConnectionStatus.Broken Then

       End If
       If currentLayer.SelectionCount = 0 Then

       Else

           Dim in_features = "LAYERNAME"
           Dim out_features = "C:\PATH\file.shp"
           Dim where_clause = "TYPE = 80"
           Dim use_field_alias_as_name = "NOT_USE_ALIAS"
           Dim sort_field = "None"

           Dim progDlg = New ProgressDialog("Export map" & vbCrLf & "Go get a coffee", "Cancel")
           progDlg.Show()
           Dim progsrc=New CancelableProgressorSource(progDlg)
           If Not System.IO.Directory.Exists(outpath) Then System.IO.Directory.CreateDirectory(outpath)
           Dim valueArray = Await QueuedTask.Run(Function()
                                                     Dim inlayers As List(Of String) = New List(Of String)()
                                                     inlayers.Add(layerpath)
                                                     Return Geoprocessing.MakeValueArray(inlayers, outpath, where_clause, use_field_alias_as_name, sort_field)
                                                 End Function)
           Dim flags As GPExecuteToolFlags = GPExecuteToolFlags.GPThread
           Dim gpResult As IGPResult = Await Geoprocessing.ExecuteToolAsync("conversion.ExportFeatures", valueArray, Nothing, progsrc.CancellationTokenSource.Token, Nothing, flags)

           progDlg.Hide()
           Return If(String.IsNullOrEmpty(gpResult.ReturnValue), $"Error in gp tool: {gpResult.ErrorMessages}", $"Ok: {gpResult.ReturnValue}")
       End If

   Catch ex As Exception
       MessageBox.Show(ex.Message)
   End Try
   

 

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Your shared code is not so accurate. Code below works:

    Protected async Overrides Sub OnClick()
        Try


            Dim currentLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType(Of FeatureLayer).FirstOrDefault

            If currentLayer.ConnectionStatus = ConnectionStatus.Broken Then

            End If
            If currentLayer.SelectionCount = 0 Then

            Else

                Dim out_features = "C:\PATH\file.shp"
                Dim where_clause = "TYPE = 80"
                Dim use_field_alias_as_name = "NOT_USE_ALIAS"
                Dim sort_field = "None"

                Dim progDlg = New ProgressDialog("Export map" & vbCrLf & "Go get a coffee", "Cancel")
                progDlg.Show()
                Dim progsrc=New CancelableProgressorSource(progDlg)

                Dim outpath = System.IO.Path.GetDirectoryName(out_features)


                If Not System.IO.Directory.Exists(outpath) Then System.IO.Directory.CreateDirectory(outpath)
                Dim valueArray = Await QueuedTask.Run(Function()
                                                          Return Geoprocessing.MakeValueArray(currentLayer, out_features, where_clause, use_field_alias_as_name, sort_field)
                                                      End Function)
                Dim flags As GPExecuteToolFlags = GPExecuteToolFlags.GPThread
                Dim gpResult As IGPResult = Await Geoprocessing.ExecuteToolAsync("conversion.ExportFeatures", valueArray, Nothing, progsrc.CancellationTokenSource.Token, Nothing, flags)

                progDlg.Hide()
                Dim val = If(String.IsNullOrEmpty(gpResult.ReturnValue), $"Error in gp tool: {gpResult.ErrorMessages}", $"Ok: {gpResult.ReturnValue}")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

View solution in original post

0 Kudos
1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

Your shared code is not so accurate. Code below works:

    Protected async Overrides Sub OnClick()
        Try


            Dim currentLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType(Of FeatureLayer).FirstOrDefault

            If currentLayer.ConnectionStatus = ConnectionStatus.Broken Then

            End If
            If currentLayer.SelectionCount = 0 Then

            Else

                Dim out_features = "C:\PATH\file.shp"
                Dim where_clause = "TYPE = 80"
                Dim use_field_alias_as_name = "NOT_USE_ALIAS"
                Dim sort_field = "None"

                Dim progDlg = New ProgressDialog("Export map" & vbCrLf & "Go get a coffee", "Cancel")
                progDlg.Show()
                Dim progsrc=New CancelableProgressorSource(progDlg)

                Dim outpath = System.IO.Path.GetDirectoryName(out_features)


                If Not System.IO.Directory.Exists(outpath) Then System.IO.Directory.CreateDirectory(outpath)
                Dim valueArray = Await QueuedTask.Run(Function()
                                                          Return Geoprocessing.MakeValueArray(currentLayer, out_features, where_clause, use_field_alias_as_name, sort_field)
                                                      End Function)
                Dim flags As GPExecuteToolFlags = GPExecuteToolFlags.GPThread
                Dim gpResult As IGPResult = Await Geoprocessing.ExecuteToolAsync("conversion.ExportFeatures", valueArray, Nothing, progsrc.CancellationTokenSource.Token, Nothing, flags)

                progDlg.Hide()
                Dim val = If(String.IsNullOrEmpty(gpResult.ReturnValue), $"Error in gp tool: {gpResult.ErrorMessages}", $"Ok: {gpResult.ReturnValue}")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
0 Kudos