Skip to content

Commit cc769fe

Browse files
authored
Merge pull request #14 from InventorCode/feat/interfacemembers
Add IPlugin interface members
2 parents 0339a3d + a598a12 commit cc769fe

File tree

14 files changed

+172
-128
lines changed

14 files changed

+172
-128
lines changed

GitVersion.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
next-version: 0.5.1
2+
major-version-bump-message: ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([\w\s]*\))?(!:|:.*\n\n((.+\n)+\n)?BREAKING CHANGE:\s.+)
3+
minor-version-bump-message: '^(feat)(\([\w\s]*\))?:'
4+
patch-version-bump-message: '^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\([\w\s]*\))?:'
15
branches: {}
26
ignore:
37
sha: []
48
merge-message-formats: {}
5-
major-version-bump-message: "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?(!:|:.*\\n\\n((.+\\n)+\\n)?BREAKING CHANGE:\\s.+)"
6-
minor-version-bump-message: "^(feat)(\\([\\w\\s]*\\))?:"
7-
patch-version-bump-message: "^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?:"

README.md

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ To help remedy this, we can decouple the tools/plugins from each other entirely.
3737
- `Execute()`: Executes whatever you want; accessible from the calling assembly.
3838
- `Activate(Inventor.Application inventorApplication, string ClientId, bool firstTime = true)`
3939
- `Deactivate()`: Deactivates the plugin
40+
- `Name`: Name of the plugin, as a string. Read-only.
41+
- `Version`: Version of the assembly, as a string. Read-only.
42+
- `ExecuteSettings`: an `Inventor.CommandControl` object that lets you activate settings from the HostPlugin.
4043

4144

