// get the model tool's parameter syntax from the model's helpstringinput_roads=@"C:\data\Input.gdb\PlanA_Roads";stringbuff_dist_field="Distance";// use values from a fieldstringinput_vegetation=@"C:\data\Input.gdb\vegtype";stringoutput_data=@"C:\data\Output.gdb\ClippedFC2";// the model name is ExtractVegetationstringtool_path=@"C:\data\MB\Models.tbx\ExtractVegetation";varargs= Geoprocessing.MakeValueArray(input_roads, buff_dist_field, input_vegetation, output_data);varresult= Geoprocessing.ExecuteToolAsync(tool_path, args);
stringinput_data=@"C:\data\data.gdb\Population";stringout_pdf=@"C:\temp\Reports.pdf";stringfield_name="INCOME";// use defaults for other parameters - no need to pass any valuevararguments= Geoprocessing.MakeValueArray(input_data, out_pdf, field_name);stringtoolpath=@"C:\data\WorkflowTools.tbx\MakeHistogram";
Geoprocessing.OpenToolDialog(toolpath, args);
Get Geoprocessing project items
vargpItems= CoreModule.CurrentProject.Items.OfType<GeoprocessingProjectItem>();// go through all the available toolboxesforeach(var gpItem in gpItems){varitemsInsideToolBox= gpItem.GetItems();// then for each toolbox list the tools insideforeach(var toolItem in itemsInsideToolBox){stringnewTool= String.Join(";",newstring[]{ toolItem.Path, toolItem.Name });// do something with the newTool// for example, add to a list to track or use them later}}
Stop a featureclass created with GP from automatically adding to the map
// However, settings in Pro App's Geoprocessing Options will override option set in code// for example, in Pro App's Options > Geoprocessing dialog, if you check 'Add output datasets to an open map'// then the output WILL BE added to history overriding settings in codevarGPresult= Geoprocessing.ExecuteToolAsync(tool_path, args,null,null,null, GPExecuteToolFlags.None);
GPExecuteToolFlags.AddToHistory will add the execution messages to Hisotry
// However, settings in Pro App's Geoprocessing Options will override option set in code// for example, if in Options > Geoprocessing dialog, if you uncheck 'Write geoprocessing operations to Geoprocessing History'// then the output will not be added to history. varresult2= Geoprocessing.ExecuteToolAsync(tool_path, args,null,null,null, GPExecuteToolFlags.AddToHistory);
Multi Ring Buffer
//The data referenced in this snippet can be downloaded from the arcgis-pro-sdk-community-samples repo//https://github.com/Esri/arcgis-pro-sdk-community-samplesprotectedasyncTask<string>CreateRings(EditingTemplatecurrentTemplate){varvalueArray=await QueuedTask.Run(()=>{return Geoprocessing.MakeValueArray(currentTemplate.MapMember.Name,@"C:\Data\FeatureTest\FeatureTest.gdb\Points_MultipleRingBuffer",newList<string>{"1000","2000"},"Meters","Distance","ALL","FULL");});IGPResultgpResult=await Geoprocessing.ExecuteToolAsync("Analysis.MultipleRingBuffer", valueArray);returnstring.IsNullOrEmpty(gpResult.ReturnValue)?$@"Error in gp tool: {gpResult.ErrorMessages}":$@"Ok: {gpResult.ReturnValue}";}
Non-blocking execution of a Geoprocessing tool
//The data referenced in this snippet can be downloaded from the arcgis-pro-sdk-community-samples repo//https://github.com/Esri/arcgis-pro-sdk-community-samplesprotectedasyncTask<string>NonBlockingExecuteGP(EditingTemplatecurrentTemplate){varvalueArray=await QueuedTask.Run(()=>{stringin_data=@"C:\tools\data.gdb\cities";stringcities_buff=@"E:\data\data.gdb\cities_2km";return Geoprocessing.MakeValueArray(in_data, cities_buff,"2000 Meters");});// to let the GP tool run asynchronously without blocking the main thread// use the GPThread option of GPExecuteToolFlasgs//GPExecuteToolFlagsflags= GPExecuteToolFlags.GPThread;// instruct the tool run non-blocking GPThreadIGPResultgpResult=await Geoprocessing.ExecuteToolAsync("Analysis.Buffer", valueArray,null,null,null, flags);returnstring.IsNullOrEmpty(gpResult.ReturnValue)?$@"Error in gp tool: {gpResult.ErrorMessages}":$@"Ok: {gpResult.ReturnValue}";}
How to pass parameter with multiple or complex input values
publicasyncTask<IGPResult>ExecuteSnap(){varenvironments= Geoprocessing.MakeEnvironmentArray(overwriteoutput:true);stringtoolName=@"Snap_edit";// Snap tool takes multiple inputs each of which has // Three (3) parts: a feature class or layer, a string value and a distance// Each part is separated by a semicolon - you can get example of sytax from the tool documentation pagevarsnapEnv=@"'C:/SnapProject/fgdb.gdb/line_1' END '2 Meters';'C:/SnapProject/fgdb.gdb/points_1' VERTEX '1 Meters';'C:/SnapProject/fgdb.gdb/otherline_1' END '20 Meters'";varparameters=await QueuedTask.Run(()=>{varinfc=@"C:/SnapProject/fgdb.gdb/poly_1";return Geoprocessing.MakeValueArray(infc, snapEnv);});GPExecuteToolFlagstokens= GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory;vargpResult=await Geoprocessing.ExecuteToolAsync(toolName, parameters, environments,null,null, flags: tokens);returngpResult;}