Skip to end of metadata
Go to start of metadata

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

Compare with Current View Page History

« Previous Version 11 Next »

ARES Commander provides .NET API which lets you author third party Plugin Software for ARES Commander.

Supported API Sets 

ARES Commander supports 3 API sets which can be used independently.

  1. .NET Classic API
  2. ARES COM API
  3. CFx .NET (SWIG generated .NET API version of ARES C++ SDK)
API Assembly NamesNature of PluginLoading Mechanism
NET Classic API

TD_Mgd_x.xx_xx.dll

FxCoreMgd_x.xx_xx.dll

In-processUse NETLOAD command

ARES COM API

ARESC.exe

OdaX_x.xx_xx.dll

TD_Mgd_x.xx_xx.dll(For In-process plugin only)

In-process

Out-process

  •  In-process-Use NETLOAD command
  • Out-rocess-  Runs as a separated EXE

CFx .NET

ArgonMGD.dll

TD_SwigCoreMgd.dll

TD_SwigDbMgd.dll

TG_SwigDbMgd.dll

TD_Mgd_x.xx_xx.dll

In-processUse NETLOAD command

.NET Classic Plugin:

  • 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 TD_Mgd_x.xx_xx*.dll and FxCoreMgd_x.xx_xx.dll by Browsing ARES installation folder.
    • Developer can see available NameSpaces,Classes,Methods, Properties in each assembly using Object Browser

                 





  • Rename Class1.cs tp PluginCommands.cs it will change class Class1 to class PluginCommands like below.


  • Defining a command use Teigha.Runtime namespace to access CommandMethod method atrribute as below and add a method i.e AnyFunctionName having this attribute. It define MySampleCommand command which can be executed on ARES Commandline.
  •  
  • The above procedure is similar to all type of in-process plugn.
  • Build the sample project is will generate PluginCommans.dll or <YourProjectName.dll>
  • Run ARES and type NETLOAD on command line it will prompt to load the plugin dll, browse PluginCommands.dll and Load, message of successful loading will appear on command line.
  • Run MySampleCommand AnyFunctionName method will be executed. 

Accessing Application Object

Accessing Documents and ActiveDocument

From application object one can access document manager, Document Manager has peroperties and Methods by which one can access active document and also can add new document or open existing drawings.

 


Promping for User input 

For user IO Editor class is responsible, one can get it from Document and all related class for UserIO are available in Teigha.EditorInput namespace.


            Document activeDocument = docManager.MdiActiveDocument;
            Editor ed = activeDocument.Editor;

            PromptIntegerOptions op = new PromptIntegerOptions("Input a positive integer");
            op.AllowNegative = false;
            PromptIntegerResult res =(PromptIntegerResult) ed.DoPrompt(op);
            if( res.Status == PromptStatus.OK)
            {
                int retVal = res.Value;
            }

Creating .NET Extension Application

.NETExtension Application allow user to run their code while loading the plugin.i.e when plugin is loaded it want to add some entries in Ribbon or want to show some UI palatte in ARES Commander then creating the extension application is the right choice. But it is optional and totally depend upon the requirement.


To make Plugin as Extension Application one has add a class into project and this class has to implement IExtensionApplication interface and each plugin can have only one class of such type.

public void Initialize() get called when this plugin loaded via NETLOAD command and Terminate one this plugin unloaded by the System.


Defining .NET LispFunction

Third party can define .NET methods which is usable in LISP, below example defining lisptest function using LispFunction Method attribute this funcion is callable by LISP script as 

