Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 7 Next »

There are two types of ActiveX/COM plugins:

  • Out-Process: Runs as a separate .exe file.
  • In-Process: Runs using the NETLOAD command.

Out-Process Active/COM Plugins

  1. 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.

  2. From Solution Explorer, add references of OdaX_x.xx_xx*.dll and ARESC.exe from ARES Commander installation folder.

  3. You can add references by searching PCAD_AC_X and PCAD_DB_X from COM Assemblies.

  4. You can see the available NameSpaces, Class Methods, and Properties in each assembly using Object Browser.

  5. Rename Program.cs to PluginCommands. This will change class Program to class PluginCommands as in the following example.

    namespace SamplePlugins
    {
    	class PluginCommands
    	{
    		static void Main(string[] args)
    		{
    		}
    	}
    }
  6. There two ways to work with out process:
    • Create a new Instance
    • Attach with already running application

  7. To create an Instance of AcadApplication, use PCAD_AC_X.
    This starts ARES Commander directly.

    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.

    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.

foreach(AcadDocument Doc in app.Application.Documents)
{
	Console.Writeline("\n" + Doc.Name);
}

The following code gets the active document.

AcadDocument NewDrawing;
NewDrawing = app.ActiveDocument;

The 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*.dllARESC.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 namespace by Teigha namespace in source code.
  • Replace AutoCAD to PCAD_AC_X and AXDBLiB to PCAD_DB_X in source code.





  • No labels