![]() |
自己写的一个根据polyline生成顶点坐标表格的程序,含源代码。 - 精华帖集合
自己写的一个根据polyline生成顶点坐标表格的程序,含源代码。 - 精华帖集合
www.dimcax.com 自己写的一个根据polyline生成顶点坐标表格的程序,含源代码。 using system; using autodesk.autocad.applicationservices; using autodesk.autocad.runtime; using autodesk.autocad.databaseservices; using autodesk.autocad.editorinput; using autodesk.autocad.colors; using autodesk.autocad.windows; using autodesk.autocad.geometry; namespace mytools { /// <summary> /// testclass的说明。 /// </summary> public class testclass { public testclass() { } public void createtable(point3dcollection p3dc, string scale,point3d p3d,int t) { int numrows = p3dc.count + 1; string strt; if (t == 3) { strt = "#0.000"; } else { strt = "#0.00"; } database db = hostapplicationservices.workingdatabase; editor ed = application.documentmanager.mdiactivedocument.editor; transaction trans = db.transactionmanager.starttransaction(); blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread); blocktablerecord btr = (blocktablerecord)trans.getobject(db.currentspaceid, openmode.forwrite); double dscale = double.parse(scale); double rowheight; double columnwidth1; double columnwidth2; double textheight1; double textheight2; double columnwidth3; try { textheight1 = 1.25 * (dscale / 500);//表头的字体高度 textheight2 = 0.9 * (dscale / 500);//坐标点的数字字体高度 rowheight = 2 * (dscale / 500);//行高 columnwidth1 = 4 * (dscale / 500);//1列的列宽 columnwidth2 = 11 * (dscale / 500);//2至3列的列宽 columnwidth3 = 6 * (dscale / 500);//4列的列宽 table mytable = new table(); mytable.position = p3d; mytable.numrows = numrows; mytable.numcolumns = 4; mytable.setcolumnwidth(0,columnwidth1); mytable.setcolumnwidth(1,columnwidth2); mytable.setcolumnwidth(2,columnwidth2); mytable.setcolumnwidth(3,columnwidth3); mytable.setrowheight(rowheight); ed.writemessage(rowheight.tostring()); //设置表头 mytable.settextheight(0, 0, textheight1); mytable.settextstring(0, 0, "序号"); mytable.settextheight(0, 1, textheight1); mytable.settextstring(0, 1, "x坐标"); mytable.settextheight(0, 2, textheight1); mytable.settextstring(0, 2, "y坐标"); mytable.settextheight(0, 3, textheight1); mytable.settextstring(0, 3, "圆弧标记"); //将坐标数值输入到表格中 for (int i = 0; i < p3dc.count; i++) { int n = i + 1; mytable.settextheight(n, 0, textheight2); mytable.settextstring(n, 0, n.tostring()); mytable.settextheight(n, 1, textheight2); mytable.settextstring(n, 1, p3dc.x.tostring(strt)); mytable.settextheight(n, 2, textheight2); mytable.settextstring(n, 2, p3dc.y.tostring(strt)); mytable.settextheight(n, 3, textheight2); mytable.settextstring(n, 3, p3dc.z.tostring()); } btr.appendentity(mytable); trans.addnewlycreateddbobject(mytable, true); trans.commit(); } catch (system.exception ex) { autodesk.autocad.applicationservices.application.showalertdialog("输入的比例尺有误,请重新输入"+ ex.message.tostring()); } finally { trans.dispose(); } } static private point3dcollection getplpoint(objectid plid)//并非真正的3d集合,z如果是1的话表示此点是圆弧的中点 { point3dcollection p3dcollection = new point3dcollection(); transaction trans = autodesk.autocad.databaseservices.hostapplicationservices.workingdatabase.transactionmanager.starttransaction(); using (trans) { dbobject obj = trans.getobject(plid, openmode.forread); if (obj.gettype().name == "polyline"/*此语句可获得所获取对象obj的类型,如polyline,arc,circle等。*/) { polyline pl = obj as polyline; int vn = pl.numberofvertices; for (int i = 0; i < vn; i++) { double vbulge = pl.getbulgeat(i); if (vbulge != 0) { p3dcollection.add(pl.getpoint3dat(i)); double len0 = pl.getdistatpoint(pl.getpoint3dat(i)); double len1 = pl.getdistatpoint(pl.getpoint3dat(i + 1)); double midlen = (len0 + len1) / 2; point3d midp3d = pl.getpointatdist(midlen); point3d m = new point3d(midp3d.x, midp3d.y, 1); p3dcollection.add(m); } else { p3dcollection.add(pl.getpoint3dat(i)); } } } trans.commit(); trans.dispose(); return p3dcollection; } } [commandmethod("zbb")] public void createvertextable() { editor ed = application.documentmanager.mdiactivedocument.editor; promptentityresult per = ed.getentity("\n请选择多段线"); point3dcollection p3dco = getplpoint(per.objectid); if (per.status != promptstatus.ok) { ed.writemessage("\n选择选段错误"); } for (int i = 0; i < p3dco.count; i++) { point3d point3dd = p3dco; ed.writemessage("\n" + point3dd.tostring()); } point3d p3d; promptpointoptions prpointoptions = new promptpointoptions("\n请选择表格插入点:"); promptpointresult prpointres = ed.getpoint(prpointoptions); if (prpointres.status == promptstatus.ok) { p3d = prpointres.value; } promptstringoptions pso = new promptstringoptions("\n请输入比例尺:"); promptresult prscale = ed.getstring(pso); string strscale = prscale.stringresult.tostring(); if (prscale.status != promptstatus.ok) { ed.writemessage("\n输入比例尺错误"); } promptkeywordoptions opt = new promptkeywordoptions("\n选择小数位数[三位(3)]<两位(2)>"); opt.keywords.add("3"); opt.keywords.add("2"); promptresult result = ed.getkeywords(opt); if (result.status == promptstatus.ok) { switch (result.stringresult) { case "3": createtable(p3dco, strscale, p3d, 3); break; case "2": createtable(p3dco, strscale, p3d, 2); break; } } } } } 复制代码 如果比例尺的值是11:500,你只要输入500就行,1:1500就1500 在table实例化时显示默认是1行1列,且行高、列宽都是1,但是事实上行列数正确,但是行高、列宽却不是标称的1,而是行高4.6,列宽7.5,不知道是怎么回事!而且设置的值低于这两个数时,是无效的设置。比如设置mytable.setrowheight(2),那么行高仍然是4.6,是不能改变的,列宽也是同样的情况。 所以上述代码你的比例尺如果输入的是 请问各位高手这个问题怎么解决啊? 发觉是table本身问题,在cad中用表格工具画表格时也是一样的!看来是bug,和字体的大小有关系! 我决定自己写个制作表格的类,用多段线画!到时候贴上来。郁闷阿! 原帖由 muli 于 2007-6-11 02:32 pm 发表 发觉是table本身问题,在cad中用表格工具画表格时也是一样的!看来是bug,和字体的大小有关系! 我决定自己写个制作表格的类,用多段线画!到时候贴上来。郁闷阿! table类是有点问题,不知道是autocad .net本身的问题,还是我们的编码有问题。 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 |
所有的时间均为北京时间。 现在的时间是 11:06 AM. |