1. 程式人生 > >ObjectARX中三維多段線轉二維多段線的方法

ObjectARX中三維多段線轉二維多段線的方法

ext tro errors ont step sed close des on()

Acad::ErrorStatus 
AcDb3dPolylineToAcDb2dPolyline(AcDbObjectId objId, int flag /* =0 */)
{

	Acad::ErrorStatus es;
	AcDbEntity *pEnt = NULL;
	double elev = 0.0;
	es = acdbOpenObject(pEnt, objId, AcDb::kForWrite);
	int i = 0;
	if (pEnt->isKindOf(AcDb3dPolyline::desc()))
	{
		AcDb2dPolyline *pNewline = new AcDb2dPolyline();
		AcDb3dPolyline *pPline = AcDb3dPolyline::cast(pEnt);
		AcDbObjectIterator *pItr = pPline->vertexIterator();

		for (pItr->start(); !pItr->done(); pItr->step())
		{
			AcDb3dPolylineVertex *pVertex = NULL;
			AcDbObjectId vId = pItr->objectId();
			acdbOpenObject(pVertex, vId, AcDb::kForRead);
			AcDb::Vertex3dType verType = pVertex->vertexType();
			if (verType != AcDb::k3dControlVertex)
			{
				i++;
				AcDb2dVertex *p2dVertex = new AcDb2dVertex(pVertex->position());
				p2dVertex->setXData(pVertex->xData());
				pNewline->appendVertex(p2dVertex);
				p2dVertex->close();
			}
			if (flag == 1)
			{
				elev += pVertex->position().z;
			}

			pVertex->close();
		}
		delete pItr;
		pItr = 0;
		double eleva = elev / i;

		pNewline->setElevation(eleva);
		pNewline->setPropertiesFrom(pPline);
		if (pPline->isClosed())
		{
			pNewline->makeClosed();
		}
		pNewline->setXData(pPline->xData());
		m_DbUtil.PostToModelSpace(pNewline);
		pPline->erase();

	}
	pEnt->close();

	return es;
}

  

ObjectARX中三維多段線轉二維多段線的方法