几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-19, 09:18 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 .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
......
其中,分隔符可以是“,”,或者空格。
为什么没有高手帮我看一下呢?才哥呢?
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 01:31 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多