.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)
{
}
}
}
.NET CAD二次开发学习第一天的更多相关文章
- 基于.NET的CAD二次开发学习笔记二:AutoCAD .NET中的对象
1.CAD对象:一个CAD文件(DWG文件)即对应一个数据库,数据库中的所有组成部分,看的见(包括点.多段线.文字.圆等)和看不见(图层.线型.颜色等)的都是对象,数据库本身也是一个对象. 直线.圆弧 ...
- 基于.NET的CAD二次开发学习笔记一:CAD开发入门
1.AutoCAD .NET API由不同的DLL文件组成,它们提供用于访问图形文件或AutoCAD应用程序的包含丰富的类.结构.方法和事件.每一个DLL文件都定义不同的使用基于功能的库组织组件的命名 ...
- .NET CAD二次开发学习 对称画线功能
[CommandMethod("CBline")] //对称画线 public void CBline() { Document doc = Application.Documen ...
- .NET CAD二次开发学习 直线画矩形并转换成组
主要代码: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...
- C#进行CAD二次开发环境配置
最近被公司分配到了做CAD二次开发.也是初次接触这方面的东西,其实是有些无从下手的感觉.因为公司这边也没有人有时间带我,只能是自己看书,然后再写一些Demo,再结合实际的应用来一点点的学习.废话不多说 ...
- CAD二次开发起步
1 环境搭建(VS 2017 + CAD 2019) CAD版本一般要比VS版本晚两年以上,比如我现在使用VS2017,则CAD要用2019版,至于CAD2018能不能用没试验过,有兴趣的小伙伴可以试 ...
- CAD二次开发
用C#有一段时间了,由于单位需要,开始接触CAD二次开发,网上一搜,加入CAD开发的群,零零碎碎看了一些文章和博客,没有系统地的知识,能解决一些小问题.最近开始系统学习,再次推荐两本书,一本事纸质版的 ...
- Civil 3D API二次开发学习指南
Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...
- Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试
CAD2008的二次开发,有个很奇怪的现象,只要你选择的点集不在当前视图上SelectCrossingPolygon和SelectFence返回结果Status就会为error,所以要获取正确的结果, ...
随机推荐
- Linux 下配置Nginx,MySql,php-fpm开机启动
一. Nginx 开机启动 1.在/etc/init.d/目录下创建脚本 vim /etc/init.d/nginx 2.编写脚本内容 (将以下复制进去相应改动安装路径) #!/bin/bash # ...
- Oracle系列-锁表与解锁解决方案(大招版)-解决问题才是王道
[Oracle系列-锁表与解锁解决方案(大招版)] --1查看被锁的表 select b.owner,b.object_name,a.session_id,a.locked_mode from v$l ...
- css3新增动画
1.transiition过渡:样式改变就会执行transition (1)格式:transiition:1s width linear,2s 1s height; (2)参数: transition ...
- 对图片进行索引,存入数据库sqlite3中,实现快速搜索打开
对图片进行索引,存入数据库中,实现快速搜索打开 这个任务分为两步: 第一步:建立索引 import os import shutil import sqlite3 # 扫描函数,需扫描路径目录处 ...
- UWP中实现大爆炸效果(二)
上一回实现了一个宽度不均匀的Panel,这次我们编写一个简单的BigbangView主体. 首先创建一个模板化控件,删掉Themes/Generic.xaml中的<Style TargetTyp ...
- Django文件上传(经典上传方式)
经典文件上传方式 创建URL from django.contrib import admin from django.urls import path from django.conf.urls i ...
- SSRS报表服务随笔(rdl报表服务)-报表数据:使用第三方控件生成条形码
因为工作需要,需要将订单号显示成条形码,比如数据库存储的20190106A,我需要把这个转换为Code128来显示出来 在国内我没有找到这方面的教程,最后还是一个人自己摸索出来的 在这里我是使用的是B ...
- 树莓派3b+_32位linux系统arm架构安装JDK
如图我的Raspbian系统如下图版本信息: 可以看到是armv7l,我查了一下是32位的arm架构,即下载第一个就好了 然后用SSH Secure Shell远程上去把压缩包或者解压后的文件传过去 ...
- 从壹开始前后端分离【 .NETCore2.1 +Vue 2 +AOP+DI】框架之一 || 前言
缘起 作为一个.Net攻城狮已经4年有余了,一直不温不火,正好近来项目不是很忙,闲得无聊,搞一搞新技术,一方面是打发无聊的时间,一方面也是督促自己该学习辣!身边的大神都转行的转行,加薪的加薪,本人比较 ...
- Nginx 安装详细(一)
1. 老规矩,来点开场白:Nginx简单介绍 Nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:Nginx可以作为一个HTT ...