[每日一码] 转换同面的3DPOLYLINE到AcDb2dPolyline
void asdktest(){
ads采用name ss;
ACHAR* prompts={L"\nSelect 3d polylines",L"\nUnselect objects"};
int res=acedSSGet(L":$",prompts,NULL,NULL,ss);
if (RTNORM != res)
{
acutPrintf(L"\nNo objects selected");
return;
}
long len;
res=acedSSLength(ss,&len);
if (RTNORM != res || len == 0)
{
acutPrintf(L"\nNo objects selected");
return;
}
//get coordinate system from current UCS
AcGeMatrix3d mat;
acdbUcsMatrix(mat);
AcGePoint3dorigin;
AcGeVector3d xAxis;
AcGeVector3d yAxis;
AcGeVector3d norm;
mat.getCoordSystem(origin,xAxis,yAxis,norm);
Acad::ErrorStatus es;
for(int i=0 ; i < len ; i++)
{
ads采用name eName;
acedSSName(ss,i,eName);
AcDbObjectId objId;
acdbGetObjectId(objId,eName);
AcDb3dPolyline *pPline=NULL;
es=acdbOpenObject(pPline, objId, AcDb::kForRead);
if (Acad::eOk == es)
{
AcDbObjectIterator *pVertIter= pPline->vertexIterator();
Adesk::Boolean isClosed=Adesk::kFalse;
isClosed=pPline->isClosed();
pPline->close();
// Finished with the pline header.
AcGePoint3d location;
AcDbObjectId vertexObjId;
AcGePoint3dArray aPts;
for (;!pVertIter->done();pVertIter->step())
{
AcDb3dPolylineVertex *pVertex;
vertexObjId = pVertIter->objectId();
acdbOpenObject(pVertex, vertexObjId,AcDb::kForRead);
aPts.append(pVertex->position());
pVertex->close();
}
delete pVertIter;
AcGePoint3dArray newPts;
AcGePoint3d newPt;
for (int i=0 ; i< aPts.length() ; i++)
{
acdbWcs2Ecs(asDblArray(aPts<i>),asDblArray(newPt), asDblArray(norm),Adesk::kFalse);
newPts.append( newPt);
}
AcDb2dPolyline *pPoly = new AcDb2dPolyline(AcDb::k2dSimplePoly /*poly type*/,
newPts /* vertices */,
newPts.at(0) /* elevation */,
isClosed /* closed or open*/);
pPoly->setNormal(norm);
pPoly->setLayer(L"0");
pPoly->setColorIndex(5); //blue color
postToModelSpace(pPoly);
pPoly->close();
}//if
}//for
acedSSFree(ss);
}/* end of asktest*/
页:
[1]