internal static void Invoke(string tool) { UID uniqueId = new UIDClass(); uniqueId.Value = "esriGeoprocessingUI.ArcToolboxExtension"; var arcToolboxExtension = ArcMap.Application.FindExtensionByCLSID(uniqueId) as IArcToolboxExtension; if (arcToolboxExtension == null) return; IGPTool gpTool = null; try { gpTool = arcToolboxExtension.ArcToolbox.GetToolbyNameString(tool); } catch (COMException) { MessageBox.Show(@"Unable to find tool: " + tool + Environment.NewLine + @"in the system toolbox.", @"Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (gpTool == null) return; IGPToolCommandHelper gpCommandHelper = new GPToolCommandHelper(); gpCommandHelper.SetTool(gpTool); gpCommandHelper.Invoke(null); }
private static void Invoke(string workspace, string toolbox, string tool) { IWorkspaceFactory factory = new ToolboxWorkspaceFactoryClass(); var toolboxWorkspace = (IToolboxWorkspace)factory.OpenFromFile(workspace, 0); if (toolboxWorkspace == null) return; IGPToolbox gpToolbox = toolboxWorkspace.OpenToolbox(toolbox); if (gpToolbox == null) return; IGPTool gpTool = gpToolbox.OpenTool(tool); if (gpTool == null) return; IGPToolCommandHelper gpCommandHelper = new GPToolCommandHelper(); gpCommandHelper.SetTool(gpTool); gpCommandHelper.Invoke(null); }
private void runTool(System.String toolname) { try { IGPTool pGpt = getGPTool(toolname); //sample "TableToExcel" if (pGpt != null) { IGPToolCommandHelper pCommand = new GPToolCommandHelper(); pCommand.SetTool(pGpt); pCommand.Invoke(null); } } catch (Exception ex) { MessageBox.Show("Failed to run tool: " + toolname + Environment.NewLine + ex.Message); } }