(setq x (lisptest "Text created by .NET lisp function" 1.0 '(10 10 0)))


        //Method attribute to define lisp callable function 'LispTest' 
        //i.e (setq x (lisptest "Text created by .NET lisp function" 1.0 '(10 10 0)))
        [LispFunction("lisptest")]
        public ResultBuffer DoIt(ResultBuffer args)
        {
            // Get the database of the active document.
            Database db = HostApplicationServices.WorkingDatabase;
            TypedValue[] argsVal = new TypedValue[3];
            if (args != null)
            {
                argsVal = args.AsArray();
            }
            else
            {
                argsVal[0] = new TypedValue((int)LispDataType.Text, "Default Text");
                argsVal[1] = new TypedValue((int)LispDataType.Double, .2);
                argsVal[1] = new TypedValue((int)LispDataType.Point3d, new Point3d(0, 0, 0));
            }
            // Set up transaction manager.
            Teigha.DatabaseServices.TransactionManager tm = db.TransactionManager;
            using (Transaction tr = tm.StartTransaction())
            {
                try
                {
                    Point3d pPosition = new Point3d(0, 0, 0);

                    // Create a new MText object and set properties.
                    DBText pText = new DBText();
                    pText.TextString = (String)argsVal[0].Value;
                    pText.Height = Convert.ToDouble(argsVal[1].Value);
                    pText.Position = (Point3d)argsVal[2].Value;

                    // Get model space to add the MText object.
                    BlockTable pBlockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                    BlockTableRecord pModelSpace = (BlockTableRecord)tr.GetObject(pBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    // Add the object to the model space.
                    ObjectId id = pModelSpace.AppendEntity(pText);
                    tr.AddNewlyCreatedDBObject(pText, true);

                    // Commit changes to database.
                    tr.Commit();
                    //return created text entity to lisp
                    return new ResultBuffer(new TypedValue((int)LispDataType.ObjectId, id));
                }
                finally
                {
                    // delete tr , managed by c# with garbage collection
                }

            }
        }

Migration of AutoCAD .NET Classic Application to ARES Commander

The .NET applications running on AutoCAD platform can be easily migrated to ARES Commander by making minimal changes.

  • Replace AutoCAD .NET assemblies by ARES .NET assemblies.
  • Replace Autodesk.AutoCAD by Teigha in source code.

That's all. Build your project and  migration done.


Advance Migration

If you don't want to maintain separate source code for AutoCAD and ARES then some extra steps are required, single project with 2 build configuration will solve the issue.

Step 1: Create new build configuration for both AutoCAD and ARES

 

Step 2: Using project Properties select all configurations one by one and define Symbol “AutoCAD” or “ARES” for corresponding configurations.

 

i.e For AutoCAD_Release configuration

 

and For ARES_Release

 

 Step 3: Add Conditional reference assemblies to the project using Symbols, Modify csproj file manually in text editor to add condition as below for all references.


<ItemGroup>

    <Reference Include="accoremgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\accoremgd.dll</HintPath>

    </Reference>

    <Reference Include="acdbmgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\acdbmgd.dll</HintPath>

    </Reference>

    <Reference Include="acmgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\acmgd.dll</HintPath>

    </Reference>

    <Reference Include="FxCoreMgd_4.03_14" Condition="$(DefineConstants.Contains('ARES'))">

      <HintPath>C:\Program Files\Graebert GmbH\ARES Commander 2018\BIN\FxCoreMgd_4.03_14.dll</HintPath>

    </Reference>

    <Reference Include="TD_Mgd_4.03_14" Condition="$(DefineConstants.Contains('ARES'))">

      <HintPath>C:\Program Files\Graebert GmbH\ARES Commander 2018\BIN\TD_Mgd_4.03_14.dll</HintPath>

    </Reference>

  </ItemGroup>

Step 4: Changes in source code add using directives for both the application conditionally

 

#if  AutoCAD

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using CADApp = Autodesk.AutoCAD;

#endif



#if  ARES

using Teigha.DatabaseServices;

using Teigha.Runtime;

using Teigha.Geometry;

using Teigha.ApplicationServices;

using Teigha.EditorInput;

using CADApp = Teigha;

#endif

and Replace Autodesk.AutoCAD to CADApp in *.cs source files which is defined conditional declaration above.

Step 5:

Specify separate Output directories for both the configurations.

Build both configurations one by one these builds will work with their respective applications.

 


  • No labels