![]() |
【转帖】利用vb写的随鼠标移动的图形
利用vb写的随鼠标移动的图形
www.dimcax.com 利用vb写的随鼠标移动的图形 imports autodesk.autocad.runtime imports autodesk.autocad.applicationservices imports autodesk.autocad.editorinput imports autodesk.autocad.geometry imports autodesk.autocad.interop imports autodesk.autocad.interop.common public class class1 <commandmethod("mtest")> _ public sub test() dim ed as editor = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor dim sd as new motionalmousepoint addhandler ed.pointfilter, addressof sd.getmousepoint dim pro as promptpointoptions = new promptpointoptions("请选择插入点...") ed.getpoint(pro) removehandler ed.pointfilter, addressof sd.getmousepoint end sub end class public class motionalmousepoint private mousepoint as point3d = new point3d(0, 0, 0) '保存当前鼠标位置 ''动态获取鼠标位置 public sub getmousepoint(byval sender as object, byval e as pointfiltereventargs) mousepoint = e.context.computedpoint dim m_ed as editor = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor delegatetest(mousepoint, addressof objectmove2mouse) end sub delegate sub mathoperator(byval pt as point3d) sub delegatetest(byval pt as point3d, byval op as mathoperator) op.invoke(pt) end sub public sub objectmove2mouse(byval pt as point3d) dim acadapp as acadapplication = ctype(application.acadapplication, acadapplication) dim acaddoc as acaddocument = acadapp.activedocument try static blnfirst as boolean = false static blnfst as boolean = false static objtem(2) as acadobject dim cirobj as acadcircle dim center(2) as double dim radius as double dim lineobj as acadline dim spnt(2), epnt(2) as double dim textobj as acadtext dim istpoint(2) as double center(0) = pt(0) + 0 : center(1) = pt(1) + 0 : center(2) = pt(2) + 0 : radius = 50 spnt(0) = center(0) : spnt(1) = center(1) : spnt(2) = 0 epnt(0) = center(0) + 100 : epnt(1) = center(1) + 100 : epnt(2) = 0 istpoint(0) = center(0) : istpoint(1) = center(1) : istpoint(2) = center(2) if blnfirst = true then for i as integer = 0 to 2 objtem(i).delete() '删除上次绘制的对象 next cirobj = acaddoc.modelspace.addcircle(center, radius) '创建一个圆对象 cirobj.color = acad_color.acred '将圆的颜色设为红色 lineobj = acaddoc.modelspace.addline(spnt, epnt) '创建一条直线 lineobj.lineweight = acad_lweight.aclnwt060 textobj = acaddoc.modelspace.addtext("哈!成了。", istpoint, 15) '创建单行文字 textobj.color = acad_color.acwhite objtem(0) = cirobj objtem(1) = lineobj objtem(2) = textobj else cirobj = acaddoc.modelspace.addcircle(center, radius) '创建一个圆对象 cirobj.color = acad_color.acred '将圆的颜色设为红色 lineobj = acaddoc.modelspace.addline(spnt, epnt) '创建一条直线 lineobj.lineweight = acad_lweight.aclnwt060 textobj = acaddoc.modelspace.addtext("哈!成了。", istpoint, 15) '创建单行文字 textobj.color = acad_color.acwhite objtem(0) = cirobj objtem(1) = lineobj objtem(2) = textobj blnfirst = true end if catch ex as exception end try end sub end class 回复:(scs5999)利用vb写的随鼠标移动的图形加入鼠标事件方法值得借鉴,但采用不断加入数据库对象、再不断删除的方法来实现动态显示的方法不可取 |
所有的时间均为北京时间。 现在的时间是 08:06 PM. |