几何尺寸与公差论坛------致力于产品几何量公差标准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-29, 05:44 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】自己写的:等高线(二维多线段polyline2d)转换为多线段(polyline)类 - 精华帖集合

自己写的:等高线(二维多线段polyline2d)转换为多线段(polyline)类 - 精华帖集合
www.dimcax.com
自己写的:等高线(二维多线段polyline2d)转换为多线段(polyline)类
我是搞测量的,经常处理地形图,经常是太大了,打开慢,最重要的原因就是地形图中等高线多为拟合过的二维多线段(polyline2d),占用大量内存。
经过多次实验,把“二维多线段(polyline2d)”转换为“多线段(polyline)”cad图形内存会小很多,因此写了这个类来进行批量转换,自己用过了,好像没有问题。
小弟也是刚刚学习cad开发,望大虾赐教,向你们学习,也帮我看看有没有问题。!
下面是代码:
using system;
using autodesk.autocad.applicationservices;
using autodesk.autocad.editorinput;
using autodesk.autocad.databaseservices;
using autodesk.autocad.geometry;
namespace classlibrary
{
class contourline
{
private database db;
private transaction trans;
private blocktable bt;
private blocktablerecord btr;
private objectid[] ids;//所以等高线id集合

public contourline()
{
db = hostapplicationservices.workingdatabase;
}
public void initialize()
{
trans = db.transactionmanager.starttransaction();
bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread);
btr = (blocktablerecord)trans.getobject(bt[blocktablerecord.modelspace], openmode.forwrite);
}
public void disposeall()
{
bt.dispose();
btr.dispose();
trans.dispose();
}
/// <summary>
/// 得到polyline2d等高线id集合
/// </summary>
public void getpolyline2dids()
{
editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor;
typedvalue[] firstvalue = new typedvalue[]{
new typedvalue(0,"polyline"),
new typedvalue((int)dxfcode.layername,"dgx")
};
selectionfilter filter = new selectionfilter(firstvalue);
promptselectionresult resselectopt = ed.selectall(filter);
if (resselectopt.status != promptstatus.ok)
{
ids = null;
return;
}
selectionset ss = resselectopt.value;
ids = ss.getobjectids();
}
/// <summary>
/// 二维多线段转换
/// </summary>
public void convertpolyline2dtopolyline()
{
editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor;
getpolyline2dids();
if (ids == null)
{
ed.writemessage("\n没有需要转换的拟和多线段\n");
return;
}
initialize();
long polyline2dcount = 0;
foreach (objectid id in ids)
{
polyline2d pl2d = trans.getobject(id, openmode.forwrite) as polyline2d;
if (pl2d == null)
continue;
polyline2dcount++;
polyline pl = new polyline();
//poly2dtype.simplepoly 拟和=无
//poly2dtype.fitcurvepoly 曲线拟和
//poly2dtype.quadsplinepoly 二次拟和
//poly2dtype.cubicsplinepoly 三次拟和
switch (pl2d.polytype)
{
case poly2dtype.simplepoly:
case poly2dtype.fitcurvepoly:
pl.convertfrom(pl2d, false);
break;
case poly2dtype.quadsplinepoly:
case poly2dtype.cubicsplinepoly:
int index = 0;
foreach (objectid vid in pl2d)
{
vertex2d v2d = trans.getobject(vid, openmode.forread) as vertex2d;
if (v2d.vertextype != vertex2dtype.splinecontrolvertex)
pl.addvertexat(index++, new point2d(v2d.position.x, v2d.position.y), 0,0,0);
}
break;
}
pl.layer = pl2d.layer;
pl.color = pl2d.color;
pl.linetype = pl2d.linetype;
pl.constantwidth = pl2d.defaultstartwidth;
pl.closed = pl2d.closed;
pl.elevation = pl2d.elevation;
pl2d.erase(true); //删除原拟和二维多线段

btr.appendentity(pl);
trans.addnewlycreateddbobject(pl, true);
}
trans.commit();
disposeall();
ed.writemessage("\n处理了" + polyline2dcount.tostring() + "条拟和多线段\n");
}
}
}
复制代码
[ ]
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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



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


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