tcsl9621 发表于 2006-8-27 21:46:00

如何实时动态取得CAD下光标的位置?

<DIV style="FONT-SIZE: 12px">如何实时动态取得CAD下光标的位置?</DIV>
<DIV style="FONT-SIZE: 12px">此功能有没有人知道是什么命令?(VBA,VB.net,C#,或读CAD系统参数都可以)</DIV>
<DIV style="FONT-SIZE: 12px">请知道的朋友告诉我。谢了!!!</DIV>

mkhsj929 发表于 2006-10-18 23:46:00

      private static Point3d m_MousePoint = new Point3d(0, 0, 0);//保存当前鼠标位置
      
      public void test()
      {
            Editor m_ed = Application.DocumentManager.MdiActiveDocument.Editor;
            m_ed.PointFilter+=new PointFilterEventHandler(m_GetMousePoint);
            PromptPointOptionsm_pko = new PromptPointOptions("\n按左键退出...");
            PromptPointResult m_ppr = m_ed.GetPoint(m_pko);
            if (m_ppr.Status == PromptStatus.OK)
            {
                m_ed.PointFilter -= new PointFilterEventHandler(m_GetMousePoint);
            }
      }
      //动态获取鼠标位置
      void m_GetMousePoint(object sender, PointFilterEventArgs e)
      {
            //throw new System.Exception("The method or operation is not implemented.");
            m_MousePoint = e.Context.ComputedPoint;
            Editor m_ed = Application.DocumentManager.MdiActiveDocument.Editor;
            m_ed.WriteMessage("\n当前鼠标位置:" + m_MousePoint + "\t按下鼠标左键退出...");
      }

tcsl9621 发表于 2006-8-29 19:35:00

<P>或有这个函数也可以。</P>
<P>将屏幕点转化为CAD下的点。</P>
<P>VB开发CAD2007有这个函数,但我用的CAD2006没有。请问大家有没有别的函数可以实现?</P>
<P>如CAD2007开发用的函数:ed.pointtoworld(new point(e.x,e.y))</P>

tcsl9621 发表于 2006-8-31 22:02:00

用API函数此问题已解决。谢谢才鸟兄。

tcsl9621 发表于 2006-9-10 22:30:00

<P>Public Class ArxApi<BR>&nbsp;&nbsp;&nbsp; &lt;System.Runtime.InteropServices.DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, entrypoint:="<A href="mailto:?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z" target="_blank" >?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z</A>")&gt; _<BR>&nbsp;&nbsp;&nbsp; Public Shared Function acedCoordFromPixelToWorld(ByVal viewportNumber As Integer, ByVal pixel As System.Drawing.Point, ByRef point As Point3d) As Boolean<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''<BR>&nbsp;&nbsp;&nbsp; End Function</P>
<P>&nbsp;&nbsp;&nbsp; '''<BR>&nbsp;&nbsp;&nbsp; &lt;System.Runtime.InteropServices.DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, entrypoint:="<A href="mailto:?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z" target="_blank" >?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z</A>")&gt; _<BR>&nbsp;&nbsp;&nbsp; Public Shared Function acedCoordFromWorldToPixel(ByVal viewportNumber As Integer, ByVal worldPt As Point3d, ByRef pixel As System.Drawing.Point) As Boolean<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''<BR>&nbsp;&nbsp;&nbsp; End Function</P>
<P>&nbsp;&nbsp;&nbsp; '''<BR>End Class</P>

sailor538 发表于 2006-11-6 14:46:00

屏幕点是怎么得到的?

tcsl9621 发表于 2006-11-7 10:41:00

<P>mouseup 事件中得到</P>

18hzt 发表于 2007-4-20 14:22:00

可以用吗?

scs5999 发表于 2007-5-6 17:20:00

本帖最后由 作者 于 2007-5-6 17:23:51 编辑 <br /><br /> <p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">Imports Autodesk.AutoCAD.Runtime</p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">Imports Autodesk.AutoCAD.Geometry</p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">Imports Autodesk.AutoCAD.EditorInput</p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">Public&nbsp;<span style="COLOR: blue;">Class Class1</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp; Private MousePoint As Point3d = New Point3d(0, 0, 0) '</span>保存当前鼠标位置</p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; &lt;CommandMethod("mtest")&gt; _</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Public&nbsp;&nbsp;Sub test()</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddHandler ed.PointFilter, AddressOf GetMousePoint</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim pro As PromptPointOptions = New PromptPointOptions("</span>按左键退出<span lang="EN-US">..."</span>)</p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">&nbsp;<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ed.GetPoint(pro)</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RemoveHandler ed.PointFilter, AddressOf GetMousePoint</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; End&nbsp;Sub<p></p></span></p><p></p><p></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; ''</span>动态获取鼠标位置<span lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp;</span></span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span lang="EN-US"></span><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; Private&nbsp;Sub GetMousePoint(ByVal sender As&nbsp;Object, ByVal e As PointFilterEventArgs)</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MousePoint = e.Context.ComputedPoint</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim m_ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_ed.WriteMessage("</span>当前鼠标位置<span lang="EN-US">:<span style="mso-spacerun: yes;">&nbsp; "</span></span> + vbLf + <span style="COLOR: maroon;">"X=" + MousePoint.X.ToString + vbLf + "Y=" + MousePoint.X.ToString + vbLf + "Z=" + MousePoint.Z.ToString + vbLf)</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; End&nbsp;Sub</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">End&nbsp;<span style="COLOR: blue;">Class</span></p>

tcsl9621 发表于 2007-6-9 00:54:00

好样的。
页: [1] 2
查看完整版本: 如何实时动态取得CAD下光标的位置?