I am looking for a code example for executing the Geoprocessing tool "management.Delete". I need to delete esri GRIDs that are created during processing in Pro. I am not clear as to what parameter to pass. I have looked the tool help that references input data elements.
I have tried raster datasets, raster layers. When I pass a raster layer, the tool appears to work in that the GPResults.IsFailed property comes back false. However, the GRID still resides on disk as a folder name and has its component files still present.
I have run the tool interactively in Pro. It allows me to browse to the GRID, select it, and then run the command successfully.
I need to know what value to add to the parameters of the MakeValueArray as well as any syntax requirements.
Any assistance would be greatly appreciated.
the proper parameter would be a raster dataset... with the caveat that the raster can't be open or used by 'anything', hence it can't be a layer in ArcMap, even sketchy time if Windows explorer is touching it
Thanks Dan for your input.
I have spent a good bit of time trying to make this behave. I have temporarily abandoned the effort to have the delete tool remove GRIDs that have been iteratively created during processing. Instead I have tried to run the tool programmatically against a GRID that has not been touched by the Pro Session.
I have tried the rater dataset as a parameter. The GPResults object IsFailed shows false. However, when I look at the rest of the parameters of the Results.Messages, it indicates that the GRID I am after does not exist, it appears to ignore the _connectionPath property of the raster dataset. I checked this during a run and found it be correctly populated. The ugly screen shot below shows this.
When I execute the geoprocessing Delete tool, and examine the GResults, I see a warning message the GRID I am trying to delete does not exist. The Delete tool does not seem to navigate the rasterdataset and use the _connectionPath.
I have looked at the Delete tool and note that it does not call for any environment settings. I am generating the raster dataset directly from the directories, so the raster is never added to the Pro Session as a layer.
I believe I need to pass more to the ValueArrayList than just the raster dataset, but am not clear as to what.
var parameters = Geoprocessing.MakeValueArray(pBasRasDataSet);
var gpResults = await Geoprocessing.ExecuteToolAsync("management.Delete", parameters);
When I look at the tool in Pro, it only calls for one parameter. The following screen shot depicts this.
I guess the Input Data Element is expecting more than I am providing in my code attempt to execute the tool.
I am transitioning an ArcObjects application to Pro where I am able to remove GRIDS created during the ArcMap session.
Any input to resolve the error of my ways would be welcome.
The Environments settings is right beside the Parameters setting at the top. You specify them in there.
As for the grids, they are wickedly long convoluted paths. Can you on locally stored data in a simple folder? esri grids are finicky, so you might want to try adding a *.tif to the rasters you are outputting since esri has moved to those as the default raster format.
Thanks again for your input. I guess I am unclear regarding the Environments setting regarding the Delete tool. I did look at the Environments setting and it stated No Environments were necessary. Migrating to the .tif would be a bit arduous, but perhaps I will have to down that road.
It is a bit frustrating as the Pro interactive Delete tool doesn't struggle with any of it. Perhaps one of our friends from esri could enlighten.
Thanks again Dan. I know you are a strong contributor to the forum and I appreciate you taking the time.
When I pass a raster layer, the tool appears to work in that the GPResults.IsFailed property comes back false. However, the GRID still resides on disk as a folder name and has its component files still present.
Dan is right on, deleting a layer will only delete a layer not a dataset! An issue you may be running into is that if you try to delete a raster data while a layer pointing to it still exists, the delete operation cannot complete. The interactive delete is probably working because the app has code to delete the layer and then the dataset.
Hope this helps!
Thanks for responding Curtis. I appreciate your time.
I thought the dataset was the proper object from the beginning. I have written ArcObjects applications that allow this behavior through the dataset, when that didn't work in Pro, I started experimenting with other parameters.
As I mentioned, to test the Delete tool free from any sr.lock files associated with having the GRID in the Pro session as a layer, I created the dataset from disk:
I passed the raster dataset as a parameter to the tool and encounter the results posted above. So it seems, independent of any 'layer' intrusion, the tool does not navigate the raster dataset, based off the GPResults message . As the tool does not call for any environment parameters, I am not clear what else the it requires.
Thanks again for input.
Unfortunately, you're a bit outside my expertise as I have zero experience with Pro SDK and minimal with ArcObjects. In geoprocessing all tool parameters are converted with str() before the tool runs. Tool parameters in GP are always passed in string representation. This allows easy code patterns in arcpy like:
lyr = arcpy.MakeFeatureLayer("test.shp", "lyrTest") arcpy.SelectByAttribute_management(lyr, "", "FID < 20")
In the above example the result object lyr is converted "lyrTest" -- with str(): (str(lyr) == lyr.GetOutput(0) == "lyrTest") for SelectByAttribute.
It looks like above you were passing a pointer to an object (pBasRasDataSet) -- maybe you should be passing a path extracted off this object instead.
If this doesn't help I'm hoping someone that knows the Pro SDK will chime in.