欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.NET CAD二次开发学习 对称画线功能

程序员文章站 2022-06-28 20:35:03
[CommandMethod("CBline")] //对称画线 public void CBline() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor edit = doc.Editor; Databa ......

[commandmethod("cbline")] //对称画线
public void cbline()
{
document doc = application.documentmanager.mdiactivedocument;
editor edit = doc.editor;
database db = doc.database;
using(transaction trans=doc.transactionmanager.starttransaction())
{

promptentityoptions peo = new promptentityoptions("请指定基准线\n");
promptentityresult per = edit.getentity(peo);
entity ent = trans.getobject(per.objectid, openmode.forwrite) as entity;
//if (ent.gettype()!=typeof(line))
if(!(ent is line))
{
edit.writemessage("指定的实体不是基准线!");
return;

}
line line = (line)ent;
line.colorindex = 1;
promptpointoptions ppo = new promptpointoptions("请指定第一点\n");
promptpointresult ppr = edit.getpoint(ppo);
point3d pt1=ppr.value;
promptpointoptions ppo1 = new promptpointoptions("请指定第二点\n");
promptpointresult ppr1 = edit.getpoint(ppo);
point3d pt2=ppr1.value;
point3d pt3 = line.getclosestpointto(pt1,true);
vector3d vt1 = pt3 - pt1;
point3d pt4 = new point3d(vt1.x+pt3.x,vt1.y+pt3.y,0);
point3d pt5 = line.getclosestpointto(pt2, true);
vector3d vt2 = pt5 - pt2;
point3d pt6 = new point3d(vt2.x + pt5.x, vt2.y + pt5.y, 0);
line line1 = new line(pt1, pt2);
line line2 = new line(pt4, pt6);
objectid idmodelspace = symbolutilityservices.getblockmodelspaceid(db);
blocktablerecord btr = trans.getobject(idmodelspace, openmode.forwrite) as blocktablerecord;
btr.appendentity(line1);
btr.appendentity(line2);
trans.addnewlycreateddbobject(line1, true);
trans.addnewlycreateddbobject(line2, true);
trans.commit();


}

}