设为首页 加入收藏

TOP

.NET CAD二次开发学习 直线画矩形并转换成组
2019-09-17 19:08:27 】 浏览:35
Tags:.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;

}

}
}
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇高字节,低位字节是什么东西 下一篇.net core入门-发布及部署_异常(..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目