天天看點

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:打開檔案選擇對話框擷取使用者輸入的檔案名

 視訊課程由yunyou.ke.qq.com提供

繼續閱讀