1

I am writing addins in C#, and am trying to load an addin. I thought i had the solution, but it seems like the full code is not loaded.

The button is added to my toolbar, and code seems to run, too a point. Once i need to use the singleton extension of the child, it crashes.

The child addin will run by itself, with no issues.

Calling Addin (Parent):

public class ParentExten : Extension
{
 .....

/// <summary>
        ///
        /// </summary>
        protected override void OnStartup()
        {
            WireDocumentEvents();            
            // load other extensions:

            // Call FindExtension to load this just-in-time extension.  
            var ais =  ArcMap.Application.FindExtensionByName("ChildExtension");

        }

}

Child Addin: config.esriaddinx

<AddIn language="CLR4.5" library="name.dll" namespace="name">
    <ArcMap>
      <Extensions>
        <Extension id="childExtension" class="classname"  showInExtensionDialog="true" autoLoad="false" />
      </Extensions>
      <Commands >
        <Button  id="button_id" class="namspace.classname"  
                  image="Images\Layer.jpeg"  onDemand="true"/>

        <Tool id="tool_id" class="hiddenname" 
             category="Layer" image="Images\Layer.jpeg" onDemand="true" />
      </Commands>
    </ArcMap>
  </AddIn>

1 Answer 1

1

I came up with this solution by looking up the IExtensionManager/IExtensionConfig. The 'Child' extension is set to showInExtensionDialog="false" autoLoad="false"

Parent Extension: (called after IDocumentEvents_OpenDocumentEventHandler)

private bool LoadChildExtensions()
{          
   var child = ArcMap.Application.FindExtensionByName("ChildLayeExtension");
   var configext = child as IExtensionConfig;


   if(configext.State != esriExtensionState.esriESUnavailable)
   {
     configext.State = (configext.State == esriExtensionState.esriESEnabled) ? esriExtensionState.esriESDisabled : esriExtensionState.esriESEnabled;
   }
   else
   {
      ReportError(true, string.Format("ChildLayeExtension is {0}", configext.State.ToString()));
   }

   child.Startup(ArcMap.ThisApplication);
   return true;
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.