|
static void SplitPline(void)
{
AcGePoint3d p1, p2;
if (acedGetPoint(NULL, _T("\nPick First point on Polyline: "), asDblArray(p1)) == RTNORM &&
acedGetPoint(asDblArray(p1),_T("\nPick Second point on Polyline: "), asDblArray(p2)) == RTNORM)
{
AcGeMatrix3d matUCS; acedGetCurrentUCS(matUCS);
p1.transformBy(matUCS); p2.transformBy(matUCS);
ads_name en; ads_point p;
if (acedEntSel(_T("\nSelect polyline: "), en, p) != RTNORM) return;
AcDbObjectId eid; acdbGetObjectId(eid,en);
AcDbObjectPointer<AcDbPolyline> pPline(eid,AcDb::kForRead);
if (pPline.openStatus() != Acad::eOk) return;
AcGePoint3d p1n, p2n;
if (pPline->getClosestPointTo(p1,p1n) != Acad::eOk) return;
if (pPline->getClosestPointTo(p2,p2n) != Acad::eOk) return;
double par1,par2;
if (pPline->getParamAtPoint(p1n,par1) != Acad::eOk) return;
if (pPline->getParamAtPoint(p2n,par2) != Acad::eOk) return;
AcGeDoubleArray pars;
pars.append(min(par1,par2)); pars.append(max(par1,par2));
AcDbVoidPtrArray arr;
if (pPline->getSplitCurves(pars,arr) != Acad::eOk) return;
for (int i = 0; i < arr.length(); i++)
{
AcDbEntity *pEnt = static_cast<AcDbEntity *>(arr[i]);
AcDbPolyline *pPlineSub = AcDbPolyline::cast(pEnt);
if (pPlineSub) {
pPlineSub->setClosed(true);
pPlineSub->setBulgeAt(pPlineSub->numVerts()-1,0);
}
postToDwgAndClose(pEnt);
}
}
} |
|