Select to view content in your preferred language

ExecuteToolAsync always failing

80
2
Monday
JacksonCarmack
New Contributor

I am attempting to write a method that will export features using the conversion.ExportFeatures geoprocessing tool. I am setting the parameters using the MakeValueArray and the envionments using the MakeEnvironmentArray. I then use the Geoprocessing.ExecuteToolAsync and store the result in resultGp. The tool always fails and I do not even get any meaningful error messages. The code is below and any help would be appreciated. Also the where clause used in the parameters looks something like this:

"valid_to = '2019-01-01 00:00:00' and CATEG IS NOT NULL".

I check the count for the where clause before calling the method as well and there are in fact records that exist using the where clause. 

 

public async Task<bool> ExportFeatures(FeatureClass inputFeatureClass, string outputFeatureClassName, string whereClause)
{
    Log.Log.MethodEntry();
    try
    {
        string fullPathName = _projectGeodatabase + $"\\{outputFeatureClassName}";

        var parameters = Geoprocessing.MakeValueArray(
            inputFeatureClass,
            fullPathName,
            whereClause
        );

        var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true, outputCoordinateSystem: inputFeatureClass.GetDefinition().GetSpatialReference());

        IGPResult resultGp = await Geoprocessing.ExecuteToolAsync(
            "conversion.ExportFeatures",
            parameters,
            environments,
            null,
            null,
            GPExecuteToolFlags.AddOutputsToMap
        );

        if (resultGp.IsFailed)
        {
            Log.Log.Error($"Failed to export features {resultGp.Messages.Select(x => x.Text)}");
            return false;
        }

        return true;
    }
    catch (Exception e)
    {
        Log.Log.Error($"{e}");
        return false;
    }
}

 

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

I would recommend to use ExecuteToolAsync method  with GPToolExecuteEventHandler parameter . More info you could find in another thread. It will allow you to get more information about input/output parameters validity.

Another one thing is your where clause. If you check your where clause in ArcGIS Pro Select By Attributes tool, you will find what query for date fields needs timestamp. Your query could be like this:

"valid_to = timestamp '2019-01-01 00:00:00' and CATEG IS NOT NULL"

Info here

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

It's difficult to decipher the parameters for some GP tools.  I usually run the GP Tool that I want to embed in my code by hand using the Geoprocessing toolbox.  After the tool completes successfully, I open the Geoprocessing History dockpane and right click on "history entry" and click on "Copy Python Command".   When you look at the Python Command it looks like this:

arcpy.conversion.ExportFeatures(
    in_features="MyPoints",
    out_features=r"C:\Data\ElectionData\ElectionData.gdb\MyPoints_ExportFeatures",
    where_clause="Y2008_D > 82868",
    use_field_alias_as_name="NOT_USE_ALIAS",
    field_mapping='Y2008_D "2008 Dem Votes" true true false 8 Double 0 0,First,#,MyPoints,Y2008_D,-1,-1;Y2008_R "2008 GOP Votes" true true false 8 Double 0 0,First,#,MyPoints,Y2008_R,-1,-1;ORIG_FID "ORIG_FID" true true false 4 Long 0 0,First,#,MyPoints,ORIG_FID,-1,-1',
    sort_field=None
)

You can now use the string format to construct you parameters.