There are two types of ActiveX/COM plugins:
- Out-Process:Runs The plugin runs as a separate .exe file.
- In-Process: Runs using Load and run the pluglin using the NETLOAD command.
Out-Process Active/COM Plugins
- Create a new C# or VB.NET project using the Visual Studio project Wizard( **minimum requirement .NET Framework v4.58).
One can either create Windows Form Application, Console Application, or Class Library. - From Solution Explorer, add references of to OdaX_xx.x.xx_xx*.dll dll and ARESC.exe from ARES Commander installation folder.
- You can add references by searching PCAD_AC_X and PCAD_DB_X from COM Assemblies.
- You can see the available NameSpaces, Class Methods, and Properties in each assembly using Object Browser.
Rename Program.cs to PluginCommands. This will change changes class Program to class PluginCommands as in the following example.
Code Block language c# theme RDark firstline 1 linenumbers true namespace SamplePlugins { class PluginCommands { static void Main(string[] args) { } } }
- There are two ways to work with an out-process plugin:
- Create a new Instance
- Attach with already running applicationthe debugger while the application is running
To create an Instance of AcadApplication, use PCAD_AC_X.
This call starts ARES Commander directly.Code Block language c# theme RDark firstline 1 linenumbers true using PCAD_AC_X; namespace SamplePlugins { class PluginCommands { static void Main(string[] args) { Application app = new AcadApplication(); } } }
If ARES Commander is already running, use a version dependent ProgIDs or an independent ProgIDs one as in the following example.
For Marshal, use System.Runtime.InteropServices.Code Block language c# theme RDark firstline 1 linenumbers true using PCAD_AC_X; using System.Runtime.InteropServices; namespace SamplePlugins { class PluginCommands { static void Main(string[] args) { AcadApplication app = (PCAD_AC_X.AcadApplication)Marshal.GetActiveObject("PCAD_AC_X.AcadApplication"); } } }
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
IAcadPreferencesDisplay AcadPref; AcadPref = app.Preferences.Display; int Size = AcadPref.CursorSize; |
Prompting For User Input
Utility functions
...
let you
...
request input from the user
...
and perform geometric calculations.
...
You can access Utility functions through the ActiveDocument object.
...
Various Utility functions prompt user for input. For example, GetInteger() allows integer input. Similar methods allow prompting for Angle, Distance, AngleFromAxis, and Keyword
...
.
For reference, see the following code.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
int promptInteger; //With prompting to user promptInteger = app.ActiveDocument.Utility.GetInteger("Enter an integer") //Without prompting to user promptInteger = app.ActiveDocument.Utility.GetInteger(); |
In-
...
Process Active/COM Plugins
- Create a new C# or VB.NET project using Visual Studio project Wizard( **minimum requirement .NET Framework v4.5)
- From Solution Explorer, add references of to OdaX_xx.x.xx_xx*.dll, ARESC.exe, and TD_Mgd_xx.x.xx_xx.dll from ARES Commander installation folder.
- You can see the available NameSpaces, Class Methods, and Properties in each assembly using Object Browser.
Rename Program.cs to PluginCommands. This will change changes class Program to class PluginCommands as in the following example:
Code Block language c# theme RDark firstline 1 linenumbers true namespace ActiveXCOMSample { public class PluginCommands { } }
Defining a command uses Runtime namespace to access the CommandMethod attribute and add adds a method with this attribute. See AnyFunctionName() in the following example.
The following example defines the MySampleCommand command.Code Block language c# theme RDark firstline 1 linenumbers true using Teigha.Runtime; namespace ActiveXCOMSample { public class PluginCommands { [CommandMethod("MySampleCommand")] public void AnyFunctionName() { } } }
Using a similar procedure, you can create all types of in-process pluginplugins.
- Building the sample project generates generates a dll or file named <YourProjectName.dll>
Running the NETLOAD Command
- Start ARES Commander.
- Type NETLOAD at the command prompt and press Enter. Navigate to PluginCommands.dll and load it.
The command window displays a confirmation message. - Run MySampleCommand which executes the AnyFunctionName method.
- Because Ares ARES Commander is already running, use GetActiveObject method instead of creating an instance of AcadApplication.
- For Marshal, use System.Runtime.InteropServices
Use the same procedure for accessing steps to access various ActiveX/COM objects and collections.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
using Teigha.Runtime; using PCAD_AC_X; using System.Runtime.InteropServices; namespace ActiveXCOMSample { public class PluginCommands { [CommandMethods("MySampleCommand")] public void AnyFunctionName() { IAcadApplication app = (IAcadApplication)Marshal.GetActiveObject("PCAD_AC_X.AcadApplication"); } } } |
Migrating AutoCAD® ActiveX PlugIn Application to ARES Commander
...