4245
In the demo project below, when the addin is started:
@@ -66,114 +69,15 @@ This project contains a [Demo solution](https://github.com/InventorCode/Plugin/t
6669

6770
### AddinDemo
6871

69-
This is the addin class that implements the `Inventor.ApplicationAddInServer`.
70-
71-
```C#
72-
using Inventor;
73-
using Microsoft.Win32;
74-
using System;
75-
using System.Runtime.InteropServices;
76-
using System.Windows.Forms;
77-
using InventorCode.Plugin;
78-
using System.Collections.Generic;
79-
80-
namespace PluginHostDemo
81-
{
82-
[ProgId("PluginHostDemo.StandardAddinServer")]
83-
[GuidAttribute("7F39964A-C0DC-4BC7-948E-4B0A060256D1")]
84-
public class StandardAddInServer : Inventor.ApplicationAddInServer
85-
{
86-
private Inventor.Application m_inventorApplication;
87-
88-
// Create an instance of the PluginHost class in the package. This contains
89-
// the code to wire up the plugins dynamically.
90-
private PluginHost pluginHost = new PluginHost();
91-
92-
public StandardAddInServer()
93-
{
94-
// Here we will actually wire up the plugins by collecting classes with advertised
95-
// Plugin interfaces into our PluginHost object. If you need granular control, you
96-
// can manually compose these using MEF. See the IPluginHost class to get you started.
97-
pluginHost.ComposePlugins();
98-
}
99-
100-
101-
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
102-
{
103-
m_inventorApplication = addInSiteObject.Application;
104-
105-
// Here we'll activate the individual plugins...
106-
pluginHost.ActivateAll(m_inventorApplication, "7F39964A-C0DC-4BC7-948E-4B0A060256D1");
107-
}
108-
109-
public void Deactivate()
110-
{
111-
// And here we'll deactivate the individual plugins...
112-
pluginHost.DeactivateAll();
113-
114-
// Release objects.
115-
m_inventorApplication = null;
116-
117-
GC.Collect();
118-
GC.WaitForPendingFinalizers();
119-
}
120-
121-
public void ExecuteCommand(int commandID) { }
122-
123-
public object Automation { get => null; }
124-
}
125-
}
126-
```
127-
128-
---
72+
This is the addin class that implements the `Inventor.ApplicationAddInServer`. It acts as the puppet master that loads the plugins via the PluginHost class. Please find the code [here](https://github.com/InventorCode/Plugin/blob/master/demo/PluginHostDemo/PluginHostDemo.csproj).
12973

13074
### PluginExample
13175

132-
As for the individual tools/plugins... the demo code for a single plugin is included below. Think of this as a mini-addin; you can do just about anything here that you would in a full fledged addin: add event handlers, buttons, commands, ribbon interfaces, etc.
133-
134-
1. For this to work wou will need to add an assembly reference `System.ComponentModel.Composition`, and
135-
1. install the `InventorCode.Plugin` nuget package
136-
137-
```C#
138-
using Inventor;
139-
using Microsoft.Win32;
140-
using System;
141-
using System.Runtime.Interop;
142-
using System.Windows.Forms;
143-
using InventorCode.Plugin;
144-
using System.ComponentModel.Composition;
145-
146-
namespace PluginDemo
147-
{
148-
//This attribute is required! It is what PluginHost uses to find this plugin.
149-
[Export(typeof(IPlugin))]
150-
// Implement the Plugin Interface
151-
public class Main : IPlugin
152-
{
153-
154-
private Inventor.Application _inventorApplication;
155-
private string _clientId;
156-
157-
private DockableWindow dockableWindow;
158-
public void Activate(Inventor.Application InventorApplication, string ClientId, bool firstTime = true)
159-
{
160-
_inventorApplication = InventorApplication;
161-
_clientId = ClientId;
162-
163-
//Create dockable window
164-
dockableWindow = _inventorApplication.UserInterfaceManager.DockableWindows.Add(ClientId,
165-
"dockable_window.StandardAddInServer.dockableWindow", "PluginDemo");
166-
dockableWindow.ShowVisibilityCheckBox = true;
167-
}
168-
169-
public void Deactivate()
170-
{
171-
_inventorApplication = null;
172-
}
173-
174-
public void Execute()
175-
{
176-
}
177-
}
178-
}
179-
```
76+
As for the individual tools/plugins... the demo code for a single plugin is included below. Think of this as a mini-addin; you can do just about anything here that you would in a full fledged addin: add event handlers, buttons, commands, ribbon interfaces, etc. Please find the demo code [here](https://github.com/InventorCode/Plugin/blob/master/demo/PluginDemo/main.cs).
77+
78+
## Plugin and PluginHost templates
79+
80+
You can find templates for the Plugin and HostPlugin implementations in the following `dotnet new` [template pack](https://github.com/InventorCode/inventor-addin-templates).
81+
82+
- `inv-pluginhost` template creates a bare-bones addin implementation that utilizes the InventorCode.Plugin package.
83+
- `inv-plugin` template creates a minimal IPlugin implementation as a new project.

demo/PluginDemo/PluginDemo.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<AssemblyName>PluginDemo</AssemblyName>
1010
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1111
<Authors>Matthew D. Jordan</Authors>
12+
<Version>0.1.0</Version>
1213
<Company></Company>
1314
<Product></Product>
14-
<Description></Description>
15+
<Description>This is a description.</Description>
1516
<Copyright></Copyright>
1617
</PropertyGroup>
1718

@@ -29,14 +30,16 @@
2930
</PropertyGroup>
3031

3132
<ItemGroup>
32-
<PackageReference Include="InventorCode.Plugin" Version="0.4.2" />
33+
<PackageReference Include="InventorCode.Plugin" Version="0.6.0" />
3334
</ItemGroup>
3435

3536
<ItemGroup>
3637
<Reference Include="Autodesk.Inventor.Interop">
3738
<HintPath>..\..\..\..\..\..\..\..\Program Files\Autodesk\Inventor 2021\Bin\Public Assemblies\Autodesk.Inventor.Interop.dll</HintPath>
3839
</Reference>
39-
<Reference Include="System.ComponentModel.Composition" />
40+
<Reference Include="System.ComponentModel.Composition">
41+
<Private>true</Private>
42+
</Reference>
4043
<Reference Include="System.Windows.Forms" />
4144
</ItemGroup>
4245

demo/PluginDemo/main.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Inventor;
2-
using Microsoft.Win32;
3-
using System;
4-
using System.Runtime.InteropServices;
5-
using System.Windows.Forms;
62
using InventorCode.Plugin;
3+
using System;
74
using System.ComponentModel.Composition;
5+
using System.Reflection;
6+
using System.Windows.Forms;
87

98
namespace PluginDemo
109
{
@@ -28,7 +27,7 @@ public void Activate(Inventor.Application InventorApplication, string ClientId,
2827
{
2928
_inventorApplication = InventorApplication;
3029
_clientId = ClientId;
31-
MessageBox.Show("PluginDemo Loaded.");
30+
MessageBox.Show("External PluginDemo Loaded, with " + Name + " ver: " + Version);
3231
}
3332

3433
public void Deactivate()
@@ -39,5 +38,20 @@ public void Deactivate()
3938
public void Execute()
4039
{
4140
}
41+
42+
#region Properties
43+
44+
//Provides a place to implement a settings command from the PluginHost
45+
public CommandControl ExecuteSettings { get; set; }
46+
47+
// Provides the name of your plugin. Typically this would be set to return the
48+
// assembly name as shown below...
49+
public string Name { get => Assembly.GetExecutingAssembly().GetName().Name; }
50+
51+
// Provides the version of your plugin. Typically this would be set to return the
52+
// assembly version as shown below...
53+
public string Version { get => Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
54+
55+
#endregion Properties
4256
}
43-
}
57+
}

demo/PluginHostDemo/EmbeddedPluginDemo.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using InventorCode.Plugin;
22
using System.ComponentModel.Composition;
3+
using System.Reflection;
34
using System.Windows.Forms;
45

56
namespace PluginHostDemo
@@ -14,7 +15,7 @@ public void Activate(Inventor.Application InventorApplication, string ClientId,
1415
{
1516
_inventorApplication = InventorApplication;
1617
_clientId = ClientId;
17-
MessageBox.Show("EmbeddedPluginDemo Loaded.");
18+
MessageBox.Show("EmbeddedPluginDemo Loaded with " + Name + " ver: " + Version);
1819
}
1920

2021
public void Deactivate()
@@ -25,5 +26,11 @@ public void Deactivate()
2526
public void Execute()
2627
{
2728
}
29+
30+
public Inventor.CommandControl ExecuteSettings { get; set; }
31+
32+
public string Name { get => Assembly.GetExecutingAssembly().GetName().Name; }
33+
34+
public string Version { get => Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
2835
}
2936
}

demo/PluginHostDemo/PluginHostDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</PropertyGroup>
3232

3333
<ItemGroup>
34-
<PackageReference Include="InventorCode.Plugin" Version="0.4.2" />
34+
<PackageReference Include="InventorCode.Plugin" Version="0.6.0" />
3535
</ItemGroup>
3636

3737
<ItemGroup>

nuget-build-script.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
nuget pack
2-
nuget push InventorCode.Plugin.0.4.1.nupkg -Source https://api.nuget.org/v3/index.json
2+
nuget push InventorCode.Plugin.0.6.0.nupkg -Source https://api.nuget.org/v3/index.json

src/IPlugin.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,39 @@
22
{
33
public interface IPlugin
44
{
5+
/// <summary>
6+
/// Executes code that the user chooses.
7+
/// </summary>
58
void Execute();
69

10+
/// <summary>
11+
/// Activates the plugin, acts as the plugin's entry point. Synonymous with the
12+
/// Inventor.StandardAddinServer.Activate() method.
13+
/// </summary>
14+
/// <param name="inventorApplication">Inventor.Application object</param>
15+
/// <param name="ClientId">The addin's string GUID.</param>
16+
/// <param name="firstTime">Optional boolean value. Not currently used.</param>
717
void Activate(Inventor.Application inventorApplication, string ClientId, bool firstTime = true);
818

19+
/// <summary>
20+
/// Deactivates the plugin, acts as the plugin's finalize/cleanup method.
21+
/// Synonymous with the Inventor.StandardAddinServer.Activate() method.
22+
/// </summary>
923
void Deactivate();
24+
25+
/// <summary>
26+
/// Provides the ability to add a settings ui accessible from the PluginHost.
27+
/// </summary>
28+
Inventor.CommandControl ExecuteSettings { get; set; }
29+
30+
/// <summary>
31+
/// Provides the name of the plugin.
32+
/// </summary>
33+
string Name { get;}
34+
35+
/// <summary>
36+
/// Provides the version number of the plugin.
37+
/// </summary>
38+
string Version { get; }
1039
}
11-
}
40+
}

src/Plugin.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
<PropertyGroup>
2929
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
3030
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
31-
<Version>0.4.2</Version>
31+
<Version>0.6.0</Version>
32+
<PackageVersion>0.6.0</PackageVersion>
3233
<PackageProjectUrl></PackageProjectUrl>
3334
<PackageIcon>icon.png</PackageIcon>
3435
<RepositoryUrl>https://github.com/InventorCode/Plugin</RepositoryUrl>
35-
<AssemblyVersion>0.4.2.0</AssemblyVersion>
36+
<AssemblyVersion>0.6.0.0</AssemblyVersion>
3637
<PackageLicenseFile>LICENSE</PackageLicenseFile>
3738
</PropertyGroup>
3839

0 commit comments

Comments
 (0)