To provide the user with graphical feedback during long tasks, and also ensure that any user cancellation (due to the Escape key being pressed) is handled, you can use the following functions:
int acedSetStatusBarProgressMeter(const ACHAR* pszLabel, int nMinPos, int nMaxPos);
int acedSetStatusBarProgressMeterPos(int nPos);
void acedRestoreStatusBar();
To check for cancellation by the user you can use this function:
int acedUsrBrk();
It returns 1 if the user has cancelled the operation, or 0 otherwise. I would check it regularly (though not excessively so), and on finding the return value is true your application should perform the necessary cleanup and return control to the user.
In the code sample, a long task is simulated using nested for loops and the Win32 Sleep() function. The methods used here are part of rxmfcapi.h and you will have this included in your project automatically if you choose MFC support while creating your project using the ObjectARX Wizard.
Here is the sample code :
static void ADSProjectMyCommand(void)
{
Adesk::Boolean bContinue = Adesk::kTrue;
acutPrintf
(
ACRX_T("\nStarting Progress Meter…\r")
);
acedSetStatusBarProgressMeter
(
ACRX_T("Test Progress Bar"), 0, 100
);
for( int i =0; i <= 100; i++ )
{
for( int j = 0; j <= 10; j++ )
{
Sleep( 100 );
if ( acedUsrBrk() )
{
// Perform cleanup on cancel
bContinue = Adesk::kFalse;
acutPrintf(
ACRX_T("\nCancelled !")
);
break;
}
}
if ( !bContinue )
break;
acedSetStatusBarProgressMeterPos( i );
}
acedRestoreStatusBar();
}
For a .Net implementation of similar functionality, please take a look at this blog post :
Displaying a progress meter during long operations in AutoCAD using .NET

Leave a Reply