Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ARES Commander supports three .NET API sets that you can use independently. Now here we’ll going to discuss about

This document describes CFx. NET(.NET ARES) and listed it’s lists the differences with .NET Classic API's coding.

  1. .NET Classic API

  2. ARES COM API

  3. CFx .NET (SWIG generated .NET API version of ARES C++ SDK)

    Here We differentiate Differences between .NET Classic and .NET ARES.

API

.NET Classic API

CFx .NET (.NET ARES)

Assembly Names

TD_Mgd_x.xx_xx.dll

FxCoreMgd_x.xx_xx.dll

ArgonMGD.dll

TD_SwigCoreMgd.dll

TD_SwigDbMgd.dll

TG_SwigDbMgd.dll

TD_Mgd_x.xx_xx.dll

Nature of Plugin

In-process

In-process

Loading Mechanism

Use the NETLOAD command

Use the NETLOAD command

Compatibility

AutoCAD compatible

ARES specific, not vailable available in other CADs

Access Document

Document document = Teigha.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

CFxDocument pFxDocument = PCADGlobals.FXAPI().GetFxDocument();
or
CFxDocument pFxDocument = PCADGlobals.GetFxSystemServices().GetFxDocumentManager().GetActiveDocument();

Access Database

Database db = document.Database;

CFxDatabase pFxDatabase = pFxDocument.GetFxDatabase();

Prompting For User Input

PromptIntegerOptions op = new PromptIntegerOptions("Input a positive integer");
PromptIntegerResult res = (PromptIntegerResult)ed.DoPrompt(op);

CFxUserIO pFxUserIO = pFxDocument.GetFxUserIO();

pFxUserIO.GetInt

Lisp Function Creation

Possible to create Lisp Functions. Using
LispFunction method attribute.

Cannot create Lisp Functions.

.NET Project Type

.NET Class Library

.NET Class Library

Notifications

via Events

via Reactor classes

Commands

Using command method Attribute

Directly inherit from CFxCommand and add instance of this class to command stack or Using command method Attribute

OR

Using command method Attribute

UI Controls

Ribbon and Palettes API available

Not available

...

  1. Create a new .NET ARES project using the Visual Studio project creation Wizard(  **minimum requirement .NET Framework v4.5)

    Image RemovedImage Added

  2. From Solution Explore, add references of of the following .dll:
    ArgonMGD.dll
    TD_SwigCoreMgd.dll

    TD_SwigDbMgd.dll

    TG_SwigDbMgd.dll

    TD_Mgd_x.xx_xx.dll from the ARES Commander installation folder.

    Image RemovedImage Added


    You can see all available NameSpaces, Classes, Methods, and Properties in each assembly in the Object Browser.

               

  3. Rename Class1.cs to PluginCommands.cs. This changes the class Class1 to class PluginCommands, as in the following example.

  4. Defining a command uses Teigha.Runtime namespace to access CommandMethod method attribute and adds a method, such as AnyFunctionName an AnyFunctionName method that has this attribute. The following example defines the MySampleCommand command which you can run later in ARES Commander, from the command prompt.
    You can define all types of in-process plugin using a similar procedure.

  5. You can also define a command directly inheriting from CFxCommand. Use the Setup method to add an instance of this class to the command stack.

    Code Block
    namespace SamplePlugin
    {
        public class PluginCommands : CFxCommand
        {
            public bool m_bExecuted;
            public PluginCommands()
            {
                m_bExecuted = false;
            }
            public override string globalName()
            {
                return "SampleCMD";
            }
            public override int Execute(CFxCommandContext pFxCmdCtx)
            {
                m_bExecuted = true;
                CFxDocument pFxDoc = PCADGlobals.FXAPI().GetFxDocument();
                if (pFxDoc == null)
                    return PCADGlobals.RTCAN;
                CFxCommandContext ctx = pFxDoc.GetFxCommandContext();
                if (ctx == null)
                    return PCADGlobals.RTCAN;
                PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n SampleCMD Command Executed"));
                return PCADGlobals.RTNORM;
            }
    
            class CFxCommandTest : IExtensionApplication
            {
                DocumentReactor docReactor;
    
                PluginCommands m_test;
                public CFxCommandTest()
                {
                    docReactor = new DocumentReactor();
                }
                public void Initialize()
                {
                    m_test = new PluginCommands();
                    Globals.odedRegCmds().addCommand(m_test);
                    PCADGlobals.GetFxSystemServices().GetFxDocumentManager().AddReactor(docReactor);
                }
                public void Terminate()
                {
                    Globals.odedRegCmds().removeCmd(m_test.groupName(), m_test.globalName());
                    PCADGlobals.GetFxSystemServices().GetFxDocumentManager().RemoveReactor(docReactor);
                }
            }
        }
    }
  6. Build the sample project to generate PluginCommands.dll or <YourProjectName.dll>.

  7. Start ARES Commander and type NETLOAD at the command prompt. Next, browse and load the plugin dll (PluginCommands.dll).
    The command window displays a confirmation message.

