?? exam03.cpp
字號:
#include <adslib.h>
#include <rxdlinkr.h>
#include <aced.h>
#include <dbents.h>
#include <geassign.h>
#include <dbsymtb.h>
#include <dbapserv.h>
Acad::ErrorStatus newLine();
void addLineCommand()
{
//{{BEGIN_LEVEL_ADVANCED
if (newLine()==Acad::eOk)
acutPrintf("Success\n");
else
acutPrintf("Failed\n");
//{{END_LEVEL_ADVANCED
}
Acad::ErrorStatus
postToDatabase(/*[in]*/AcDbEntity* pEnt,/*[out]*/AcDbObjectId& idObj)
{
Acad::ErrorStatus es;
AcDbBlockTable* pBlockTable;
AcDbBlockTableRecord* pSpaceRecord;
//確定當前有正在工作的數據庫
if (acdbHostApplicationServices()->workingDatabase()==NULL)
return Acad::eNoDatabase;
//獲得當前圖形的指針
//獲得圖形的塊表,打開準備讀取數據
if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk){
//獲得建模空間的記錄,打開準備寫數據
if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite))==Acad::eOk){
//添加實體指針到建模空間后關閉指針和建模空間記錄
if ((es = pSpaceRecord->appendAcDbEntity(idObj, pEnt))==Acad::eOk)
pEnt->close();
pSpaceRecord->close();
}
//關閉塊表
pBlockTable->close();
}
//返回狀態信息
return es;
}
Acad::ErrorStatus newLine()
{
ads_point pt1, pt2;//定義兩個ads_point的點
int retval;
try
{
//從用戶處獲得第一點
if ((retval = acedGetPoint(NULL, "\nSelect lower left: ", pt1)) != RTNORM)
throw retval;
//以第一點為基點, 從用戶處獲得第二點.
if ((retval = acedGetPoint(pt1, "\nSelect upper right: ", pt2)) != RTNORM)
throw retval;
}
catch (int e)
{
if (e == RTCAN)
//判斷輸入錯誤程序中斷
return Acad::eUserBreak;
if (e == RTERROR)
//判斷無效輸入
return Acad::eInvalidInput;
}
// 將ads_point類型的點轉換為AcGePoint3d類型之后創建直線
AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2));
//如果創建直線出錯,返回錯誤信息
if (!pLine)
{
acedAlert("Not enough memory to create a Line!");
return Acad::eOutOfMemory;
}
AcDbObjectId id; //定義對象ID
return postToDatabase(pLine, id);
}
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
//注冊命令
acedRegCmds->addCommand("EXAM03","addline","addline",ACRX_CMD_MODAL,addLineCommand);
break;
case AcRx::kUnloadAppMsg:
//當應用程序卸載后,為防止AUOTCAD調用此命令,產生不必要的
//錯誤,移走命令組
acedRegCmds->removeGroup("EXAM03");
break;
}
return AcRx::kRetOK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -