...
Create a new .NET ARES project using the Visual Studio project creation Wizard( **minimum requirement .NET Framework v4.5)
From Solution Explore, add references of
ArgonMGD.dll
TD_SwigCoreMgd.dllTD_SwigDbMgd.dll
TG_SwigDbMgd.dll
TD_Mgd_x.xx_xx.dll from the ARES Commander installation folder.
You can see all available NameSpaces, Classes, Methods, and Properties in each assembly in the Object Browser.
Rename Class1.cs to PluginCommands.cs. This changes the class Class1 to class PluginCommands, as in the following example.
Defining a command uses Teigha.Runtime namespace to access CommandMethod method attribute and adds a method, such as AnyFunctionName 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.There is another way to define a command, Directly inherit from CFxCommand and add instance of this class to command stack by using Setup method it adds the command into the 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; return PCADGlobals.RTNORM; } class CFxCommandTest : TestCase { PluginCommands m_test; public CFxCommandTest() { } public override string Name() { return "CFxCommand"; } public override bool SetupTest() { m_test = new PluginCommands(); Teigha.Core.Globals.odedRegCmds().addCommand(m_test); return true; } public override bool Execute() { CFxDocument pFxDoc = PCADGlobals.FXAPI().GetFxDocument(); if (pFxDoc == null) return false; CFxCommandContext ctx = pFxDoc.GetFxCommandContext(); if (ctx == null) return false; Teigha.Core.Globals.odedRegCmds().executeCommand(m_test.globalName(), ctx); return true; } } } }
Build the sample project to generate PluginCommands.dll or <YourProjectName.dll>.
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 you can use Reactors like this:
Code Block |
---|
class ReactorTest { static DatabaseReactor _dbReactor; public static void OnDatabaseAttached(CFxDatabase db) { db.addReactor(_dbReactor); } public static void OnDatabaseDetached(CFxDatabase db) { db.removeReactor(_dbReactor); } } class DatabaseReactor : CFxDatabaseReactor { public override void objectAppended(OdDbDatabase pDb, OdDbObject pObject) { } public override void objectModified(OdDbDatabase pDb, OdDbObject pObject) { } public override void objectErased(OdDbDatabase pDb, OdDbObject pObject) { } public override void goodbye(OdDbDatabase pDb) { } } |