![]() |
.net开发的从text读取特定格式数据并生成图形
.net开发的从text读取特定格式数据并生成图形
www.dimcax.com .net开发的从text读取特定格式数据并生成图形 我是一个初学者,不懂编程,也不懂arx,最近才开始学c#.net + arx开发cad,刚作出一个小程序,与初学的交流一下,也请高手帮我完善一下,因我我没有加异常处理^_^,加了老是“并非所有代码路径都返回值”的错误,所以删了~~~希望谁能帮我改写一下,程序如下: using system ; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; using system.io; using system.collections.specialized; using autodesk.autocad.runtime ; using autodesk.autocad.databaseservices; using autodesk.autocad.applicationservices; //using autodesk.autocad.colors; using autodesk.autocad.geometry; using autodesk.autocad.editorinput; [assembly: commandclass(typeof(classlibrary.myclass))] namespace classlibrary { /// <summary> /// summary description for myclass. /// </summary> public class myclass { public myclass() { // // todo: add constructor logic here // } static public objectid createlayer() { objectid layerid; //它返回函数的值 database db = hostapplicationservices.workingdatabase; transaction trans = db.transactionmanager.starttransaction(); //首先取得层表…… layertable lt = (layertable)trans.getobject(db.layertableid, openmode.forwrite); //检查employeelayer层是否存在…… if (lt.has("laj")) { layerid = lt["laj"]; } else { //如果employeelayer层不存在,就创建它 layertablerecord ltr = new layertablerecord(); ltr.name = "laj"; //设置层的名字 ltr.color = autodesk.autocad.colors.color.fromcolorindex(autodesk.autocad.colors.colormethod.byaci, 1); layerid = lt.add(ltr); trans.addnewlycreateddbobject(ltr, true); } trans.commit(); trans.dispose(); return layerid; } static public point3dcollection inputcoo() { point3dcollection point3dcollection = new point3dcollection(); system.windows.forms.openfiledialog openfiledialog1 = new system.windows.forms.openfiledialog(); openfiledialog openfiledialog = new openfiledialog(); openfiledialog1.initialdirectory = @"d:\documents and settings\muli\my documents\"; openfiledialog1.filter = "txt files (*.txt)|*.txt|all files (*.*)|*.*"; openfiledialog1.filterindex = 1; openfiledialog1.restoredirectory = true ; if (openfiledialog1.showdialog() == dialogresult.ok) { streamreader sr = new streamreader(openfiledialog1.filename,system.text.encoding.default); string [] sline = null; arraylist arrtext = new arraylist(); // string delimstr = ",,,"; // char [] delimiter = delimstr.tochararray(); while (sr.peek() != -1) { string aa = sr.readline(); string delimstr = " ,"; char [] delimiter = delimstr.tochararray(); sline = aa.split(delimiter); for (int i = 0; i < 3; i++) { string sl = sline[i]; arrtext.add(sl); } } string[] arrstring = new string[arrtext.count]; arrtext.copyto(arrstring,0); //以下代码将arrstring中的元素转为point3dcollection for (int c = 0; c < arrtext.count/3; c++) { double x = system.convert.todouble(arrstring[3*c + 1]); double y = system.convert.todouble(arrstring[3*c + 2]); point3d point3d = new point3d(x,y,0); point3dcollection.add(point3d); } sr.close(); return point3dcollection; } else { messagebox.show("打开/读写文件出错"); return null; } } [commandmethod("cpline")] static public void createpline() { point3dcollection ptarr = inputcoo();//定义三维坐标数组对象 editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor; database db = hostapplicationservices.workingdatabase; transaction trans = db.transactionmanager.starttransaction(); try { polyline2d pline = new polyline2d(poly2dtype.simplepoly, ptarr, 0.0, true, 0.0, 0.0, null); objectid layerlaj = createlayer(); pline.closed = true; pline.layerid = layerlaj; blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread); blocktablerecord btr = (blocktablerecord)trans.getobject(db.currentspaceid,openmode.forwrite ); btr.appendentity(pline); trans.addnewlycreateddbobject(pline,true); trans.commit(); } catch { ed.writemessage("error!"); } finally { trans.dispose(); } } } } 另,坐标文件的格式如下: 1,x,y 2,x,y 3,x,y ...... 其中,分隔符可以是“,”,或者空格。 为什么没有高手帮我看一下呢?才哥呢? |
所有的时间均为北京时间。 现在的时间是 01:17 AM. |