![]() |
【转帖】自己写的坐标标注的程序 - 精华帖集合
自己写的坐标标注的程序 - 精华帖集合
www.dimcax.com 自己写的坐标标注的程序 using system; using autodesk.autocad.runtime; using autodesk.autocad.databaseservices; using autodesk.autocad.editorinput; using acadapp = autodesk.autocad.applicationservices.application; using autodesk.autocad.geometry; /// <summary> /// 标注坐标 /// </summary> [commandmethod("coorbiaozhu")] public void coorbiaozhu() { database db = hostapplicationservices.workingdatabase; editor ed = acadapp.documentmanager.mdiactivedocument.editor; promptdoubleoptions prodoubopt = new promptdoubleoptions("\n请输入标注字体高度"); prodoubopt.defaultvalue = 1; promptdoubleresult prodoubres = ed.getdouble(prodoubopt); if (prodoubres.status != promptstatus.ok) { return; } double m_textsize = prodoubres.value; promptpointoptions proptopt = new promptpointoptions("\n点击标注点"); promptpointresult proptres = ed.getpoint(proptopt); if (proptres.status != promptstatus.ok) { return; } point3d pt1 = new point3d(proptres.value.x, proptres.value.y, 0);//基点 proptopt.basepoint = pt1; proptopt.usebasepoint = true; proptopt.message = "\n选择方向点"; proptres = ed.getpoint(proptopt); if (proptres.status != promptstatus.ok) { return; } point3d pt2 = new point3d(proptres.value.x, proptres.value.y, 0); objectid tstid = objectid.null; transactionmanager tm = db.transactionmanager; using (transaction trans = tm.starttransaction()) { #region 加入字体 textstyletable tst = trans.getobject(db.textstyletableid, openmode.forwrite) as textstyletable; if (tst.has("宋体")) { tstid = db.textstyle = tst["宋体"]; } else { textstyletablerecord tstr = new textstyletablerecord(); tstr.name = "宋体"; tstr.textsize = m_textsize; tstr.filename = "宋体"; tstid = tst.add(tstr); trans.addnewlycreateddbobject(tstr, true); db.textstyle = tstid; } #endregion string strx = string.format("{0:f3}", pt1.x); string stry = string.format("{0:f3}", pt1.y); int strlength = strx.length > stry.length ? strx.length : stry.length; strx = strx.padleft(strlength, ' ');//使得x字符串与y字符串长度相等 stry = stry.padleft(strlength, ' ');//使得x字符串与y字符串长度相等 strx = "x=" + strx; stry = "y=" + stry; strlength += 2; dbtext dbtextx = new dbtext(); dbtext dbtexty = new dbtext(); dbtextx.height = m_textsize; dbtexty.height = m_textsize; dbtextx.textstring = strx; dbtexty.textstring = stry; dbtextx.textstyle = tstid; dbtexty.textstyle = tstid; //字宽 double width = dbtextx.geometricextents.maxpoint.x - dbtextx.geometricextents.minpoint.x; polyline pl = new polyline(); pl.addvertexat(0, new point2d(pt1.x, pt1.y), 0, 0, 0); pl.addvertexat(1, new point2d(pt2.x, pt2.y), 0, 0, 0); if (pt2.x - pt1.x >= 0) { pl.addvertexat(2, new point2d(pt2.x + width, pt2.y), 0, 0, 0); dbtextx.position = new point3d(pt2.x, pt2.y + m_textsize * 0.3, 0); dbtexty.position = new point3d(pt2.x, pt2.y - m_textsize * 1.3, 0); } else { pl.addvertexat(2, new point2d(pt2.x - width, pt2.y), 0, 0, 0); dbtextx.position = new point3d(pt2.x - width, pt2.y + m_textsize * 0.3, 0); dbtexty.position = new point3d(pt2.x - width, pt2.y - m_textsize * 1.3, 0); } blocktable bt = trans.getobject(db.blocktableid, openmode.forwrite) as blocktable; blocktablerecord btr = trans.getobject(bt["*model_space"], openmode.forwrite) as blocktablerecord; btr.appendentity(pl); btr.appendentity(dbtextx); btr.appendentity(dbtexty); trans.addnewlycreateddbobject(pl, true); trans.addnewlycreateddbobject(dbtextx, true); trans.addnewlycreateddbobject(dbtexty, true); trans.commit(); } } 复制代码 自己写的坐标标注的程序(附件) 附件 路漫漫其修远兮,吾将上下而求索! 楼主,正需要. 楼主,正需要. 支持,支持,俺也正在学习,虽然昨天被打击了 你让我滚我滚了,你让我回来,对不起滚远了 非常感谢~~ 非常感谢楼主的无私奉献~~ 非常感谢楼主的无私奉献~~ sadf 楼主!!!! 学习见解不少东西! |
所有的时间均为北京时间。 现在的时间是 11:11 PM. |