主要代码如下: #include "StdAfx.h" #include "StdArx.h" #include "resource.h" #include <stdio.h> #include "adslib.h" #include "adesk.h" #include "aced.h" #include "math.h" #include "acdb.h" #include "dbents.h" #include <dbsymtb.h> #include "rxregsvc.h" #include <rxdlinkr.h> #include <geassign.h> #include <dbapserv.h>
//----------------------------------------------------------------------------- // This is command 'MOTOIN, by [2005-8-31], , void xlgisMotoin() { #ifdef OARXWIZDEBUG acutPrintf ("\nOARXWIZDEBUG - xlgisMotoin() called."); #endif // OARXWIZDEBUG double A[3]={130.000,83.000,0.000}; double D[3]={213.000,83.000,0.000}; //四边边长 double a,b,c,d; a=34.000; b=101.000; c=64.000; d=D[0]-A[0]; //定义四点abcd AcGePoint3d APt(A[0],A[1],A[2]); AcGePoint3d DPt(D[0],D[1],D[2]); double B[36][3]; double C[36][3]; //B点和C点的运动轨迹计算结果数组 AcGePoint3d BPt[36]; AcGePoint3d CPt[36]; ////////////////////////// ///计算分析 double DETFI,FI,THETA,THETA1,THETA2; DETFI=3.1415926*10/180;//步长 FI=0;//初始角度 for (int i=0;i<36;i++) {//计算各点的坐标 double BD=sqrt(a*a+d*d-2*a*d*cos(FI)); THETA1=acos(-(a*a-d*d-BD*BD)/(2*d*BD)); THETA2=acos(-(b*b-c*c-BD*BD)/(2*c*BD)); THETA=THETA1+THETA2; //B点坐标 B[0]=A[0]+a*cos(FI); B[1]=A[1]+a*sin(FI); B[2]=0.000; //C点坐标 C[0]=D[0]+c*cos(THETA); C[1]=D[1]+c*sin(THETA); C[2]=0.000; FI=FI+DETFI; BPt.x=B[0]; BPt.y=B[1]; BPt.z=B[2]; CPt.x=C[0]; CPt.y=C[1]; CPt.y=C[2]; } //创建各图形 AcDbLine *pLine=new AcDbLine(APt,DPt);//创建直线AD实体对象 AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase()->getBlockTable( pBlockTable,AcDb::kForRead);// //获得当前块表(下) //获得当前块表的块表记录(下) AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close();//使用完毕,关闭块表 AcDbObjectId lineId; AcDbObjectId circleId_A; AcDbObjectId circleId_D; AcDbCircle *pCircleA; AcDbCircle *pCircleD; pCircleA=new AcDbCircle(APt,AcGeVector3d(0,0,1),1); //创建A点小圆实体对象R=1 pCircleD=new AcDbCircle(DPt,AcGeVector3d(0,0,1),1); //创建D点小圆实体对象R=1 pBlockTableRecord->appendAcDbEntity(lineId,pLine); //将直线IO加入到块表记录中 pBlockTableRecord->appendAcDbEntity(circleId_A,pCircleA); //将A点小圆加入到块表记录中 pBlockTableRecord->appendAcDbEntity(circleId_D,pCircleD); //将D点小圆加入到块表记录中 pBlockTableRecord->close();//关闭块表记录 pLine->close();//关闭实体直线AD对象 pCircleA->close();//关闭A点小圆实体对象 pCircleD->close();//关闭D点小圆实体对象 //---------------------------------------------------------------- AcDbObjectId circleId_B[36]; AcDbObjectId circleId_C[36]; AcDbCircle *pCircleB; AcDbCircle *pCircleC; for ( i=0;i<36;i++ ) {//创建BC点小圆 和AB BC CD AcDbObjectId idLine_AB; AcDbObjectId idLine_BC; AcDbObjectId idLine_CD; //获得当前块表(下) AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); //获得当前块表的块表记录(下) AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close();//使用完毕,关闭块表 pCircleB=new AcDbCircle(BPt,AcGeVector3d(0,0,1),1); //创建B点小圆实体对象R=1 pCircleC=new AcDbCircle(CPt,AcGeVector3d(0,0,1),1); //创建C点小圆实体对象R=1 AcDbLine *pLine_AB=new AcDbLine(APt,BPt); //创建AB实体对象 AcDbLine *pLine_BC=new AcDbLine(BPt,CPt); //创建BC实体对象 AcDbLine *pLine_CD=new AcDbLine(CPt,DPt); //创建CD实体对象 //加入到块表记录 pBlockTableRecord->appendAcDbEntity(circleId_B,pCircleB); pBlockTableRecord->appendAcDbEntity(circleId_C,pCircleC); pBlockTableRecord->appendAcDbEntity(idLine_AB,pLine_AB); pBlockTableRecord->appendAcDbEntity(idLine_BC,pLine_BC); pBlockTableRecord->appendAcDbEntity(idLine_CD,pLine_CD); pBlockTableRecord->close();//关闭块表记录 //关闭各图形对象 pCircleB->close(); pCircleC->close(); pLine_AB->close(); pLine_BC->close(); pLine_CD->close(); }//循环结束 // TODO: Implement the command }
|