• 2021年1月1日 AutoCAD.Net/C#.Net QQ群:193522571改变多段线区直



    代码:

    #include "StdAfx.h"
    #include "StdArx.h"
    #include <dbpl.h>
    #include "..\..\Common\Others\ConvertUtil.h"
    #include <geassign.h>
    #include "..\..\Common\Entity\ArcUtil.h"
    #include "..\..\Common\Document\DwgDatabaseUtil.h"
    #include <afxwin.h>
    #include <dbents.h>


    void ZffMyProjectchangeline()
    {

    ads_name polyLinename;
    ads_point pnt;

    if (acedEntSel("\n请选择多段线的条直线段!",polyLinename,pnt)!=RTNORM)
    {
    return;
    }
    AcDbObjectId polyLineId;
    acdbGetObjectId(polyLineId,polyLinename);
    AcDbEntity *pEnt=NULL;
    acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);
    if (pEnt->isKindOf(AcDbPolyline::desc()))
    {
    AcDbPolyline *pPolyline=AcDbPolyline::cast(pEnt);
    pEnt->close();
    int vtnum=pPolyline->numVerts();
    AcGePoint3dArray pts;
    AcGePoint3d pt;
    for(int i=0; i<vtnum; i++)
    {
    pPolyline->getPointAt(i, pt);
    pts.append(pt);
    }
    AcDbVoidPtrArray curves;
    pPolyline->getSplitCurves(pts,curves);
    bool nRb=true;
    for (i=0;i<curves.length();i++)
    {
    AcDbCurve *pCurve=static_cast<AcDbCurve*>(curves[i]);
    if (nRb)
    {
    AcGeLine2d geLine;
    AcGePoint3d pt1,pt2;
    pCurve->getStartPoint(pt1);
    pCurve->getEndPoint(pt2);
    AcGePoint2d pt12d,pt22d,pnt2d,pt2d;
    ads_point pt;
    AcGePoint3d ptOnArc;
    pt12d=CConvertUtil::ToPoint2d(pt1);
    pt22d=CConvertUtil::ToPoint2d(pt2);
    pnt2d=CConvertUtil::ToPoint2d(asPnt3d(pnt));
    geLine.set(pt12d,pt22d);
    double tol =1;
    if (geLine.distanceTo(pnt2d)<tol)
    {
    nRb=false;
    delete pCurve;
    pCurve->close();
    acedGetPoint(NULL,"\n输入一个点:",pt);
    pt2d=CConvertUtil::ToPoint2d(asPnt3d(pt));
    AcGeCircArc2d geArc(pt12d, pt2d, pt22d);
    AcGePoint2d ptCenter = geArc.center();
    double radius = geArc.radius();
    AcGeVector2d vecStart(pt12d.x - ptCenter.x, pt12d.y - ptCenter.y);
    AcGeVector2d vecEnd(pt22d.x - ptCenter.x, pt22d.y - ptCenter.y);
    double startAngle = vecStart.angle();
    double endAngle = vecEnd.angle();
    AcDbArc *pArc=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter), radius, startAngle, endAngle);
    pArc->getClosestPointTo(asPnt3d(pt),ptOnArc);

    if (CConvertUtil::ToPoint2d(ptOnArc).distanceTo(pt2d)<tol)
    {
    CDwgDatabaseUtil::PostToModelSpace(pArc);
    }
    else
    {
    AcDbArc *pArc2=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter),radius,endAngle,startAngle);
    CDwgDatabaseUtil::PostToModelSpace(pArc2);
    delete pArc;
    }
    continue;
    }

    }
    CDwgDatabaseUtil::PostToModelSpace(pCurve);
    pCurve->close();
    }
    acdbOpenObject(pPolyline,polyLineId,AcDb::kForWrite);
    pPolyline->erase();
    pPolyline->close();
    }
    pEnt->close();
    }

  • 相关阅读:
    微信内置浏览器 如何小窗不全屏播放视频?也可以尝试canvas.
    正则替换replace中$1的用法以及常用正则
    去掉textarea和input在ios下默认出现的圆角
    让ckplayer支持m3u8格式的播放
    ios中的safari转换时间戳问题
    JavaScript判断不同平台
    swiper实现臭美app滑动效果
    开启CSP网页安全政策防止XSS攻击
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    设置元素text-overflow: ellipsis后引起的文本对齐问题
  • 原文地址:https://www.cnblogs.com/NewAutoMan/p/5125112.html
Copyright © 2020-2023  润新知