There are two types of ActiveX/COM plugins:
...
- Create a new C# or VB.NET project using the Visual Studio project Wizard( **minimum requirement .NET Framework v4.5).
One can either create Windows Form Application, Console Application or Class Library. - From Solution Explorer, add references of OdaX_x.xx_xx*.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 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 two ways to work with out process:
- Create a new Instance
- Attach with already running application
...
To create an Instance of AcadApplication
...
, use PCAD_AC_X.
This 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 or
...
independent ProgIDs 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"); } } }
Accessing Documents and Active Documents
From the application object
...
you can access collection of documents or active documents and
...
preferences.
...
The following code iterates through the document collection.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
foreach(AcadDocument Doc in app.Application.Documents) { Console.Writeline("\n" + Doc.Name); } |
...
The following code gets the active document.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
AcadDocument NewDrawing; NewDrawing = app.ActiveDocument; |
...
The following code accesses the display preferences.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
IAcadPreferencesDisplay AcadPref; AcadPref = app.Preferences.Display; int Size = AcadPref.CursorSize; |
...
- Rest procedure for accessing various ActiveX/COM objects and collections is same.
Migration of AutoCAD® ActiveX PlugIn Application to ARES Commander
...