主要代码:

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. Python数据结构应用4——搜索(search)

    Search是数据结构中最基础的应用之一了,在python中,search有一个非常简单的方法如下: 15 in [3,5,4,1,76] False 不过这只是search的一种形式,下面列出多种形 ...

  2. QTimer在QThread环境中失效的问题

    QTimer在非QThread的环境下能正常工作.但在QThread环境下,需要做一些改动才能正常工作. 创建Qt的线程有两种方式: 1. 子例化QThread 可以在虚函数run中启动定时器,大致的 ...

  3. 下拉框选择selected

    var id=$("#orderId").children('option:selected').val(); //selected选中项取值 var id=$('#orderId ...

  4. [Active Learning] Multi-Criteria-based Active Learning

    目录 1 Informativeness 2 Representativeness 3 Diversity 3.1 Global consideration 3.2 Local considerati ...

  5. MIP 技术进展月报:储存功能全新上线,MIP-Cache域名升级,校验更严谨

    集 ** 瞬时触达用户.高转化率.炫酷闪电标.优质展现形式 ** 等诸多特性为一体的 MIP 页面吸引了众多站点进行改造.为了更好地服务于广大站长,更快地倾听站长们的声音,MIP 技术团队特推出< ...

  6. Java进阶篇设计模式之十一 ---- 策略模式和模板方法模式

    前言 在上一篇中我们学习了行为型模式的访问者模式(Visitor Pattern)和中介者模式(Mediator Pattern).本篇则来学习下行为型模式的两个模式,策略模式(Strategy Pa ...

  7. 补习系列(19)-springboot JPA + PostGreSQL

    目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...

  8. Android之Fragment详解

    文章大纲 一. 什么是Fragment二. Fragment生命周期三. Fragment简单实例四.Fragment实战五.项目源码下载六.参考文章   一. 什么是Fragment Fragmen ...

  9. 重庆3Shape TRIOS都有哪些功能

    1.高质量的临床结果高准确度的数字化印模确保高质量的修复体密合度即时制备和印模确认就位修复体时无需多次调整和研磨2.轻松取模无需喷粉扫描无需印模材料,可保持操作台整洁无需重复取模3.更稳健的业务联系加 ...

  10. CDN工作机制和负载均衡

    定义:  CDN 即内容分布网络,(Content Delivery Netwrok) ,是构筑在现有Internet上的一种先进的流量分配网络,其目的是通过在现有的Internet中增加一层新的网络 ...