改变多段线区直
代码:
#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();
}
更多文章
-
用AcedGrRead()函数实现一拖多
实现代码:#include "StdAfx.h"#include "StdArx.h"#include "..\..\Common\我的类\Arc.h"#include <acedads.h>#include "..\..\Common\Entity\LineUtil.h"#include <geassign.h>#include <dbents.h>#include "..\..\Common\Others\ConvertUtil.h"#in
-
改变多段线区直
代码:#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&
-
获取任意路径Dwg文件内所有块在控件中显示并能选择插入当前模型空间
主对话框CPP内代码:#include "StdAfx.h"#include "resource.h"#include "BlockDialog.h"#include "..\..\Common\我的类\file.h"#include "..\..\Common\Document\DwgDatabaseUtil.h"#include <dbents.h>#include <dbmain.h>#include "..\..\Chapter11
-
多段线动态切割闭合区域
#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"
-
自创实体类从AcDbCurve派生,实现一些类方法并动态绘制
MyCurve.cpp:#include "StdAfx.h"#include "MyCurve.h"#include "actrans.h"#include "aced.h"//-----------------------------------------------------------------------------Adesk::UInt32 CMyCurve::kCurrentVersionNumber =1 ;//----------------------------------------