1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Text;4 usingESRI.ArcGIS.esriSystem;5 usingESRI.ArcGIS.Geodatabase;6 usingESRI.ArcGIS.DataSourcesGDB;7 usingESRI.ArcGIS.Geoprocessing;8
9 namespaceesriTestConsole10 {11 classProgram12 {13 private static LicenseInitializer m_AOLicenseInitializer = newesriTestConsole.LicenseInitializer();14
15 [STAThread()]16 static void Main(string[] args)17 {18 //ESRI License Initializer generated code.//这是创建ArcGIS控制台项目时自动生成的
19 m_AOLicenseInitializer.InitializeApplication(newesriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine, esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB, esriLicenseProductCode.esriLicenseProductCodeBasic, esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced },20 newesriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork, esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst });21 //ESRI License Initializer generated code.
22 try
23 {24 ToolboxWorkspaceFactory toolBoxWSF = newToolboxWorkspaceFactoryClass();25 IToolboxWorkspace toolBoxWS = (IToolboxWorkspace)toolBoxWSF.OpenFromFile("F:\\Root\\Tools", 0);26 IGPToolbox toolbox = toolBoxWS.OpenToolbox("MagmaDistribution.tbx");27 //输出toolbox的路径信息
28 Console.WriteLine("IGPToolBox的PathName:" +toolbox.PathName);29 //从IGPToolbox的ToolNames属性获得toolbox里4个tool的名字。
30 ESRI.ArcGIS.Geoprocessing.IEnumGPToolName toolName =toolbox.ToolNames;31 IGPToolName gpn =toolName.Next();32 while (gpn != null)33 {//循环输出tool的名字
34 Console.WriteLine(gpn.DisplayName);35 gpn =toolName.Next();36 }37
38 }39 catch(Exception ex)40 {41 Console.WriteLine(ex.Message);42 }43 Do not make any call to ArcObjects after ShutDownApplication()
44 finally
45 {46 Console.WriteLine("输入任意字符退出程序:");47 Console.Read();48 m_AOLicenseInitializer.ShutdownApplication();49 }50 }51 }52 }