The following is a simple example of an OdEdCommand Subclass. When executed, this object
retrieves a string value from the passed in I/O object, and writes this string back out.
class SampleCmd : public OdStaticRxObject<OdEdCommand>
{
public:
const OdString localName() const { return globalName(); }
const OdString groupName() const { return "ODA Example Commands"; }
const OdString globalName() const { return OdString("SampleCommand"); }
// Body of the custom command.
void execute(OdEdCommandContext* pCmdCtx)
{
OdDbCommandContextPtr pDbCmdCtx(pCmdCtx); // downcast for database access
OdDbDatabasePtr pDb = pDbCmdCtx->database(); // Current database
OdEdUserIO* pIO = pDbCmdCtx->userIO();
OdString sKey = pIO->getString("Enter a value: ", "< default >");
pIO->putString(sKey + " was entered");
}
};
Custom commands can peform database operations, create new objects, query
for input and then perform operations based on that input, etc. See our ExCustObj_dll
sample project for sample commands that create custom objects based on input
from the user (these commands can be executed from within our OdaMfcAppDll sample
by choosing Tools/Load Applications and loading the TX module created by ExCustObj_dll).
Once the app is loaded, the commands can be accessed from Edit/Registered Commands.