新手的第一个画直线的程序和新手分享 - 精华帖集合
www.dimcax.com
新手的第一个画直线的程序和新手分享
初学c#,望大家以后多多指教.
[commandmethod("netline")]
public void netline()
{
editor ed = application.documentmanager.mdiactivedocument.editor;
database db = hostapplicationservices.workingdatabase;
promptpointoptions oppt = new promptpointoptions("");
oppt.allownone = true;
objectidcollection ids = new objectidcollection();
point3dcollection pts = new point3dcollection();
promptpointresult respt;
point3d pt1=new point3d(0, 0, 0), pt2, spt=new point3d(0, 0, 0);
int n = 0;
do
{
switch (n)
{
case 0:
oppt.message = "\n指定第一点: ";
oppt.usebasepoint = false;
break;
case 1:
case 2:
oppt.message = "\n指定下一点或 [放弃(u)]";
oppt.keywords.add("u", "u", "u", false, true);
oppt.usebasepoint = true;
oppt.basepoint = pt1;
break;
default:
oppt.message = "\n指定下一点或 [闭合(c)/放弃(u)]";
oppt.usebasepoint = true;
oppt.basepoint = pt1;
oppt.keywords.add("u", "u", "u", false, true);
oppt.keywords.add("c", "c", "c", false, true);
break;
}
respt = ed.getpoint(oppt);
if(respt.status == promptstatus.none || respt.status == promptstatus.cancel)
return;
else
{
if(respt.status == promptstatus.keyword)
{
switch(respt.stringresult)
{
case "u":
if(n > 1 )
{
objectid objid = ids[ids.count-1];
ids.removeat(ids.count-1);
using(transaction trans = db.transactionmanager.startopenclosetransaction())
{
entity ent2 = (entity)trans.getobject(objid, openmode.forwrite, false)as entity;
ent2.erase();
trans.commit();
}
}
pts.removeat(pts.count-1);
if(pts.count > 0)
pt1 = pts[pts.count-1];
else
ed.writemessage("\n已经放弃所有线段。");
n--;
break;
case "c":
line ent1 = new line(pt1, spt);
using(transaction trans = db.transactionmanager.startopenclosetransaction())
{
blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread);
blocktablerecord btr = (blocktablerecord)trans.getobject(bt[blocktablerecord.modelspace], openmode.forwrite);
objectid id = btr.appendentity(ent1);
ids.add(id);
trans.addnewlycreateddbobject(ent1, true);
trans.commit();
}
return;
}
}
else
{
pt2 = respt.value;
if(n > 0)
{
line ent = new line(pt1, pt2);
pts.add(pt2);
pt1 = pt2;
n++;
using(transaction trans = db.transactionmanager.startopenclosetransaction())
{
blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread);
blocktablerecord btr = (blocktablerecord)trans.getobject(bt[blocktablerecord.modelspace], openmode.forwrite);
objectid id = btr.appendentity(ent);
ids.add(id);
trans.addnewlycreateddbobject(ent, true);
trans.commit();
}
}
else
{
spt = pt2;
pt1 = pt2;
pts.add(pt2);
n++;
}
}
}
oppt.keywords.clear();
}while(respt.status == promptstatus.ok || respt.status == promptstatus.keyword);
}
复制代码
很好!相信你已不是“新手”了!!
不错,加精了
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。
卢大哥和才大哥,过奖了,需要学习的地方太多了,加上不懂英文学起来很吃力,要是才大哥能组织人把objectarx.net的帮助文件翻译一下就好了. [ ]