admin 发表于 2024-5-4 18:39:42

多段线动态切割闭合区域



#include "StdAfx.h"
#include "StdArx.h"
#include <dbpl.h>
#include "..\..\Common\Others\ConvertUtil.h"
#include "..\..\Common\Document\DwgDatabaseUtil.h"
#include <dbents.h>
#include <dbregion.h>
#include "..\..\Common\Entity\RegionUtil.h"

// This is command 'INTERSECT1'
void ZffMyProjectintersect1()
{
// TODO: Implement the command
ads采用name polyLinename;
ads采用name polyLinename2;
ads采用point pnt;
ads采用point pnt2;

AcDbPolyline *pPolyline=NULL;
AcDbPolyline *pPoly=NULL;
AcDbRegion *pRegion1=NULL;
AcDbRegion *pRegion2=NULL;
acedEntSel("\n请选择截取多段线!",polyLinename,pnt);
AcDbObjectId polyLineId;
acdbGetObjectId(polyLineId,polyLinename);
AcDbEntity *pEnt=NULL;
AcGePoint3dArray pts,pts2;
acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);

if (pEnt->isKindOf(AcDbPolyline::desc()))
{
pPolyline=AcDbPolyline::cast(pEnt);
pEnt->close();
}
AcDbVoidPtrArray curves;
int num=pPolyline->numVerts();
for (int i=0;i<num;i++)
{
AcGePoint2d pt;
pPolyline->getPointAt(i,pt);
pts.append(CConvertUtil::ToPoint3d(pt));
}
pPolyline->getSplitCurves(pts,curves);
pPolyline->close();
AcDbObjectIdArray curvesId;
AcDbCurve *pCurve=NULL;
for (i=0;i<curves.length();i++)
{
pCurve=static采用cast<AcDbCurve*>(curves);
curvesId.append(CDwgDatabaseUtil::PostToModelSpace(pCurve));
}
pCurve->close();

acedEntSel("\n请选择被截取多段线!",polyLinename2,pnt2);
acdbGetObjectId(polyLineId,polyLinename2);
acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
pPoly=AcDbPolyline::cast(pEnt);
pEnt->close();
//pPoly->intersectWith(pPolyline,AcDb::kOnBothOperands,pts,0,0);
}
AcDbVoidPtrArray curves2;
num=pPoly->numVerts();
for (i=0;i<num;i++)
{
AcGePoint2d pt2;
pPoly->getPointAt(i,pt2);
pts2.append(CConvertUtil::ToPoint3d(pt2));
}
pPoly->getSplitCurves(pts2,curves2);
pPoly->close();
AcDbObjectIdArray curvesId2;
AcDbCurve *pCurve2=NULL;
for (i=0;i<curves2.length();i++)
{
pCurve2=static采用cast<AcDbCurve*>(curves2);
curvesId2.append(CDwgDatabaseUtil::PostToModelSpace(pCurve2));
}
pCurve2->close();
AcDbObjectIdArray regId=CRegionUtil::Add(curvesId);
AcDbObjectIdArray regId2=CRegionUtil::Add(curvesId2);
for (i=0;i<curvesId.length();i++)
{
acdbOpenObject(pCurve,curvesId,AcDb::kForWrite);
pCurve->erase();
pCurve->close();
}
for (i=0;i<curvesId2.length();i++)
{
acdbOpenObject(pCurve2,curvesId2,AcDb::kForWrite);
pCurve2->erase();
pCurve2->close();
}
acdbOpenObject(pRegion1,regId,AcDb::kForWrite);
acdbOpenObject(pRegion2,regId2,AcDb::kForWrite);
pRegion1->booleanOper(AcDb::kBoolIntersect,pRegion2);
pRegion1->close();
pRegion2->close();
}
页: [1]
查看完整版本: 多段线动态切割闭合区域