ObjectARX延时动画之定时器简单示意

 

 

使用定时器可以延时操控cad,不影响视图操作。如果你在定时器运行期间使用命令,可能会导致定时器生成的实体无法刷新,变为当前不可见实体。

示例代码

//声明静态全局变量
static int nPrintNumber=0;
void CALLBACK MyCopyFunc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);//回调函数声明

void CALLBACK MyCopyFunc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)//回调函数实现
{
    if(nPrintNumber > 60)
    {
        //销毁定时器
        KillTimer(acedGetAcadFrame()->m_hWnd,1);
    }
    else
    {
        //acutPrintf(_T("\n%d"),nPrintNumber++);
        nPrintNumber++;
        AcDbObjectPointer<AcDbCircle> pCir;
        Acad::ErrorStatus es= pCir.create();
        if (Acad::eOk != es)
        {
            return;
        }
        pCir->setCenter(AcGePoint3d(nPrintNumber*100,0,0));
        pCir->setRadius(150.0);
        pCir->setColorIndex(1);
        AcApDocument *pDoc=curDoc();
        acDocManager->lockDocument(pDoc);
        AcDbBlockTableRecordPointer pBlkRcd(pDoc->database()->currentSpaceId(),AcDb::kForWrite);
        es = pBlkRcd.openStatus();
        if (Acad::eOk != es)
        {
            acutPrintf(_T("\n错误码= %s"),acadErrorStatusText(es));
            return;
        }
        es = pBlkRcd->appendAcDbEntity(pCir);
        if (Acad::eOk != es)
        {
            acutPrintf(_T("\nappend错误码= %s"),acadErrorStatusText(es));
            return;
        }
        es = pCir->draw();
        if (Acad::eOk != es)
        {
            acutPrintf(_T("\ndraw错误码= %s"),acadErrorStatusText(es));
            return;
        }
        acedUpdateDisplay();
        acDocManager->unlockDocument(pDoc);
    }
}

//启动定时器
void StartTimer()
{
    nPrintNumber=0;
    SetTimer(acedGetAcadFrame()->m_hWnd,1, 100, (TIMERPROC)MyCopyFunc);
}

调用 StartTimer 即可。

 

posted @ 2020-12-18 15:31  edata  阅读(224)  评论(0编辑  收藏  举报