- UID
- 756
- 积分
- 197
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-16
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 Love-Lisp 于 2013-8-15 22:55 编辑
刚学arx不久,拼凑了一个画圆的函数传递给Lisp调用,Lisp可以根据参数的不同,使用不同的方法绘制园:
- //3d点转2d点
- AcGePoint2d Pt3dTo2d(AcGePoint3d pt)
- {
- AcGePoint2d ptTemp(pt.x, pt.y);
- return ptTemp;
- }
- //对象添加到模型空间
- AcDbObjectId PostToModelSpace(AcDbEntity* pEnt)
- {
- AcDbBlockTable *pBlockTable;
- acdbHostApplicationServices()->workingDatabase()
- ->getBlockTable(pBlockTable, AcDb::kForRead);
- /*acdbHostApplicationServices()->workingDatabase()
- ->getSymbolTable(pBlockTable, AcDb::kForRead);*/
- AcDbBlockTableRecord *pBlockTableRecord;
- pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
- AcDbObjectId entId;
- pBlockTableRecord->appendAcDbEntity(entId, pEnt);
- pBlockTable->close();
- pBlockTableRecord->close();
- pEnt->close();
- return entId;
- }
- //圆心、所在平面向量、半径创建圆
- AcDbObjectId CreateCircle(AcGePoint3d ptCenter, AcGeVector3d vec, double radius)
- {
- AcDbCircle *pCircle = new AcDbCircle(ptCenter, vec, radius);
- // 将实体添加到图形数据库
- AcDbObjectId circleId;
- circleId = PostToModelSpace(pCircle);
- return circleId;
- }
- // 圆心、半径创建圆
- AcDbObjectId CreateCircle(AcGePoint3d ptCenter, double radius)
- {
- AcGeVector3d vec(0, 0, 1);
- return CreateCircle(ptCenter, vec, radius);
- }
- //两点法创建圆
- AcDbObjectId CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2)
- {
- // 计算圆心和半径
- AcGePoint2d pt = MiddlePoint(pt1, pt2);
- AcGePoint3d ptCenter(pt[X], pt[Y], 0); // 圆心
- double radius = pt1.distanceTo(pt2) / 2;
- // 创建圆
- return CreateCircle(ptCenter, radius);
- }
- //几何类法三点画圆
- AcDbObjectId CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2, AcGePoint2d pt3)
- {
- // 使用几何类
- AcGeCircArc2d geArc(pt1, pt2, pt3);
- AcGePoint3d ptCenter(geArc.center().x, geArc.center().y, 0);
- return CreateCircle(ptCenter, geArc.radius());
- }
- //定义外部Lisp函数 addcircle
- //绘制圆
- //圆心、所在平面向量、半径创建圆
- // 圆心、半径创建圆
- //两点法创建圆
- //三点法创建圆
- static int ads_addcircle()
- {
- struct resbuf *pArgs =acedGetArgs () ;
- if (pArgs == NULL)
- {
- acdbFail(_T("\n缺少参数"));
- return RTERROR;
- }
- AcGePoint3d p0,p1,p2;
- ads_real rad;
- ads_name ent;
- AcDbObjectId CircleId;
- if (!(pArgs->restype == RTPOINT || pArgs->restype == RT3DPOINT))
- {
- acdbFail(_T("\n参数错误"));
- return RTERROR;
- }
- p0 = asPnt3d(pArgs->resval.rpoint) ;
- pArgs = pArgs->rbnext;
- if (pArgs == NULL)
- {
- acdbFail(_T("\n缺少参数"));
- return RTERROR;
- }
- if (pArgs->restype == RTREAL || pArgs->restype == RTLONG || pArgs->restype == RTSHORT)
- {
- switch (pArgs->restype)
- {
- case RTREAL:
- rad = pArgs->resval.rreal;
- break;
- case RTLONG:
- rad = pArgs->resval.rlong;
- break;
- case RTSHORT:
- rad = pArgs->resval.rint;
- break;
- default:
- break;
- }
- if (pArgs->rbnext != NULL)
- {
- acdbFail(_T("\n参数太多"));
- return RTERROR;
- }
- //“圆心、半径”法创建一个圆
- CircleId = CreateCircle(p0, rad);
- acdbGetAdsName(ent,CircleId);
- acedRetName(ent,RTENAME);
- return (RSRSLT) ;
- }
- if (!(pArgs->restype == RTPOINT || pArgs->restype == RT3DPOINT))
- {
- acdbFail(_T("\n参数错误"));
- return RTERROR;
- }
- p1 = asPnt3d(pArgs->resval.rpoint) ;
- pArgs = pArgs->rbnext;
- if (pArgs == NULL)
- {
- // 两点法创建一个圆
- CircleId = CreateCircle(Pt3dTo2d (p0), Pt3dTo2d (p1));
- acdbGetAdsName(ent,CircleId);
- acedRetName(ent,RTENAME);
- return (RSRSLT) ;
- }
- if (pArgs->restype == RTPOINT || pArgs->restype == RT3DPOINT)
- {
- p2 = asPnt3d(pArgs->resval.rpoint) ;
- if (pArgs->rbnext != NULL)
- {
- acdbFail(_T("\n参数太多"));
- return RTERROR;
- }
-
- // 三点法创建一个圆
- CircleId = CreateCircle(Pt3dTo2d (p0), Pt3dTo2d (p1), Pt3dTo2d (p2));
- acdbGetAdsName(ent,CircleId);
- acedRetName(ent,RTENAME);
- return (RSRSLT) ;
- }
- else if (pArgs->restype == RTREAL || pArgs->restype == RTLONG || pArgs->restype == RTSHORT)
- {
- switch (pArgs->restype)
- {
- case RTREAL:
- rad = pArgs->resval.rreal;
- break;
- case RTLONG:
- rad = pArgs->resval.rlong;
- break;
- case RTSHORT:
- rad = pArgs->resval.rint;
- break;
- default:
- break;
- }
- if (pArgs->rbnext != NULL)
- {
- acdbFail(_T("\n参数太多"));
- return RTERROR;
- }
- //圆心、所在平面向量、半径创建圆
- AcGeVector3d vec(p1[X],p1[Y],p1[Z]);
- vec.normalize();
- CircleId = CreateCircle(p0, vec,rad);
-
- acdbGetAdsName(ent,CircleId);
- acedRetName(ent,RTENAME);
- return (RSRSLT) ;
- }
- else
- {
- acdbFail(_T("\n参数错误"));
- return RTERROR;
- }
- }
在lisp中可以使用如下四种方式调用:
- ;;lisp测试:
- ;;圆心、所在平面向量、半径创建圆
- (addcircle (setq cp (getpoint "\n圆心:"))
- '(0 0 1) ;_ 法线
- (getdist cp "\n半径:")
- )
- ;;圆心、半径创建圆
- (addcircle (setq cp (getpoint "\n圆心:")) (getdist cp "\n半径:"))
- ;;两点法创建圆
- (addcircle (setq p1 (getpoint "\n第一点:")) (getpoint p1 "\n第二点:"))
- ;;三点法画圆
- (addcircle (setq p1 (getpoint "\n第一点:")) (getpoint p1 "\n第二点:") (getpoint p1 "\n第三点:"))
|
|