- UID
- 677263
- 积分
- 434
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-6-6
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
在网上看到不少XY坐标标注插件,lisp为多,objectarx比较少,我用objectarx写了一个放上来,与 大家交流一下。
- //根据相对极坐标来确定一个点的位置;
- static AcGePoint3d PolarPoint(const AcGePoint3d& pt, double angle, double distance)
- {
- ads_point ptForm, ptTo;
- ptForm[X] = pt[X];
- ptForm[Y] = pt[Y];
- ptForm[Z] = pt[Z];
- acutPolar(ptForm, angle, distance, ptTo);
- return asPnt3d(ptTo);
- }
- //XY坐标标注;
- static void zdqMyGroup_test () {
- // Put your command code here
- // 定义点接收用户选择点;
- ads_point adspt1;
- while(acedGetPoint(NULL,ACRX_T("\n选择标注点:"), adspt1)== RTNORM)
- {
- CString tx, ty, ts, txx, tyy, tp;
- tp=ACRX_T("\\P");
- tx=ACRX_T("X=");
- ty=ACRX_T("\\PY=");
- txx.Format(ACRX_T("%.3f"),adspt1[X]);//设置三位小数;
- tyy.Format(ACRX_T("%.3f"),adspt1[Y]);
- ACHAR stx[100], sty[100], strx[100],stry[100],sts[100],stp[100];
- _tcscpy(stp,tp);
- _tcscpy(stx,tx);
- _tcscpy(sty,ty);
- _tcscpy(strx,txx);
- _tcscpy(stry,tyy);
- AcGePoint3d point1, point2, point3;
- //将ads_point转为AcGePoint3d类型
- point1.set(adspt1[0],adspt1[1],0.0);
- point2.set(adspt1[0]+100.0,adspt1[1]+100.0,0.0); //这儿随便写;
- point3.set(adspt1[0]+1000.0,adspt1[1]+100.0,0.0);//这儿随便写;
- //获取模型空间块表记录,为了添加实体
- AcDbBlockTable *pBlockTable;
- acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
- AcDbBlockTableRecord *pBlockTableRecord;
- pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
- pBlockTable->close();
- //新建一个多行文字对象并添加到模型空间;
- AcDbObjectId mtextId, mtextId1;
- AcDbMText *pMtext = new AcDbMText();
- pMtext->setDatabaseDefaults () ;
- pMtext->setContents(_tcscat(_tcscat(stx,strx),_tcscat(sty,stry)));
- pMtext->setLocation (point2);
- pMtext->setTextHeight(500);//设置文字高度;
- if(point1[X]<=point2[X]){pMtext->setAttachment(AcDbMText::kMiddleLeft);}
- if(point1[X]>point2[X]){pMtext->setAttachment(AcDbMText::kMiddleRight);}
- pBlockTableRecord->appendAcDbEntity(mtextId, pMtext);
- double lo=pMtext->actualWidth();
- pMtext->close();
- //新建一个多行文字对象并添加到模型空间;
- AcDbMText *pMtext1 = new AcDbMText();
- pMtext1->setDatabaseDefaults () ;
- pMtext1->setContents(ACRX_T("X=\\PY="));
- pMtext1->setLocation (point2);
- pMtext1->setTextHeight(500);
- pBlockTableRecord->appendAcDbEntity(mtextId1, pMtext1);
- pMtext1->close();
- //新建一个引线对象并添加到模型空间;
- AcDbObjectId leaderId;
- AcDbLeader *pLeader = new AcDbLeader();
- pLeader->appendVertex(point1);
- pLeader->appendVertex(point2);
- pLeader->appendVertex(point3);
- pLeader->setDatabaseDefaults(curDoc()->database());
- pBlockTableRecord->appendAcDbEntity(leaderId, pLeader);
- pBlockTableRecord->close();
- pLeader->close();
- //放置多行文字
- AcDbMText *pText,*pMext;AcDbLeader *pLea;
- AcDbEntity *pEnt,*pEntm,*pEn;
- acedPrompt(_T("\n选择放置点:"));
- AcGePoint3d ptInsertNew(0, 0, 0);
- // 鼠标拖动部分;
- int track = 1, type; //track=1
- struct resbuf result; // 保存鼠标拖动时的动态坐标;
- while (track > 0)
- {
- acedGrRead(track, &type, &result); // 追踪光标移动;
- ptInsertNew[X] = result.resval.rpoint[X];
- ptInsertNew[Y] = result.resval.rpoint[Y];
- // 设置拖动位置为直线的终点坐标;
- acdbOpenObject(pEnt, mtextId, AcDb::kForWrite);
- acdbOpenObject(pEntm, mtextId1, AcDb::kForWrite);
- acdbOpenObject(pEn, leaderId, AcDb::kForWrite);
- if (pEnt->isKindOf(AcDbMText::desc()))
- {
- pMext = AcDbMText::cast(pEntm);
- pText = AcDbMText::cast(pEnt);
- pLea = AcDbLeader::cast(pEn);
- if (pText != NULL)
- {
- _tcscpy(stp,tp);
- _tcscpy(strx,txx);
- _tcscpy(stry,tyy);
- pText->setContents(_tcscat(_tcscat(strx,stp),stry));
- if(point1[X]<=ptInsertNew[X])
- {
- pMext->setLocation(ptInsertNew);
- pMext->setAttachment(AcDbMText::kMiddleLeft);
- pText->setLocation(PolarPoint(ptInsertNew,0,lo));
- pText->setAttachment(AcDbMText::kMiddleRight);
- }
- if(point1[X]>ptInsertNew[X])
- {
- pMext->setLocation(PolarPoint(ptInsertNew,-3.1415926535897932384626433832795,lo));
- pMext->setAttachment(AcDbMText::kMiddleLeft);
- pText->setLocation(ptInsertNew);
- pText->setAttachment(AcDbMText::kMiddleRight);
- }
- pLeader->setVertexAt(0,point1);
- pLeader->setVertexAt(1,ptInsertNew);
- if(point1[X]<=ptInsertNew[X]){pLea->setVertexAt(2, PolarPoint(ptInsertNew,0,lo));}
- if(point1[X]>ptInsertNew[X]){pLea->setVertexAt(2, PolarPoint(ptInsertNew,-3.1415926535897932384626433832795,lo));}
- }
- }
- pEnt->close();pEn->close();pEntm->close();
- if (type == 3) // 如果用户按下了鼠标左键;
- {
- track = 0;
- }
- }
- }
- }
- //注册命令;
- ACED_ARXCOMMAND_ENTRY_AUTO(CtestApp, zdqMyGroup, _test, test, ACRX_CMD_MODAL, NULL)
这段代码生成的标注不是一个整体,由两个多行文字和一个引线组成,虽然在绘制过程可以整体拖动预览,一旦生成就不能整体拖动,这是一个缺憾!
|
评分
-
查看全部评分
|