1、创建一个工具类CTool。
Tool.h:
static ads_real GetWidth(); static int GetColorIndex();
Tool.cpp
ads_real CTool::GetWidth() { ads_real width = 0; if(acedGetReal(_T("\n输入线宽:"), &width)==RTNORM) { return width; } else { return 0; } } int CTool::GetColorIndex() { int colorIndex = 0; if(acedGetInt(_T("输入颜色索引值(0~256):"), &colorIndex) != RTNORM) { return 0; } while(colorIndex < 0 || colorIndex >256) { acedPrompt(_T("输入了错误的颜色索引值!")); if(acedGetInt(_T("输入颜色索引值(0~256)"), &colorIndex) != RTNORM) { return 0; } } return colorIndex; }
2、添加命令AddPoly
实现代码如下:
static void qxzyAddPolyDynamicCommands_AddPoly(void) { // Add your code for command qxzyAddPolyDynamicCommands._AddPoly here int colorIndex = 0; ads_real width = 0; int index = 2; ads_point ptStart; if(acedGetPoint(NULL, _T("\n输入第一点:"), ptStart) != RTNORM) return; ads_point ptPrevious,ptCurrent; acdbPointSet(ptStart, ptPrevious); AcDbObjectId polyId; acedInitGet(NULL, _T("W C O")); int rc = acedGetPoint(ptPrevious, _T("\n输入下一点[宽度(W)/颜色(C)]<完成(O)>"), ptCurrent); while(rc == RTNORM || rc == RTKWORD) { if(rc == RTKWORD) { ACHAR kword[20]; if(acedGetInput(kword)!=RTNORM) return; if(strcmp((LPSTR)(LPCTSTR)kword,"W")==0) { width = CTool::GetWidth(); } else if(strcmp((LPSTR)(LPCTSTR)kword,"C")==0) { colorIndex = CTool::GetColorIndex(); } else if(strcmp((LPSTR)(LPCTSTR)kword, "O")==0) { return; } else { acutPrintf(_T("\n无效的关键字")); } } else if(rc == RTNORM) { if(index == 2) { AcDbPolyline *pPoly= new AcDbPolyline(2); AcGePoint2d ptGe1,ptGe2; ptGe1[X]=ptPrevious[X]; ptGe1[Y]=ptPrevious[Y]; ptGe2[X]=ptCurrent[X]; ptGe2[Y]=ptCurrent[Y]; pPoly->addVertexAt(0, ptGe1); pPoly->addVertexAt(1, ptGe2); pPoly->setConstantWidth(width); pPoly->setColorIndex(colorIndex); AcDbBlockTable *pBlkTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlkTbl, AcDb::kForRead); AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite); pBlkTblRcd->appendAcDbEntity(polyId, pPoly); pBlkTblRcd->close(); pBlkTbl->close(); pPoly->close(); } else if(index>2) { AcDbPolyline *pPoly; acdbOpenObject(pPoly, polyId, AcDb::kForWrite); AcGePoint2d ptGe; ptGe[X]=ptCurrent[X]; ptGe[Y]=ptCurrent[Y]; pPoly->addVertexAt(index-1,ptGe); pPoly->setConstantWidth(width); pPoly->setColorIndex(colorIndex); pPoly->close(); } index++; acdbPointSet(ptCurrent,ptPrevious); } acedInitGet(NULL, _T("W C O")); rc = acedGetPoint(ptPrevious, _T("\n输入下一点[宽度(W)/颜色(C)]<完成(O)>"), ptCurrent); } }
时间: 2024-10-31 01:23:52