Saturday, 3 September 2016

arcgis 10.0 - List all active extensions with ArcObjects


I am building an ArcGIS 10 Addin that dumps out as much debug information about a system that I can get. I am currently trying to query which extensions are active in the ArcMap session. The following code is to query on the active ESRI extensions, but does not show the 3rd party extensions. Any ideas of what I need to do to get the information on 3rd party extensions?


public string Extensions

{
get
{
var aoi = new ESRI.ArcGIS.esriSystem.AoInitializeClass();
var extensionsEnum = aoi.GetProductExtensions(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
var licenseCode = extensionsEnum.Next();
var ret = "";
while(Convert.ToInt32(licenseCode) != -1)
{
if(aoi.IsExtensionCheckedOut(licenseCode))

ret += aoi.GetLicenseExtensionName(licenseCode) + ",";
licenseCode = extensionsEnum.Next();
}
return ret+Environment.NewLine;
}
}

Here is the working code:


public string Extensions
{

get
{
var extensionManager = (IExtensionManager) ArcMap.Application;

var ret = "";
for (int i = 0; i < extensionManager.ExtensionCount; i++)
{
var extension = extensionManager.Extension[i];
var config = extension as IExtensionConfig;
if(config == null || config.State == esriExtensionState.esriESEnabled)

ret += extension.Name + ",";
}

var jitExtensionManager = (IJITExtensionManager) ArcMap.Application;
for (int i = 0; i < jitExtensionManager.JITExtensionCount; i++ )
{
var extensionUid = jitExtensionManager.JITExtensionCLSID[i];
if(jitExtensionManager.IsLoaded(extensionUid))
{
var extension = ArcMap.Application.FindExtensionByCLSID(extensionUid);

var config = extension as IExtensionConfig;
if (config == null || config.State == esriExtensionState.esriESEnabled)
ret += extension.Name + ",";
}
}

ret = ret.Substring(0, ret.Length - 1);
return ret+Environment.NewLine;
}
}


Answer



Yes. Use the ExtensionManager class.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...