Creating the Plugin

AutoCAD Map 3D .NET API

 
Creating the Plugin
 
 
 
NoteTo ensure the plugin is loaded, place the DLL in the Plugins\DataConnect folder under the AutoCAD Map 3D installation folder. Plugins in this folder that follow the proper structure are loaded on demand. There is no need to run the netload command.

Using Visual Studio, create a new project. Add a UserControl to the project. The control will be embedded in the Data Connect dialog.

The plugin class must implement the IDataConnectConnectionPlugin interface. It also requires a DataConnectPluginAttribute with the FDO provider name. The provider name must match the name in providers.xml. For example:

[DataConnectPluginAttribute("Autodesk.Oracle.3.1")]
public partial class SampleProviderConnectUIPlugin
    : UserControl
    , IDataConnectConnectionPlugin
{

IDataConnectConnectionPlugin provides the necessary methods for AutoCAD Map 3D to interact with the control. It inherits 2 other interfaces: IDataConnectPlugin and IPlugin.

The implementation for IDataConnectPlugin can be simple, as follows. The IDataConnectPluginHost interface contains a single property, HostApplication, of type object. When attached, it contains a reference to the host application object, Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication.

// IDataConnectPlugin implementation
 
protected IDataConnectPluginHost _host;
protected string _providerName;
 
public void Attach(IDataConnectPluginHost host)
{
    _host = host;
}
 
public void Detach() { _host = null; }
 
public IDataConnectPluginHost Host
{
    get { return _host; }
}
 
public UserControl ClientControl
{
    get { return this; }
}

Similarly, the implementation for IPlugin needs methods to get and set properties. The properties are used to describe the plugin. They may be displayed to the user and should be localized. The Dependencies property is not currently used.

// IPlugin implementation
 
protected string title = "title";
protected string description = "description";
protected string company = "company";
protected string version = "3.0.0";
protected Type[] dependencies;
 
public string Title
{
  get { return title; }
  set { title = value; }
}
 
public string Description
{
  get { return description; }
  set { description = value; }
}
 
public string Company
{
  get { return company; }
  set { company = value; }
}
 
public string Version
{
  get { return version; }
  set { version = value; }
}
 
public Type[] Dependencies
{
  get { return dependencies; }
}

IDataConnectConnectionPlugin contains methods to get and set the connection parameters for the FDO provider, so the implementation depends on the requirements of the provider. For complete details about the methods, refer to the AutoCAD Map 3D .NET API Reference Supplement. Generally these methods will work with fields on the custom form.

The properties of IDataConnectConnectionPlugin return information about the connection parameters for the provider. These are used to open the FDO connection.

Property Description
ConnectionParameterNames A list of parameters for the provider.
ConnectionParametersValid Boolean. True if the current parameters are valid for the provider.
ProviderName The provider name.

The methods of IDataConnectConnectionPlugin get and set parameter values:

Method name Description
GetConnectionParameter() Returns the current value of a connection parameter.
SetConnectionParameter() Sets the value of a connection parameter. This should update the form field for the parameter.
Initialize() Called when the plugin first loads.
SetConnectionParametersToDefaults() Sets all connection parameters to default values.

There is also an event, ParameterValueChanged, which should fire when a parameter value changes. This event is required so the containing form is able to update the Connect button state based on the validity of the current parameter values.