.NET CAD二次开发学习第一天
基于浩辰cad2019
需求:
开发线转圆简单命令。
命令过程:
1) 请选择图中直线(要求支持一次选多个):
2) 弹出对话框,输入圆的图层名和半径
3) 点对话框中确定按钮,结束命令。
命令执行效果:
所选每条直线的起点和终点处,自动生成两个圆;同时,所有直线自动整体平移move一个向量acgevector3d(1000,1000,0)。
代码如下
using system;
using grxcad.runtime;
using grxcad.applicationservices;
using grxcad.editorinput;
using grxcad.geometry;
using grxcad.databaseservices;
using grxcad.windows;
//using system.windows.forms;
namespace arxfirsttest
{
public class class1
{
[commandmethod("linetocircle")]
public void linetocircle()
{
document doc = application.documentmanager.mdiactivedocument;
editor editor = doc.editor;
database db = doc.database;
selectionset acsset = null;
form1 form = new form1();
promptselectionoptions pso = new promptselectionoptions()
{
allowduplicates = false,
selecteverythinginaperture = true,
singleonly = false,
rejectobjectsfromnoncurrentspace = false,
//keywords = { "0","1"},
};
promptselectionresult sspsr = editor.getselection(pso);
if (sspsr.status != promptstatus.ok)
{
return;
}
else
{
acsset = sspsr.value;
}
using (transaction transaction = db.transactionmanager.starttransaction())
{
form.showdialog();
foreach (selectedobject acssobj in acsset)
{
if (acssobj!=null)
{
entity entity = transaction.getobject(acssobj.objectid, openmode.forwrite) as entity;
if (entity is line)
{
string s = form.combobox1.text;
double d = double.parse(form.textbox2.text);
line line = (line)entity;
circle cir1 = new circle();
cir1.center = line.startpoint;
cir1.radius = d;
cir1.layer = s;
circle cir2 = new circle();
cir2.center = line.endpoint;
cir2.radius = d;
cir2.layer = s;
line.transformby(matrix3d.displacement(new vector3d(1000, 1000, 0)));
objectid idmodelspace = symbolutilityservices.getblockmodelspaceid(db);
blocktablerecord btr = transaction.getobject(idmodelspace, openmode.forwrite) as blocktablerecord;
btr.appendentity(line);
btr.appendentity(cir1);
btr.appendentity(cir2);
transaction.addnewlycreateddbobject(line, true);
transaction.addnewlycreateddbobject(cir1, true);
transaction.addnewlycreateddbobject(cir2, true);
}
else
{
application.showalertdialog("选择的实体中有为非直线,请重新选择!");
return;
}
}
}
transaction.commit();
}
}
}
}
using system;
using grxcad.runtime;
using grxcad.applicationservices;
using grxcad.editorinput;
using grxcad.geometry;
using grxcad.databaseservices;
using system.collections;
//using system.windows.forms;
namespace arxfirsttest
{
public partial class form1 : system.windows.forms.form
{
public form1()
{
initializecomponent();
}
public void textbox1_textchanged(object sender, eventargs e)
{
}
public void form1_load(object sender, eventargs e)
{
using (database db = hostapplicationservices.workingdatabase)
{
using (transaction trans = db.transactionmanager.starttransaction())
{
using (layertable lt = (layertable)trans.getobject(db.layertableid, openmode.forread))
{
foreach (objectid id in lt)
{
layertablerecord ltr = (layertablerecord)trans.getobject(id, openmode.forread);
combobox1.items.add(ltr.name);
}
}
trans.commit();
}
}
}
private void textbox2_textchanged(object sender, eventargs e)
{
}
public void button1_click(object sender, eventargs e)
{
document doc = application.documentmanager.mdiactivedocument;
editor editor = doc.editor;
if (double.tryparse(textbox2.text, out double b))
{
//editor.command("enter");
this.close();
}
else
{
application.showalertdialog("数据输入有误,请重新输入");
}
}
public void combobox1_selectedindexchanged(object sender, eventargs e)
{
}
}
}
上一篇: 这家新闻很少的农业电商企业 一年800亿
下一篇: 如何用php获取文件名后缀