Interacting with AutoCAD

User interaction functions, such as acedGetPoint(), must be wrapped by a series of ObjectARX API calls when called from an Automation context. These ObjectARX functions save the AutoCAD “state” before the interaction, and restore it afterward. They also ensure that any other out-of-process Automation requests are rejected for the duration of your interaction. This prevents another Automation client from changing the command line or database while you are waiting for user input.

ObjectARX APIs to use when interacting with the user include the following functions:

Adesk::Boolean acedSetOLELock(int handle, int flags=0);
Adesk::Boolean acedClearOLELock(int handle);
void acedPostCommandPrompt();

For example:

// Get a point in AutoCAD, even though the point is not used.
//
STDMETHODIMP CMyApp::GetPoint()
{
    // Establishing a lock informs AutoCAD to reject any other
    // out-of-process Automation requests. If this call is 
    // made from an unknown context (e.g., not a normal AutoCAD
    // registered command or lisp), then it also saves the 
    // current AutoCAD state.
    //
    if (acedSetOLELock(5) != Adesk::kTrue) // arbitrary handle value
    {
        return E_FAIL;
    }
    // Do the input acquisition (interaction).
    //
    ads_point result;
    if(acedGetPoint(NULL, "Pick a point: ", result) != RTNORM)
    {
        acedClearOLELock(5); 
        return E_FAIL;
    }
    // Clear the lock to allow out-of-process Automation 
    // requests to be accepted again. If the AutoCAD state was saved
    // during the call to acedSetOLELock(), then the saved state is
    // restored.
    //
    acedClearOLELock(5); // use same handle used in acedSetOLELock()
    // Forces AutoCAD to redisplay the command prompt.
    //
    acedPostCommandPrompt(); 
    return S_OK;
}