These plug-ins are of two types
- Out-Process: Runs as a separate exe.
- In-Process: Using NETLOAD
Out-Process
- Create a new C# or VB.NET project using Visual Studio project Wizard( **minimum requirement .NET Framework v4.5)
- One can either create Windows Form Application, Console Application or Class Library.
- Add references from Solution Explore of OdaX_x.xx_xx*.dll and ARESC.exe by Browsing ARES installation folder.
- References can also be added by searching PCAD_AC_X and PCAD_DB_X from COM Assemblies.
- Developer can see available NameSpaces, Class Methods, Properties in each assembly using Object Browser.
- Rename Program.cs to PluginCommands, it will change class Program to class PluginCommands like below.
namespace SamplePlugins { class PluginCommands { static void Main(string[] args) { } } }
- There two ways to work with out process. Either create an new Instance or Attach with already running application.
- Creating an Instance of AcadApplication. Use PCAD_AC_X .
using PCAD_AC_X; namespace SamplePlugins { class PluginCommands { static void Main(string[] args) { Application app = new AcadApplication(); } } }
- This will Launch the Ares directly.
- If Ares is already running, use version dependent or Independent ProgIDs as Below.
- For Marshal use System.Runtime.InteropServices .
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 application object one can access collection of documents or active documents and Preferences.
- Following Code iterates through the document collection.
foreach(AcadDocument Doc in app.Application.Documents) { Console.Writeline("\n" + Doc.Name); }
- Following code gets the active document.
AcadDocument NewDrawing; NewDrawing = app.ActiveDocument;
- Following code accesses the display preferences.
IAcadPreferencesDisplay AcadPref; AcadPref = app.Preferences.Display; int Size = AcadPref.CursorSize;
Prompting For User
- Utility functions that allow you to request input from the user or perform geometric calculations.
- Utility can be accessed through ActiveDocument object. There are various functions in utility that prompts user to input. for example to input integer there is GetInteger(). Like this for prompting Angle, Distance, AngleFromAxis, Keyword, etc there is a corresponding method.
- See following code for the reference.
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
- Create a new C# or VB.NET project using Visual Studio project Wizard( **minimum requirement .NET Framework v4.5)
- Add references from Solution Explore of OdaX_x.xx_xx*.dll, ARESC.exe and TD_Mgd_x.xx_xx.dll by Browsing ARES installation folder.
- Developer can see available NameSpaces, Class Methods, Properties in each assembly using Object Browser.
- Rename Program.cs to PluginCommands, it will change class Program to class PluginCommands like below
namespace ActiveXCOMSample { public class PluginCommands { } }
- Defining a command use Runtime namespace to access CommandMethod method attribute as below and add a method i.e AnyFunctionName having this attribute. It define MySampleCommand command which can be executed on ARES Commandline.
using Teigha.Runtime; namespace ActiveXCOMSample { public class PluginCommands { [CommandMethod("MySampleCommand")] public void AnyFunctionName() { } } }
- The above procedure is similar to all type of in-process plugn.
- Build the sample project is will generate dll or <YourProjectName.dll>
- Run ARES and type NETLOAD on command line it will prompt to load the plug-in dll, browse PluginCommands.dll and Load, message of successful loading will appear on command line.
- Run MySampleCommand AnyFunctionName method will be executed.
- Now instead of creating instance of AcadApplication, we will use GetActiveObject method, because in this case Ares will already be running.
- For Marshal use System.Runtime.InteropServices
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"); } } }
- Rest procedure for accessing various ActiveX/COM objects and collections is same.
Migration of AutoCAD ActiveX PlugIn Application to ARES Commander
The ActiveX/COM applications running on AutoCAD platform can be easily migrated to ARES Commander by making minimal changes.
- Replace AutoCAD ActiveX/COM assemblies by ARES ActiveX/COM(OdaX_x.xx_xx and ARESC.exe) assemblies.
- Replace Autodesk.AutoCAD by Teigha in source code.
- Replace AutoCAD to PCAD_AC_X and AXDBLiB to PCAD_DB_X in source code.
That's all. Build your project and migration done.