anston 发表于 2005-9-9 08:43:00

[求助]关于拾取点获得点坐标

<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>

pqs001 发表于 2005-9-9 09:56:00

可以到xdcad.net上面翻翻置顶的例子

uusky 发表于 2005-9-9 19:27:00

<P>给你个参考</P>
<P>void&nbsp; iterate(AcDbObjectId plineId)<BR>{&nbsp; //遍历多义线的顶点&nbsp; 并且打印出每个顶点的坐标<BR>&nbsp;AcDb2dPolyline *pPline;<BR>&nbsp;acdbOpenObject(pPline,plineId,AcDb::kForRead);</P>
<P>&nbsp;AcDbObjectIterator*pVertIter = pPline-&gt;vertexIterator();<BR>&nbsp;pPline-&gt;close();</P>
<P>&nbsp;AcDb2dVertex *pVertex;<BR>&nbsp;AcGePoint3d&nbsp; location;<BR>&nbsp;AcDbObjectId&nbsp; vertexObjId;</P>
<P>&nbsp;for(int&nbsp; vertexNumber=0;!pVertIter-&gt;done();<BR>&nbsp;&nbsp; vertexNumber++,pVertIter-&gt;step())<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; vertexObjId=pVertIter-&gt;objectId();<BR>&nbsp;&nbsp;&nbsp; acdbOpenObject(pVertex,vertexObjId,AcDb::kForRead);</P>
<P>&nbsp;&nbsp;&nbsp; location=pVertex-&gt;position();<BR>&nbsp;&nbsp;&nbsp; pVertex-&gt;close();</P>
<P>&nbsp;&nbsp;&nbsp; acutPrintf("\n顶点 # %d的位置为:%0.3f,%0.3f,%0.3f",vertexNumber,<BR>&nbsp;&nbsp;&nbsp;&nbsp; location,location,location);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; delete pVertIter;<BR>}</P>

zyxc1981 发表于 2005-9-9 20:43:00

<P>`~</P>
<P>帮你顶</P>

anston 发表于 2005-9-11 11:10:00

<P>谢谢楼上几位,我先研究一下</P>
<P>过几天报告研究结果^_^</P>

anston 发表于 2005-9-16 10:26:00

<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>&nbsp;CPickPointApp () : AcRxArxApp () {}</P>
<P>&nbsp;virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<BR>&nbsp;&nbsp;AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;<BR>&nbsp;&nbsp;// TODO: Add your initialization code here</P>
<P>&nbsp;&nbsp;return (retCode) ;<BR>&nbsp;}</P>
<P>&nbsp;virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {<BR>&nbsp;&nbsp;AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;<BR>&nbsp;&nbsp;// TODO: Add your code here</P>
<P>&nbsp;&nbsp;return (retCode) ;<BR>&nbsp;}</P>
<P>&nbsp;virtual void RegisterServerComponents () {<BR>&nbsp;}</P>
<P><BR>&nbsp;// ----- lemonPickPoint.pp command (do not rename)<BR>&nbsp;static void lemonPickPointpp(void)<BR>&nbsp;{<BR>&nbsp;&nbsp;// Add your code for command lemonPickPoint.pp here<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;ads_point pt;<BR>&nbsp;&nbsp;int NodeNumCount;&nbsp; //定义节点数,即最大的节点编号数值<BR>&nbsp;&nbsp;acedGetInt("Please input the node number:",&amp;NodeNumCount);<BR>&nbsp;&nbsp;for(int i=0;i&lt;NodeNumCount;i++)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(acedGetPoint(NULL,"\nPick a point:",pt)==RTNORM)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xpt.Format("%g",pt); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ypt.Format("%g",pt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("\nThe coordinates of the point is:%s,%s",xpt,ypt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;_ConnectionPtr m_pConnection;<BR>&nbsp;&nbsp;AfxOleInit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HRESULT hr;<BR>&nbsp;<BR>&nbsp;&nbsp;hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象<BR>&nbsp;&nbsp;if(SUCCEEDED(hr))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hr = m_pConnection-&gt;Open("Provider=SQLOLEDB;Data Source=CZQDAY;User ID=sa;Password=820306;Initial Catalog=TOSHIBA1","","",adModeUnknown);///连接数据库<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; try<BR>&nbsp;&nbsp;{&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _variant_t varProjectID,varID,varx,vary;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i=0;i&lt;NodeNumCount;i++)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;atof(xpt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;atof(ypt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;varProjectID = "as001";<BR>&nbsp;&nbsp;&nbsp;&nbsp;varID = i+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; varx = xpt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vary = ypt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _RecordsetPtr t_pRecordset;<BR>&nbsp;&nbsp;&nbsp;&nbsp;t_pRecordset.CreateInstance("ADODB.Recordset");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;Open("SELECT * FROM xy",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;MoveFirst();<BR>&nbsp;&nbsp;&nbsp;&nbsp;t_pRecordset-&gt;AddNew();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;PutCollect("ProjectID",varProjectID);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;PutCollect("id",varID);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;PutCollect("x",varx);<BR>&nbsp;&nbsp;&nbsp;&nbsp;t_pRecordset-&gt;PutCollect("y",vary);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_pRecordset-&gt;Update();//只有写了这句才能刷新数据库!!<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;//Refresh();//只有运行这个函数,才能保存成功<BR>&nbsp;&nbsp;&nbsp;&nbsp;t_pRecordset-&gt;Close();&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch(_com_error e)///捕捉异常<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AfxMessageBox("保存不成功!");///显示错误信息<BR>&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //更改数据类型,CString-&gt;float<BR>&nbsp;&nbsp;for (int j=0;j&lt;NodeNumCount;j++)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;xco=atof(xpt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yco=atof(ypt);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //pick点,连续画直线<BR>&nbsp;&nbsp;AcDbBlockTableRecord *pBlkTableRcd<BR>&nbsp;&nbsp;&nbsp;=new AcDbBlockTableRecord();//创建块表记录<BR>&nbsp;&nbsp;//以写方式得到当前块表的指针<BR>&nbsp;&nbsp;AcDbBlockTable *pBlkTable=NULL;&nbsp;<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;getSymbolTable(pBlkTable, AcDb::kForWrite);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //将新的块表记录加入块表中,并获得块表记录的ID<BR>&nbsp;&nbsp;AcDbObjectId Id;<BR>&nbsp;&nbsp;pBlkTable-&gt;add(Id, pBlkTableRcd);<BR>&nbsp;&nbsp;pBlkTable-&gt;close();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int k=0;k&lt;NodeNumCount;k++)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//生成直线<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint3d startPt(xco,yco,0.0);//定义直线起点<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint3d endPt(xco,yco,0.0);//定义直线终点<BR>&nbsp;&nbsp;&nbsp;AcDbLine *pLine=new AcDbLine(startPt,endPt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbBlockTable *pBlkTable2=NULL;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;getSymbolTable(pBlkTable2, AcDb::kForRead);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBlkTable2-&gt;getAt(ACDB_MODEL_SPACE, pBlkTableRcd,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDb::kForWrite);<BR>&nbsp;&nbsp;&nbsp;pBlkTable2-&gt;close();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId lineId;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBlkTableRcd-&gt;appendAcDbEntity(lineId, pLine);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLine-&gt;setLayer("Layer_Frame");//设置创建轮廓线的层为"Layer_Frame"<BR>&nbsp;&nbsp;&nbsp;pLine-&gt;close();<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;pBlkTableRcd-&gt;close();</P>
<P><BR>&nbsp;}</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>

pglyxq 发表于 2005-9-18 13:01:00

页: [1]
查看完整版本: [求助]关于拾取点获得点坐标