Composable parts exporting a valid contract (ie.IExternalCallback, IExternalUserControl) can be made aware of ISwAddinBase as shown in the following code:
 public class SomeClass
    {
        private ISwAddinBase myOwner = null;

        [ImportingConstructor()]
        public MainMenu([Import] ISwAddinBase owner)
        {
            myOwner = owner;
           
        }
    }


The above is not true for methods invoked from a SolidWorks command or menu item. To get access to ISwAddinBase while inside of a callback method, you must use the following IExternalCallback implementation. The reason behind this is that the concrete type containing your callback methods is never instantiated. However, when the code generated type is built, a reference to ISwAddinBase is injected as a static, public field.
public ISwAddinBase OwnerAddin
        {
            get { return (ISwAddinBase)this.GetType().GetField("OwnerAddin").GetValue(this); }
        }

// This method is a callback from a command item
public void GafManagerCallback()
        {
            AddinManager manager = new AddinManager(OwnerAddin.compositionContainer);
            manager.ShowDialog();
        }

Last edited Jun 30, 2010 at 8:53 PM by fixitchris, version 10

Comments

No comments yet.