.NET CAD二次开发学习 直线画矩形并转换成组
主要代码:
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
using grxcad.runtime;
using grxcad.applicationservices;
using grxcad.editorinput;
using grxcad.geometry;
using grxcad.databaseservices;
using grxcad.windows;
namespace arxfirsttest
{
public class xrect
{
private point3d startpoint;
private point3d endpoint;
private double width;
public void xrecpic()
{
document doc = application.documentmanager.mdiactivedocument;
editor editor = doc.editor;
database db = doc.database;
promptpointoptions promptpoint1 = new promptpointoptions("\n请指定起点<退出>");
promptpointresult pointresult1 = editor.getpoint(promptpoint1);
promptpointoptions promptpoint2 = new promptpointoptions("\n请指定终点<退出>");
promptpointresult pointresult2 = editor.getpoint(promptpoint2);
promptdoubleoptions pdoubleoptions = new promptdoubleoptions("\n请输入宽度<退出>");
promptdoubleresult pdoubleres = editor.getdouble(pdoubleoptions);
if (pointresult1.status == promptstatus.ok && pointresult2.status == promptstatus.ok && pdoubleres.value > 0)
{
using (transaction trans = doc.transactionmanager.starttransaction())
{
startpoint = pointresult1.value;
endpoint = pointresult2.value;
width = pdoubleres.value;
line line = new line();
line.startpoint = startpoint;
line.endpoint = endpoint;
dbobjectcollection dboj = line.getoffsetcurves(width / 2);
dbobjectcollection dboj1 = line.getoffsetcurves(width / 2 - width);
line line1 = (line)dboj[0];
line line2 = (line)dboj1[0];
line line3 = new line();
line line4 = new line();
line3.startpoint = line1.startpoint;
line3.endpoint = line2.startpoint;
line4.startpoint = line1.endpoint;
line4.endpoint = line2.endpoint;
objectid idmodelspace = symbolutilityservices.getblockmodelspaceid(db);
blocktablerecord btr = trans.getobject(idmodelspace, openmode.forwrite) as blocktablerecord;
btr.appendentity(line1);
btr.appendentity(line2);
btr.appendentity(line3);
btr.appendentity(line4);
trans.addnewlycreateddbobject(line1, true);
trans.addnewlycreateddbobject(line2, true);
trans.addnewlycreateddbobject(line3, true);
trans.addnewlycreateddbobject(line4, true);
entity ent1 = (entity)line1;
entity ent2 = (entity)line2;
entity ent3 = (entity)line3;
entity ent4 = (entity)line4;
group group = new group();
group.append(ent1.objectid);
group.append(ent2.objectid);
group.append(ent3.objectid);
group.append(ent4.objectid);
dbdictionary groupdic = trans.getobject(db.groupdictionaryid,openmode.forwrite) as dbdictionary;
group.selectable = true;
groupdic.setat(group.name, group);
trans.addnewlycreateddbobject(group, true);
trans.commit();
}
}
else
{
application.showalertdialog("选择或者输入有误,请重新输入");
return;
}
}
}
}