7 8. Run MySampleCommand, which executes the AnyFunctionName method. 

Accessing Documents

...

The CFxUserIO class controls the user input. All related classes for prompting on the command window are available in PCAD_DOT_NET.CFxUserIO namespace.

Code Block
CFxDocument Doc = PCADGlobals.FXAPI().GetFxDocument();
            CFxDatabase pDB = Doc.GetFxDatabase();

            CFxUserIO UserIO = Doc.GetFxUserIO();

            if (UserIO == null)
                return;
            
            CFxString prompt = UserIO.GetPrompt(new CFxString("Specify center point for circle or"));

            OdGePoint3d centerPoint = new OdGePoint3d();
            double radius = 5.0;

            int iResult = UserIO.GetPoint(prompt, new OdGePoint3d(), null, centerPoint);

            if (iResult == PCADGlobals.RTNORM)
            {
                using (OdDbCircle circle = OdDbCircle.createObject())
                {
                    circle.setDatabaseDefaults(pDB, true);
                    circle.setThickness(pDB.getTHICKNESS());
                    circle.setCenter(centerPoint);
                    circle.setRadius(radius);
                    
                    OdDbBlockTableRecord pBTR = (OdDbBlockTableRecord)pDB.GetActiveBlockId().openObject(Teigha.TD.OpenMode.kForWrite);
                    pBTR.appendOdDbEntity(circle);
                }
            }

Notifications(via Reactor Classes)

In .NET ARES there are Reactors

  1. CFxDocumentManagerReactor

  2. CFxDatabaseReactor

  3. CFxEditorReactor

  4. OdEdCommandStackReactor
    you can use Reactors like this:

Code Block
class DocumentReactor : CFxDocumentManagerReactor
    {
        public override void DocumentActivated(CFxDocument pActivatedDoc)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentActivated Fired"));
        }
        public override void DocumentActivationModified(bool bActivation)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentActivationModified Fired"));
        }
        public override void DocumentBecameCurrent(CFxDocument pDoc)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentBecameCurrent Fired"));
        }
        public override void DocumentCreateCanceled(CFxDocument pDocCreateCancelled)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentCreateCanceled Fired"));
        }
        public override void DocumentCreated(CFxDocument pDocCreating)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentCreated Fired"));
        }
        public override void DocumentCreateStarted(CFxDocument pDocCreating)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentCreateStarted Fired"));
        }
        public override void DocumentDestroyed(CFxDocument pDocToDestroyed, CFxString strFileName)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentDestroyed Fired"));
        }
        public override void DocumentPreOpen(CFxDocument pDoc, CFxString strFileName, int codePage, int openFlags)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentPreOpen Fired"));
        }
        public override void DocumentToBeActivated(CFxDocument pActivatingDoc)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentToBeActivated Fired"));
        }
        public override void DocumentToBeDeactivated(CFxDocument pDeActivatedDoc)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentToBeDeactivated Fired"));
        }
        public override void DocumentToBeDestroyed(CFxDocument pDocToDestroy)
        {
            PCADGlobals.GetFxSystemServices().WriteLine(new CFxString("\n Event DocumentToBeDestroyed Fired"));
        }
    }