ObjectARX_AutoCAD创建直线功能实现

void CreateLine()//创建直线命令
{
	ads_point startPoint, endPoint;
	//用户交互,获取点
	int nReturn;
	nReturn = acedGetPoint(NULL, _RXST("指定第一个点:"), startPoint);
	if (nReturn != RTNORM){
		AfxMessageBox(_RXST("点选失败."));
		return;
	}
	//记录坐标点的数目
	int PotNumber = 1;
	ads_point temp_point;
	temp_point[X] = startPoint[X], temp_point[Y] = startPoint[Y];
	while (true){
		acedInitGet(NULL, _T("U C"));
		if (PotNumber >= 3){
			nReturn = acedGetPoint(temp_point, _RXST("\n指定下一点或闭合(C)或放弃(U):"), endPoint);
		}
		else {
			nReturn = acedGetPoint(temp_point, _RXST("\n指定下一点或放弃(U):"), endPoint);
		}
		//判断时关键字or按下一点or其他
		if (nReturn == RTKWORD)//关键字
		{
			ACHAR kword[20];
			if (acedGetInput(kword) != RTNORM){
				return;
			}
			if (_tcscmp(kword, _T("U")) == 0){
				acutPrintf(_RXST("放弃 创建直线."));
				return;
			}
			else if (_tcscmp(kword, _T("C")) == 0){
				if (PotNumber < 3)
					continue;
				AcGePoint3d AcGeStartPot = asPnt3d(temp_point);
				AcGePoint3d AcGeEndPot = asPnt3d(startPoint);
				AcDbLine *pLine = new AcDbLine(AcGeStartPot, AcGeEndPot);
				HysuEditor::PostToModelSpace(pLine);
				acutPrintf(_RXST("闭合直线."));
				return;
			}
			else
				AfxMessageBox(_RXST("关键字无效."));
		}
		else if (nReturn == RTNORM)//按下一点
		{
			PotNumber++;
			AcGePoint3d AcGeStartPot = asPnt3d(temp_point);
			AcGePoint3d AcGeEndPot = asPnt3d(endPoint);
			AcDbLine *pLine = new AcDbLine(AcGeStartPot, AcGeEndPot);
			HysuEditor::PostToModelSpace(pLine);
			//将下一点坐标转换成下一直线的起始点
			temp_point[X] = endPoint[X], temp_point[Y] = endPoint[Y];
		}
		else//其他
		{
			acutPrintf(_RXST("\n已退出 创建直线."));
			return;
		}	
	}
}
AcDbObjectId HysuEditor::PostToModelSpace(AcDbEntity *pEnt, AcDbDatabase *pDb)
{
	AcDbBlockTable *pBlkTbl = NULL;
	Acad::ErrorStatus es;
	es = pDb->getBlockTable(pBlkTbl, AcDb::kForRead);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\n块表打开失败,错误代码:%s"), acadErrorStatusText(es));
		return AcDbObjectId::kNull;
	}
	AcDbBlockTableRecord *pBlkTblRcd = NULL;
	es = pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\n模型空间块表记录打开失败,错误代码:%s"), acadErrorStatusText(es));
		pBlkTbl->close();
		return AcDbObjectId::kNull;
	}
	pBlkTbl->close();
	AcDbObjectId outId;
	es = pBlkTblRcd->appendAcDbEntity(outId, pEnt);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\n无法添加实体到模型空间,错误代码:%s"), acadErrorStatusText(es));
		pBlkTblRcd->close();
		return AcDbObjectId::kNull;
	}
	pEnt->close();
	pBlkTblRcd->close();
	return outId;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值