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

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】一个简单的多段线jig程序 (http://www.dimcax.com/hust/showthread.php?t=9247)

yang686526 2009-04-20 05:37 PM

【转帖】一个简单的多段线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
不错,学习

不错,学习
: 谢谢! 学习一下
.....强烈抵制


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