External User Controls

The Generic Addin Framework allows you to create user controls in a separate library. This allows for a more modular design (mef.codeplex.com). After the external control library is compiled, the DLL and TLB files must be placed in the same folder as SwAddinBase and SwAddinHelpers DLLs. When SolidWorks loads the Generic Addin Framework, it imports any types tagged with [Export(typeof(IExternalUserControl))] attribute. The IExternalUserControl interface acts as a proxy, passing the external control type as a dynamic type to the Generic Addin Framework.
Task Pane Control Template
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SwAddinHelpers.Base;
using SwAddinHelpers.Contracts;
using SwAddinHelpers.Attributes;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Design;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;

namespace ExternalTaskPaneControl
{
    [ComVisible(true)]
    [ProgId(PROGID)]
    [Export(typeof(IExternalUserControl))]
    [HostedAsTaskpane]
    public class Class1: TaskPaneControlBase, IExternalUserControl
    {
        public const string PROGID = "SwExternalControls.ExternalTaskPaneControl1";

        public Class1()
        {
            InitializeComponent();
        }

        public dynamic ExternalUserControl
        {
            get { return this; }
        }

        [SinkMethod(SwAddinHelpers.Sinks.enumEventSink.SW_ActiveModelDocChangeNotify,true)]
        public void SomeMethodToFire(object sender, EventArgs e)
        {

        }
    }
}

Last edited Jun 17, 2010 at 11:45 PM by fixitchris, version 4

Comments

No comments yet.