基於浩辰CAD2019 需求: 開發線轉圓簡單命令。命令過程:1) 請選擇圖中直線(要求支持一次選多個):2) 彈出對話框,輸入圓的圖層名和半徑3) 點對話框中確定按鈕,結束命令。命令執行效果:所選每條直線的起點和終點處,自動生成兩個圓;同時,所有直線自動整體平移MOVE一個向量AcGeVector ...
基於浩辰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)
{
}
}
}