几何尺寸与公差论坛------致力于产品几何量公差标准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-20, 05:37 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】一个简单的多段线jig程序

一个简单的多段线jig程序
www.dimcax.com
一个简单的多段线jig程序
这是一个简单的多段线jig程序,运行时,提示用户先后输入三个点,程序根据第一二点,画出直线段,拖动第三点后,画出圆弧段,圆弧段和前一直线段相切。此程序的写法与kean的程序有所不同,可进行对象捕捉,闪烁感也明显比kean的小。但程序还有几个地方应该改进:一是不支持ucs;二是没进行出错处理;三是应该增加关键字选项( 如 指定下一点或[直线(l)/圆弧(a)] )。源码如下:
以下内容需要积分高于 10 才可浏览
using system;
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.editorinput;
using autodesk.autocad.geometry;
using autodesk.autocad.graphicsinterface;
using autodesk.autocad.runtime;
namespace csmgd100
{
public class class2 : drawjig
{
private polyline temppolyline;
private double bulge;
private point3d mpt1, mpt2, mpt3;
[commandmethod("test1")]
public void test1()
{
editor ed = application.documentmanager.mdiactivedocument.editor;
database db = hostapplicationservices.workingdatabase;
promptpointoptions opt1 = new promptpointoptions("\n请输入第一点");
promptpointresult res1 = ed.getpoint(opt1);
if (res1.status != promptstatus.ok)
{
return;
}
mpt1 = res1.value;
promptpointoptions opt2 = new promptpointoptions("\n请输入第二点");
opt2.basepoint = mpt1;
opt2.usebasepoint = true;
promptpointresult res2 = ed.getpoint(opt2);
if (res2.status != promptstatus.ok)
{
return;
}
mpt2 = res2.value;
polyline polylineent = new polyline();
polylineent.addvertexat(0, new point2d(mpt1.x, mpt1.y), 0, 0, 0);
polylineent.addvertexat(1, new point2d(mpt2.x, mpt2.y), 0, 0, 0);
objectid entid = appendentity(polylineent);
temppolyline = new polyline();
temppolyline.addvertexat(0, new point2d(mpt2.x, mpt2.y), 0, 0, 0);
temppolyline.addvertexat(1, new point2d(mpt2.x, mpt2.y), 0, 0, 0);
promptresult resjig = ed.drag(this);
if (resjig.status == promptstatus.ok)
{
using (transaction trans = db.transactionmanager.starttransaction())
{
polylineent = (polyline)trans.getobject(entid, openmode.forwrite);
polylineent.addvertexat(2, new point2d(mpt3.x, mpt3.y), 0, 0, 0);
polylineent.setbulgeat(1, bulge);
polylineent.setbulgeat(2, bulge);
trans.commit();
}
}
}
protected override samplerstatus sampler(jigprompts prompts)
{
jigpromptpointoptions optjigpoint = new jigpromptpointoptions
("\n请输入第三点:");
optjigpoint.cursor = cursortype.rubberband;
optjigpoint.basepoint = mpt2;
optjigpoint.usebasepoint = true;
promptpointresult resjigpoint = prompts.acquirepoint(optjigpoint);
point3d curpt = resjigpoint.value;
if (mpt3 != curpt)
{
mpt3 = curpt;
double ang = (new point2d(mpt3.x, mpt3.y) - new point2d(mpt2.x, mpt2.y)).angle -
(new point2d(mpt2.x, mpt2.y) - new point2d(mpt1.x, mpt1.y)).angle;
bulge = math.tan(0.5 * ang);
temppolyline.setpointat(1, new point2d(mpt3.x, mpt3.y));
temppolyline.setbulgeat(0, bulge);
temppolyline.setbulgeat(1, bulge);
return samplerstatus.ok;
}
else
{
return samplerstatus.nochange;
}
}
protected override bool worlddraw(worlddraw draw)
{
draw.geometry.draw(temppolyline);
return true;
}
private objectid appendentity(entity ent)
{
database db = hostapplicationservices.workingdatabase;
objectid entid;
using (transaction trans = db.transactionmanager.starttransaction())
{
blocktable bt = (blocktable)trans.getobject(db.blocktableid,
openmode.forread);
blocktablerecord btr = (blocktablerecord)trans.getobject
(bt[blocktablerecord.modelspace], openmode.forwrite);
entid = btr.appendentity(ent);
trans.addnewlycreateddbobject(ent, true);
trans.commit();
}
return entid;
}
}
}
复制代码
(42.75 kb)
下载次数:1
不错,学习

不错,学习
: 谢谢! 学习一下
.....强烈抵制
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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



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


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