![]() |
【转帖】老才,如果会编就编一个让大家欣赏一下你的才能!
老才,如果会编就编一个让大家欣赏一下你的才能!
www.dimcax.com 老才,如果会编就编一个让大家欣赏一下你的才能! 图形随鼠标移动的程序编写,用c# 已经有一个块名为mybtr,块内已经添加了如线、圆等实体。我想实现这样的功能,当鼠标在autocad 用动态块吧 用动态块,然后用i插入即可。 还用老才亲自出马?我来告诉你 <commandmethod("mm")> _ public sub movetermline() try objarraylist.clear() dim caddoc as acaddocument = cadmgr.joincad_doc if caddoc.readonly = true then caddoc.sendcommand("此文件为只读文件,不能执行此操作") exit sub end if dim ptresult as promptpointresult = cadmgr.getpt() if ptresult is nothing then exit sub end if dim pt1(0 to 2) as double pt1(0) = ptresult.value.x : pt1(1) = ptresult.value.y : pt1(2) = ptresult.value.z dim otherpt as object = cadmgr.getbotherpt(pt1) if otherpt is nothing then exit sub end if dim sset as acadselectionset try sset = caddoc.selectionsets.add("movedwg") catch sset = caddoc.selectionsets.item("movedwg") sset.delete() sset = caddoc.selectionsets.add("movedwg") end try dim mode as acselect = acselect.acselectionsetcrossing sset.select(mode, pt1, otherpt) for each ent in sset objarraylist.add(ent) ent.highlight(true) next moveterml() catch ex as system.exception utility.showerrormessage("移动失败") end try end sub '移动端子排 dim withevents ed as editor dim objarraylist as new arraylist dim ent as object dim ptstar1(0 to 2) as double public sub moveterml() dim ptresult as promptpointresult = cadmgr.getpt() if ptresult is nothing then for each ent in objarraylist ent.highlight(false) next exit sub end if ptstar1(0) = ptresult.value.x : ptstar1(1) = ptresult.value.y : ptstar1(2) = ptresult.value.z ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor dim db as database = hostapplicationservices.workingdatabase dim m_ppo as promptpointoptions = new promptpointoptions("\n请选择移动的坐标") autodesk.autocad.applicationservices.application.updatescreen() dim m_ppr as promptpointresult = ed.getpoint(m_ppo) for each ent in objarraylist ent.highlight(false) next ed = nothing end sub private sub ed_pointfilter(byval sender as object, byval e as autodesk.autocad.editorinput.pointfiltereventargs) handles ed.pointfilter dim dypoint as autodesk.autocad.geometry.point3d = e.context.computedpoint '//转换动态点 dim pt(0 to 2) as double pt(0) = dypoint.x pt(1) = dypoint.y pt(2) = dypoint.z for each ent in objarraylist ent.move(ptstar1, pt) ent.highlight(true) next ptstar1 = pt end sub 还有cadmgr模块下面的三个方法,补上 ''' <summary> ''' 请选择一个点 ''' </summary> public function getpt() as promptpointresult dim prpointoptions as promptpointoptions = new promptpointoptions("请选择一个点") dim prpointres as promptpointresult dim ed as editor = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor try prpointres = ed.getpoint(prpointoptions) getpt = prpointres if prpointres.status <> promptstatus.ok then return nothing end if catch return nothing end try end function ''' <summary> ''' 画一条直线,并返加未点的坐标 ''' </summary> ''' <param name="ptinsert">直线的第一点</param> public function getotherpt(byval ptinsert as object) as object try joincad() getotherpt = acaddoc.utility.getpoint(ptinsert, "请输入另一点: ") catch getotherpt = nothing end try end function public function joincad_doc() as acaddocument ' 连接至 autocad 应用程序 try ' 可能导致异常的代码 acadapp = getobject(, "autocad.application.17") 'if acadapp.visible = false then ' acadapp.quit() 'end if catch ' 当异常发生时处理异常的代码 try acadapp = createobject("autocad.application.17") catch utility.showwarningmessage(err.description) joincad_doc = nothing exit function end try finally ' 清理现场 end try ' 连接至 autocad 图形 acaddoc = acadapp.activedocument joincad_doc = acaddoc end function 上面的getotherpt应为下面这个方法,传错了 ''' <summary> ''' 画一矩形,并返加未点的坐标 ''' </summary> ''' <param name="ptinsert">矩形的第一点</param> public function getbotherpt(byval ptinsert as object) as object try getbotherpt = acaddoc.utility.getcorner(ptinsert, "请输入另一点:") catch getbotherpt = nothing end try end function 看来顶一下真有用 看来顶一下真有用!马上就有人出手了。 这个问题我已经解决了 这个问题我已经解决了,用entityjig实现的,就不必老才了,他也不一定会。 也不必向houlinbo那么麻烦 原帖由 tbeahgl 于 这个问题我已经解决了,用entityjig实现的,就不必老才了,他也不一定会。 jig的东西是不太熟悉 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 插入一个块 public class blockoperatorjig : drawjig { #region private member fields private point3d previouscursorposition; private point3d currentcursorposition; private blockreference entitytodrag; #endregion [commandmethod("insertblock")] public void insertblock() { //initialize cursor position //use the geometry library to create a new 3d point object editor ed = application.documentmanager.mdiactivedocument.editor; promptresult pr = ed.getstring("输入插入块名称"); if (pr.status == promptstatus.ok) { previouscursorposition = new point3d (0,0,0); autodesk.autocad.databaseservices.database db = application.documentmanager.mdiactivedocument.database; autodesk.autocad.databaseservices.transactionmanager tm = db.transactionmanager; using (transaction ts = tm.starttransaction()) { blocktable bt = (blocktable)tm.getobject(db.blocktableid,openmode.forread); if (bt.has(pr.stringresult)) { objectid id = bt[pr.stringresult]; //blocktodrag = (blocktablerecord)ts.getobject(id, openmode.forwrite); entitytodrag = new blockreference(new point3d(0, 0, 0), id); ed.drag(this); entitytodrag.position = currentcursorposition; blocktablerecord btr = (blocktablerecord)tm.getobject(bt[blocktablerecord.modelspace], openmode.forwrite, false); btr.appendentity((entity)entitytodrag); tm.addnewlycreateddbobject((entity)entitytodrag, true); ts.commit(); } } } } //you must override this method protected override samplerstatus sampler(jigprompts prompts) { //get the current cursor position promptpointresult userfeedback = prompts.acquirepoint(); currentcursorposition = userfeedback.value; if (cursorhasmoved()) { //get the vector of the move vector3d displacementvector = previouscursorposition.getvectorto(currentcursorposition); //transform the circle to the new location entitytodrag.transformby(matrix3d.displacement(displacementvector)); //save the cursor position previouscursorposition = currentcursorposition; return samplerstatus.ok; } else { return samplerstatus.nochange; } } //you must override this method protected override bool worlddraw(autodesk.autocad.graphicsinterface.worlddraw draw) { draw.geometry.draw(entitytodrag); return true; } private bool cursorhasmoved() { return !(currentcursorposition == previouscursorposition); } } 1 |
所有的时间均为北京时间。 现在的时间是 06:08 PM. |