閱讀378 返回首頁    go 阿裏雲 go 技術社區[雲棲]


ObjectArx學習筆記-創建多段線

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);
		}


	}


最後更新:2017-04-03 08:26:26

  上一篇:go 麵向 Java 開發人員的 Ajax: Google Web Toolkit 入門
  下一篇:go 什麼是連接池,其工作原理是什麼?