• 2021年1月1日 AutoCAD.Net/C#.Net QQ群:193522571多段线动态切割闭合区域



    #include "StdAfx.h"
    #include "StdArx.h"
    #include <dbpl.h>
    #include "....CommonOthersConvertUtil.h"
    #include "....CommonDocumentDwgDatabaseUtil.h"
    #include <dbents.h>
    #include <dbregion.h>
    #include "....CommonEntityRegionUtil.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(" 请选择截取多段线!",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[i]);
    curvesId.append(CDwgDatabaseUtil::PostToModelSpace(pCurve));
    }
    pCurve->close();

    acedEntSel(" 请选择被截取多段线!",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[i]);
    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[i],AcDb::kForWrite);
    pCurve->erase();
    pCurve->close();
    }
    for (i=0;i<curvesId2.length();i++)
    {
    acdbOpenObject(pCurve2,curvesId2[i],AcDb::kForWrite);
    pCurve2->erase();
    pCurve2->close();
    }
    acdbOpenObject(pRegion1,regId[0],AcDb::kForWrite);
    acdbOpenObject(pRegion2,regId2[0],AcDb::kForWrite);
    pRegion1->booleanOper(AcDb::kBoolIntersect,pRegion2);
    pRegion1->close();
    pRegion2->close();
    }

  • 相关阅读:
    iBATIS.net配置说明篇
    深入理解asp.net里的HttpModule机制
    iBATIS.net开发的第一个web实例
    javascript对iframe的互操作浅析
    sql的临时表使用小结
    bootstrap的BaseCSS 20120328
    bootstrap2.02 notice
    我个人的ASPNET与php与nodeJS比较
    64汉诺塔问题
    jQuery使用感
  • 原文地址:https://www.cnblogs.com/NewAutoMan/p/5133346.html
Copyright © 2020-2023  润新知