|
//创建多段线==================
static ads_real GetWidth(){
ads_real width = 0;
if(acedGetReal(_T("\n输入线宽"),&width) == RTNORM){
return width;
}
else{
return 0;
}
}
static int GetColorIndex(){
int colorIndex = 0;
if(acedSetColorDialog(colorIndex,Adesk::kFalse,256) != IDOK){
return 0;
}
else{
return colorIndex;
}
}
添加多段线,用户指定点、线宽、颜色
static void TESTaddplcmd(){
int colorIndex = 255;
ads_real width = 1;
int index = 2;
ads_point ptStart;
//提示用户输入起始点
if(acedGetPoint(NULL,_T("\n输入第一点"),ptStart) != RTNORM){
return;
}
ads_point ptPrevious,ptCurrent;//前一个参考点,当前拾取的点
acdbPointSet(ptStart,ptPrevious);
AcDbObjectId polyId;//多段线的ID
输入第二点
acedInitGet(NULL,_T("W C O"));
int rc = acedGetPoint(ptPrevious,_T("\n输入下一点[宽度(W)颜色(C)]<完成(O)>:"),ptCurrent);
while(rc == RTNORM || rc == RTKWORD){
if(rc == RTKWORD){如果用户输入了关键字
CString kword;
if(acedGetInput(kword.GetBuffer()) != RTNORM)
return;
if(kword.Compare(_T("W")) == 0){
width = GetWidth();
}
else if (kword.Compare(_T("C")) == 0){
colorIndex = GetColorIndex();
}
else if(kword.Compare(_T("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);
添加到模型
polyId = LoadEntity(pPoly);
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->setColorIndex(colorIndex);
pPoly->close();
}
index ++;
acdbPointSet(ptCurrent,ptPrevious);
}
acedInitGet(NULL,_T("W C O"));
rc = acedGetPoint(ptPrevious,_T("\输入下一点"),ptCurrent);
}
} |
|