主要代码:

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 CAD二次开发学习 直线画矩形并转换成组的更多相关文章

  1. 基于.NET的CAD二次开发学习笔记二:AutoCAD .NET中的对象

    1.CAD对象:一个CAD文件(DWG文件)即对应一个数据库,数据库中的所有组成部分,看的见(包括点.多段线.文字.圆等)和看不见(图层.线型.颜色等)的都是对象,数据库本身也是一个对象. 直线.圆弧 ...

  2. .NET CAD二次开发学习第一天

    基于浩辰CAD2019 需求: 开发线转圆简单命令.命令过程:1) 请选择图中直线(要求支持一次选多个):2) 弹出对话框,输入圆的图层名和半径3) 点对话框中确定按钮,结束命令.命令执行效果:所选每 ...

  3. 基于.NET的CAD二次开发学习笔记一:CAD开发入门

    1.AutoCAD .NET API由不同的DLL文件组成,它们提供用于访问图形文件或AutoCAD应用程序的包含丰富的类.结构.方法和事件.每一个DLL文件都定义不同的使用基于功能的库组织组件的命名 ...

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

    [CommandMethod("CBline")] //对称画线 public void CBline() { Document doc = Application.Documen ...

  5. CAD二次开发

    用C#有一段时间了,由于单位需要,开始接触CAD二次开发,网上一搜,加入CAD开发的群,零零碎碎看了一些文章和博客,没有系统地的知识,能解决一些小问题.最近开始系统学习,再次推荐两本书,一本事纸质版的 ...

  6. C#进行CAD二次开发环境配置

    最近被公司分配到了做CAD二次开发.也是初次接触这方面的东西,其实是有些无从下手的感觉.因为公司这边也没有人有时间带我,只能是自己看书,然后再写一些Demo,再结合实际的应用来一点点的学习.废话不多说 ...

  7. CAD二次开发起步

    1 环境搭建(VS 2017 + CAD 2019) CAD版本一般要比VS版本晚两年以上,比如我现在使用VS2017,则CAD要用2019版,至于CAD2018能不能用没试验过,有兴趣的小伙伴可以试 ...

  8. Civil 3D API二次开发学习指南

    Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...

  9. Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试

    CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ...

随机推荐

  1. solr+jieba结巴分词

    为什么选择结巴分词 分词效率高 词料库构建时使用的是jieba (python) 结巴分词Java版本 下载 git clone https://github.com/huaban/jieba-ana ...

  2. PCB泪滴设计

    操作:选择[Tools]-->[Teardrops],快捷键T+E.打开[Teardrop Options]对话框进行设置.如下图所示: 对话框面板介绍 [General] 1.该区域的[Pad ...

  3. turtle文库 ——python

    本文将会为您介绍关于python--turtle库函数,学会这个库函数,会有很多让你意想不到的事情发生哦! 我也也会为你们,简单的编写几个代码,让你们看一下turtle函数的魅力 Turtle库是Py ...

  4. 关于throw、throws、try--catch的问题

    首先回顾概念 throws表示出现异常的一种可能性,并不一定会发生这些异常 throw则是抛出了异常,执行throw则一定抛出了某种异常 try--catch try语句用大括号{}指定了一段代码,该 ...

  5. 如何将markdown转换为wxml

    话说我要为技术博客写一个小程序版,我的博客解决方案是 hexo + github-page,格式当然是技术控们喜欢的 markdown 了 .但小程序使用的却是独有的模版语言 WXML.我总不能把之前 ...

  6. Spark学习之数据读取与保存总结(一)

    一.动机 我们已经学了很多在 Spark 中对已分发的数据执行的操作.到目前为止,所展示的示例都是从本地集合或者普通文件中进行数据读取和保存的.但有时候,数据量可能大到无法放在一台机器中,这时就需要探 ...

  7. 将本地文件传输到GitHub

    统一概念: 工作区:增删文件和内容 暂存区:键入命令 git add 改动的文件,此次改动就放到了 『暂存区』 本地仓库 :键入命令 git commit ,此次改动就放到了『本地仓库』,每个 com ...

  8. go语言调度器源代码情景分析之二:CPU寄存器

    本文是<go调度器源代码情景分析>系列 第一章 预备知识的第1小节. 寄存器是CPU内部的存储单元,用于存放从内存读取而来的数据(包括指令)和CPU运算的中间结果,之所以要使用寄存器来临时 ...

  9. 深入vue - 源码目录及构建过程分析

     公众号原文链接:深入vue - 源码目录及构建过程分析   喜欢本文可以扫描下方二维码关注我的公众号 「前端小苑」 ​“ 本文主要梳理一下vue代码的目录,以及vue代码构建流程,旨在对vue源码整 ...

  10. .NET Core微服务系列基础文章索引(目录导航Final版)

    一.为啥要总结和收集这个系列? 今年从原来的Team里面被抽出来加入了新的Team,开始做Java微服务的开发工作,接触了Spring Boot, Spring Cloud等技术栈,对微服务这种架构有 ...