|
![]() |
Attribute that declares a plugin implements a particular interface or behaviours.
Namespace: Autodesk.Navisworks.Api.Plugins
Assembly: Autodesk.Navisworks.Api (in Autodesk.Navisworks.Api.dll)
Syntax
Visual Basic |
---|
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := True)> _ Public NotInheritable Class InterfaceAttribute _ Inherits Attribute |
C# |
---|
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true)] public sealed class InterfaceAttribute : Attribute |
Visual C++ |
---|
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple = true)] public ref class InterfaceAttribute sealed : public Attribute |
Remarks
This attribute can be applied to any plugin. This attribute declares a plugin implements a particular interface or behaviours. This does not imply any specific .NET interface.
This attribute can also be used to group a collection of plugins, the plugins assigned the same InterfaceAttribute can be found using Application.Plugins.FindInterfaces. Which can be particularly useful for grouping CustomPlugins.
Examples

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows.Forms; using System.Text; using Autodesk.Navisworks.Api.Controls; namespace VehicleAddin { [Plugin("VehiclePlugin", "ADSK")] //standard Plugin attribute [AddInPlugin(AddInLocation.AddIn, CallCanExecute = CallCanExecute.Always, LoadForCanExecute = false)] public class VehicleAddin : AddInPlugin { //When called this searches all the plugins for the attribute defined interface //then displays a message box with the plugin details public override int Execute(params string[] parameters) { //load the bike plugin PluginRecord bikePluginRecord = Autodesk.Navisworks.Api.Application.Plugins.FindPlugin("BikePlugin.ADSK"); if (bikePluginRecord != null) { if (!bikePluginRecord.IsLoaded) { bikePluginRecord.LoadPlugin(); } } StringBuilder output = new StringBuilder(); output.AppendLine("The following 'Vehicles.ADSK' interfaces were found:"); foreach (PluginRecord pr in Autodesk.Navisworks.Api.Application.Plugins.FindInterfaces("Vehicles.ADSK")) { output.Append("DisplayName="); output.Append(pr.DisplayName); output.Append(", IsLoaded="); output.Append(pr.IsLoaded); if (pr.IsLoaded && pr.LoadedPlugin is VehiclePlugins.VehiclePlugin) { output.Append(", Vehicle is "); output.Append((pr.LoadedPlugin as VehiclePlugins.VehiclePlugin).VehicleType); } output.AppendLine(); } MessageBox.Show(output.ToString()); return 0; } } } namespace VehiclePlugins { [Plugin("VehiclePlugin", "ADSK")] //standard Plugin attribute [Interface("Vehicles", "ADSK")] //All the vehicles implement the same interface so they can be easily searched for public abstract class VehiclePlugin : CustomPlugin { abstract public string VehicleType { get; } } [Plugin("CarPlugin", "ADSK")] //standard Plugin attribute [Interface("Vehicles", "ADSK")] //All the vehicles implement the same interface so they can be easily searched for) public class CarPlugin : VehiclePlugin { public override string VehicleType { get { return "a car"; } } } [Plugin("BikePlugin", "ADSK")] //standard Plugin attribute [Interface("Vehicles", "ADSK")] //All the vehicles implement the same interface so they can be easily searched for public class BikePlugin : VehiclePlugin { public override string VehicleType { get { return "a bike"; } } } [Plugin("TruckPlugin", "ADSK")] //standard Plugin attribute [Interface("Vehicles", "ADSK")] //All the vehicles identify with the same interface so they can be easily searched for public class TruckPlugin : VehiclePlugin { public override string VehicleType { get { return "a truck"; } } } }