Custom Models

1007
1
Jump to solution
05-11-2017 06:31 AM
JanakiGattu1
New Contributor III

Hi,

Can anyone help me in Executing the Custom Models developed in Model Builder.

I have designed few Models in Model Builder....Now It would like to add those models in ArcGIS Pro using ArcGIS Pro SDK...I am getting struck while initiating the Variables in the Pro SDK....##arcgisprosdk

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
NobbirAhmed
Esri Regular Contributor

Here is a way to do it - just remember to pass the whole path to the model tool including the Model's name. 

namespace TestModelRun
{
    internal class RunModelTool : Button
    {
        protected override async void OnClick()
        {
            await ExecuteModel();
        }

        public async Task<IGPResult> ExecuteModel()
        {

            // This is important - pass the path to toolbox and the model tool name as a combined string

            string tool_path = System.IO.Path.Combine(@"E:\sdk\MyProject27\MyProject27.tbx", "Model");

            // This tool takes only one parameter
            var parameters = Geoprocessing.MakeValueArray("E:\\data\\gdbs\\mexico.gdb\\mexicoCity_Proj");

            // Execute the tool

            IGPResult gp_result = await Geoprocessing.ExecuteToolAsync(tool_path, parameters);

            // display all GP messages
            Geoprocessing.ShowMessageBox(gp_result.Messages, "GP Messages", gp_result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);


            return gp_result;
        }
    }
}

For details visit the SDK help section for Geoprocessing at:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geoprocessing

View solution in original post

1 Reply
NobbirAhmed
Esri Regular Contributor

Here is a way to do it - just remember to pass the whole path to the model tool including the Model's name. 

namespace TestModelRun
{
    internal class RunModelTool : Button
    {
        protected override async void OnClick()
        {
            await ExecuteModel();
        }

        public async Task<IGPResult> ExecuteModel()
        {

            // This is important - pass the path to toolbox and the model tool name as a combined string

            string tool_path = System.IO.Path.Combine(@"E:\sdk\MyProject27\MyProject27.tbx", "Model");

            // This tool takes only one parameter
            var parameters = Geoprocessing.MakeValueArray("E:\\data\\gdbs\\mexico.gdb\\mexicoCity_Proj");

            // Execute the tool

            IGPResult gp_result = await Geoprocessing.ExecuteToolAsync(tool_path, parameters);

            // display all GP messages
            Geoprocessing.ShowMessageBox(gp_result.Messages, "GP Messages", gp_result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);


            return gp_result;
        }
    }
}

For details visit the SDK help section for Geoprocessing at:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geoprocessing