[求助]关于拾取点获得点坐标
<P>在ARX中<BR>1.如何通过pick图形上的点获得点坐标<BR>2.如何通过pick图形上的直线获得两端endpoint的坐标和中点midpoint的坐标</P><P>关于第一个问题我选择了acedGetPoint()<BR>但是根据函数定义<BR>int acedGetPoint(<BR>const ads_point pt,<BR>const char *prompt,<BR>ads_point result);<BR>这个函数返回RTNORM等值(这类值是否是整形的?)<BR>函数说明中说该函数将pt与result认为三维点,那么ads_point类型与AcGePoint3d这种类型有什么区别?<BR>是否能通过该函数输出pick的点的三维坐标,如果可以的话使用哪个参数输出,类型上需要如何转换?</P>
<P>关于第二个问题我查了一下<BR>有如下几个函数<BR>AcGePoint3d endPoint() const;<BR>AcGePoint3d midPoint() const;<BR>acedGetPoint()</P>
<P>为了达到我的要求应该选用哪几个函数?能否提供一小段代码让我研究一下</P>
<P>谢谢<BR></P> 可以到xdcad.net上面翻翻置顶的例子 <P>给你个参考</P>
<P>void iterate(AcDbObjectId plineId)<BR>{ //遍历多义线的顶点 并且打印出每个顶点的坐标<BR> AcDb2dPolyline *pPline;<BR> acdbOpenObject(pPline,plineId,AcDb::kForRead);</P>
<P> AcDbObjectIterator*pVertIter = pPline->vertexIterator();<BR> pPline->close();</P>
<P> AcDb2dVertex *pVertex;<BR> AcGePoint3d location;<BR> AcDbObjectId vertexObjId;</P>
<P> for(int vertexNumber=0;!pVertIter->done();<BR> vertexNumber++,pVertIter->step())<BR> {<BR> vertexObjId=pVertIter->objectId();<BR> acdbOpenObject(pVertex,vertexObjId,AcDb::kForRead);</P>
<P> location=pVertex->position();<BR> pVertex->close();</P>
<P> acutPrintf("\n顶点 # %d的位置为:%0.3f,%0.3f,%0.3f",vertexNumber,<BR> location,location,location);<BR> }<BR> delete pVertIter;<BR>}</P> <P>`~</P>
<P>帮你顶</P> <P>谢谢楼上几位,我先研究一下</P>
<P>过几天报告研究结果^_^</P> <P>报告一下我的学习成果</P>
<P>我用ObjectARX Project写了如下的代码</P>
<P>实现的功能是在当前绘图中pick点,将点坐标存在SQL Server数据库中的同时将pick的点顺序连线</P>
<P>此代码编译通过且加载ARX后实现预期功能</P>
<P>但在关闭AutoCAD时,无论选择是否保存都会导致AutoCAD非正常退出(保存能成功)</P>
<P>请帮我看看这段程序的bug在哪里,帮我完善一下,谢谢</P>
<P>#include "StdAfx.h"<BR></P>
<P>CString xpt;<BR>CString ypt;<BR>float xco;<BR>float yco;<BR>//-----------------------------------------------------------------------------<BR>#define szRDS _RXST("lemon")</P>
<P>//-----------------------------------------------------------------------------<BR>//----- ObjectARX EntryPoint<BR>class CPickPointApp : public AcRxArxApp {</P>
<P>public:<BR> CPickPointApp () : AcRxArxApp () {}</P>
<P> virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<BR> AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;<BR> // TODO: Add your initialization code here</P>
<P> return (retCode) ;<BR> }</P>
<P> virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {<BR> AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;<BR> // TODO: Add your code here</P>
<P> return (retCode) ;<BR> }</P>
<P> virtual void RegisterServerComponents () {<BR> }</P>
<P><BR> // ----- lemonPickPoint.pp command (do not rename)<BR> static void lemonPickPointpp(void)<BR> {<BR> // Add your code for command lemonPickPoint.pp here<BR> <BR> ads_point pt;<BR> int NodeNumCount; //定义节点数,即最大的节点编号数值<BR> acedGetInt("Please input the node number:",&NodeNumCount);<BR> for(int i=0;i<NodeNumCount;i++)<BR> {<BR> if(acedGetPoint(NULL,"\nPick a point:",pt)==RTNORM)<BR> {<BR> xpt.Format("%g",pt); <BR> ypt.Format("%g",pt);<BR> acutPrintf("\nThe coordinates of the point is:%s,%s",xpt,ypt);<BR> }<BR> }</P>
<P> _ConnectionPtr m_pConnection;<BR> AfxOleInit();<BR> HRESULT hr;<BR> <BR> hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象<BR> if(SUCCEEDED(hr))<BR> {<BR> hr = m_pConnection->Open("Provider=SQLOLEDB;Data Source=CZQDAY;User ID=sa;Password=820306;Initial Catalog=TOSHIBA1","","",adModeUnknown);///连接数据库<BR> }<BR> <BR> try<BR> { <BR> _variant_t varProjectID,varID,varx,vary;<BR> for(int i=0;i<NodeNumCount;i++) <BR> {<BR> atof(xpt);<BR> atof(ypt);<BR> varProjectID = "as001";<BR> varID = i+1;<BR> varx = xpt;<BR> vary = ypt;<BR> _RecordsetPtr t_pRecordset;<BR> t_pRecordset.CreateInstance("ADODB.Recordset");<BR> t_pRecordset->Open("SELECT * FROM xy",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);<BR> t_pRecordset->MoveFirst();<BR> t_pRecordset->AddNew();<BR> t_pRecordset->PutCollect("ProjectID",varProjectID);<BR> t_pRecordset->PutCollect("id",varID);<BR> t_pRecordset->PutCollect("x",varx);<BR> t_pRecordset->PutCollect("y",vary);<BR> t_pRecordset->Update();//只有写了这句才能刷新数据库!!<BR> <BR> //Refresh();//只有运行这个函数,才能保存成功<BR> t_pRecordset->Close(); <BR> }<BR> }<BR> catch(_com_error e)///捕捉异常<BR> {<BR> AfxMessageBox("保存不成功!");///显示错误信息<BR> }</P>
<P> //更改数据类型,CString->float<BR> for (int j=0;j<NodeNumCount;j++)<BR> {<BR> xco=atof(xpt);<BR> yco=atof(ypt);<BR> }</P>
<P> //pick点,连续画直线<BR> AcDbBlockTableRecord *pBlkTableRcd<BR> =new AcDbBlockTableRecord();//创建块表记录<BR> //以写方式得到当前块表的指针<BR> AcDbBlockTable *pBlkTable=NULL; <BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlkTable, AcDb::kForWrite);<BR> //将新的块表记录加入块表中,并获得块表记录的ID<BR> AcDbObjectId Id;<BR> pBlkTable->add(Id, pBlkTableRcd);<BR> pBlkTable->close();</P>
<P> for(int k=0;k<NodeNumCount;k++)<BR> {<BR> //生成直线<BR> AcGePoint3d startPt(xco,yco,0.0);//定义直线起点<BR> AcGePoint3d endPt(xco,yco,0.0);//定义直线终点<BR> AcDbLine *pLine=new AcDbLine(startPt,endPt);<BR> AcDbBlockTable *pBlkTable2=NULL;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlkTable2, AcDb::kForRead);</P>
<P> pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlkTableRcd,<BR> AcDb::kForWrite);<BR> pBlkTable2->close();</P>
<P> AcDbObjectId lineId;<BR> pBlkTableRcd->appendAcDbEntity(lineId, pLine);<BR> pLine->setLayer("Layer_Frame");//设置创建轮廓线的层为"Layer_Frame"<BR> pLine->close();<BR> }<BR> pBlkTableRcd->close();</P>
<P><BR> }</P>
<P><BR>} ;</P>
<P>//-----------------------------------------------------------------------------<BR>IMPLEMENT_ARX_ENTRYPOINT(CPickPointApp)</P>
<P>ACED_ARXCOMMAND_ENTRY_AUTO(CPickPointApp, lemonPickPoint, pp, pp, ACRX_CMD_TRANSPARENT, NULL)</P>
页:
[1]