C++ CAD Arx二次开发用户交互

C++ CAD Arx二次开发用户交互

展开

一、本节课程

Arx二次开发用户交互

二、本节要讲解的知识点

1、用户交互的一些函数:acedGetXXX(acedGetString、acedGetPoint、acedGetInt acedGetKword、acedGetReal)。

2、动态创建多段线的实现。

3、acedGetPoint函数中使用关键字。

三、具体内容

1、acedGetString:获取用户输入的字符串

acedGetPoint:获取用户输入的点

acedGetInt:获取用户输入的整型

acedGetKword:获取用户输入的关键字

acedGetReal:获取用户输入的实数。

2、动态创建多段线:最基本的要求就是用户在图形窗口中按顺序拾取各个点,每次拾取一点都会将其加入到多段线的末端,最终按ENTER键或者ESC键就完成多段线的创建。

(1)拾取第一点;

(2)拾取第二点,创建多段线。

(3)如果没有按ENTER或ESC键,则拾取下一点,并将拾取的点添加到多段线的末尾。

(4)如果用户按ENTER或ESC键,退出程序的执行,多段线创建完毕,否则执行步骤3。

3、动态创建多段线(简单版、升级版)

static void YunyouMyGroupAddPolyBaic(void)

{

int index=2;

AcGePoint3d ptStart;

if (!CGetInputUtil::GetPoint(TEXT("\n please input first point:"),ptStart))

{

return;

}

AcGePoint3d ptPrevious,ptCurrent;

ptPrevious=ptStart;

AcDbObjectId polyId;

while (CGetInputUtil::GetPoint(ptPrevious,TEXT("\n please input NEXT point:"),ptCurrent))

{

if (index==2)

{

polyId=CPolylineUtil::Add(CConvertUtil::ToPoint2d(ptPrevious),CConvertUtil::ToPoint2d(ptCurrent));

}

else if(index>2)

{

AcDbPolyline *pPoly=NULL;

if (acdbOpenObject(pPoly,polyId,AcDb::kForWrite)==Acad::eOk)

{

pPoly->addVertexAt(index-1,CConvertUtil::ToPoint2d(ptCurrent));

pPoly->close();

}

}

ptPrevious=ptCurrent;

index++;

}

}

static void YunyouMyGroupAddPoly(void)

{

int colorIndex=0;

ads_real width=0;

int index=2;

AcGePoint3d ptStart;

if (!CGetInputUtil::GetPoint(TEXT("\n please input first point:"),ptStart))

{

return;

}

AcGePoint3d ptPrevious,ptCurrent;

ptPrevious=ptStart;

AcDbObjectId polyId;

acedInitGet(NULL,TEXT("W C O"));

int rc=CGetInputUtil::GetPointReturnCode(ptPrevious,

TEXT("\n输入下一点[宽度(W)/颜色(C)<完成(O)>:"),

ptCurrent);

while (rc==RTNORM || rc==RTKWORD)

{

if (rc==RTKWORD)

{

ACHAR kword[20];

if (acedGetInput(kword)!=RTNORM)

{

return;

}

if (_tcscmp(kword,TEXT("W"))==0)

{

width=GetWidth();

}

else if (_tcscmp(kword,TEXT("C"))==0)

{

colorIndex=GetColorIndex();

}

else if (_tcscmp(kword,TEXT("O"))==0)

{

return;

}

else

{

acutPrintf(TEXT("\n输入了无效的关键字"));

}

}

else if(rc==RTNORM)

{

if (index==2)

{

polyId=CPolylineUtil::Add(CConvertUtil::ToPoint2d(ptPrevious),CConvertUtil::ToPoint2d(ptCurrent));

AcDbPolyline *pPoly=NULL;

if (acdbOpenObject(pPoly,polyId,AcDb::kForWrite)==Acad::eOk)

{

pPoly->setConstantWidth(width);

pPoly->setColorIndex(colorIndex);

pPoly->close();

}

}

else if(index>2)

{

AcDbPolyline *pPoly=NULL;

if (acdbOpenObject(pPoly,polyId,AcDb::kForWrite)==Acad::eOk)

{

pPoly->addVertexAt(index-1,CConvertUtil::ToPoint2d(ptCurrent));

pPoly->setConstantWidth(width);

pPoly->setColorIndex(colorIndex);

pPoly->close();

}

}

ptPrevious=ptCurrent;

index++;

}

//

acedInitGet(NULL,TEXT("W C O"));

rc=CGetInputUtil::GetPointReturnCode(ptPrevious,TEXT("\n输入下一点[宽度(W)/颜色(C)<完成(O)>:"),ptCurrent);//

}

}

static void YunyouMyGroupGetPointKeyword(void)

{

int rc;

ACHAR kword[20];

AcGePoint3d pt;

acedInitGet(RSG_NONULL,TEXT("K W"));

rc=CGetInputUtil::GetPointReturnCode(TEXT("\n输入一个点或[Keyword1/KeyWord2]:"),pt);

switch (rc)

{

case RTKWORD:

if (acedGetInput(kword)!=RTNORM)

{

return;

}

if (_tcscmp(kword,TEXT("K"))==0)

{

acutPrintf(TEXT("\n 选择的关键字是Keyword1"));

}

else

{

acutPrintf(TEXT("\n 选择的关键字是Keyword2"));

}

break;

case RTNORM:

acutPrintf(TEXT("\n输入点的坐标是(%.2f,%.2f,%.2f)"),pt.x,pt.y,pt.z);

break;

default:

break;

}

}

四、总结

acedGetString:获取用户输入的字符串

acedGetPoint:获取用户输入的点

acedGetInt:获取用户输入的整型

acedGetKword:获取用户输入的关键字

acedGetReal:获取用户输入的实数

acedGetDist:获取用户输入的距离值

acedGetCorner:获取用户输入的角点

acedGetAngle:获取用户输入的角度

acedGetFileD:打开文件选择对话框获取用户输入的文件名

————————————————

版权声明:本文为CSDN博主「yunyouxy」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/yunyouxy/article/details/81036230