调用ArcToolBox里的Tool的三种方法

一.用 IArcToolboxExtension获得工具赋给pGPToolCommandHelper2,然后InvokeModal
  UID pUid = new UIDClass();
            pUid.Value = "esriGeoprocessingUI.ArcToolboxExtension";
            IArcToolboxExtension pATBExt = m_application.FindExtensionByCLSID(pUid) as IArcToolboxExtension;
            IGPTool pTool = pATBExt.ArcToolbox.GetToolbyNameString("ExportCAD");
  IGPToolCommandHelper2 pGPToolCommandHelper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2;
            pGPToolCommandHelper2.SetTool(pTool);
            Boolean pOk;
            IGPMessages pGPMessages;
            pGPToolCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);
二.用IWorkspaceFactory 根据工具的文件路径找ToolBoxes,Conversion Tools,然后ExportCAD工具,然后InvokeModal
IWorkspaceFactory pToolboxWorkspaceFactory = new ToolboxWorkspaceFactoryClass();
            IToolboxWorkspace pToolboxWorkspace = (IToolboxWorkspace)pToolboxWorkspaceFactory.OpenFromFile(@"D:\ArcGIS\ArcToolbox\Toolboxes", 0);
            IGPToolbox toolbox = (IGPToolbox)pToolboxWorkspace.OpenToolbox("Conversion Tools");
            IGPTool pTool = toolbox.OpenTool("ExportCAD");
            IGPToolCommandHelper2 pGPToolCommandHelper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2;
            //pGPToolCommandHelper2.SetTool(pTool);
            pGPToolCommandHelper2.SetToolByName("Conversion Tools", "ExportCAD");
            Boolean pOk;
            IGPMessages pGPMessages;
            pGPToolCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);
三.  直接用SetToolByName方法
IGPToolCommandHelper2 pGPToolCommandHelper2 = new GPToolCommandHelperClass() as IGPToolCommandHelper2;
            //pGPToolCommandHelper2.SetTool(pTool);
            pGPToolCommandHelper2.SetToolByName("Conversion Tools", "ExportCAD");
            Boolean pOk;
            IGPMessages pGPMessages;
            pGPToolCommandHelper2.InvokeModal(m_application.hWnd, null, out pOk, out pGPMessages);

你可能感兴趣的:(null,工具,tools)