如何实时动态取得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> 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按下鼠标左键退出...");
}
<P>或有这个函数也可以。</P>
<P>将屏幕点转化为CAD下的点。</P>
<P>VB开发CAD2007有这个函数,但我用的CAD2006没有。请问大家有没有别的函数可以实现?</P>
<P>如CAD2007开发用的函数:ed.pointtoworld(new point(e.x,e.y))</P> 用API函数此问题已解决。谢谢才鸟兄。 <P>Public Class ArxApi<BR> <System.Runtime.InteropServices.DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, entrypoint:="<A href="mailto:?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z" target="_blank" >?acedCoordFromPixelToWorld@@YAHHVCPoint@@QAN@Z</A>")> _<BR> Public Shared Function acedCoordFromPixelToWorld(ByVal viewportNumber As Integer, ByVal pixel As System.Drawing.Point, ByRef point As Point3d) As Boolean<BR> '''<BR> '''<BR> End Function</P>
<P> '''<BR> <System.Runtime.InteropServices.DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, entrypoint:="<A href="mailto:?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z" target="_blank" >?acedCoordFromWorldToPixel@@YAHHQBNAAVCPoint@@@Z</A>")> _<BR> Public Shared Function acedCoordFromWorldToPixel(ByVal viewportNumber As Integer, ByVal worldPt As Point3d, ByRef pixel As System.Drawing.Point) As Boolean<BR> '''<BR> '''<BR> End Function</P>
<P> '''<BR>End Class</P> 屏幕点是怎么得到的? <P>mouseup 事件中得到</P> 可以用吗? 本帖最后由 作者 于 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 <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;"> 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;"> <CommandMethod("mtest")> _</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;"> Public 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;"> 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;"> 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;"> 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;"> <span style="mso-spacerun: yes;"> 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;"> 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;"> End 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;"> ''</span>动态获取鼠标位置<span lang="EN-US"><span style="mso-spacerun: yes;"> </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;"> Private Sub GetMousePoint(ByVal sender As 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;"> 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;"> 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;"> m_ed.WriteMessage("</span>当前鼠标位置<span lang="EN-US">:<span style="mso-spacerun: yes;"> "</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;"> End Sub</span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none;">End <span style="COLOR: blue;">Class</span></p> 好样的。
页:
[1]
2