c# cad二次开发实现注记搜索跟扩展属性搜索,并点击即可定位到位置,添加了界面操作
在这里插入图片描述

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Geometry;

namespace _7_属性查找
{
public partial class Form1selecte : Form
{
public Form1selecte()
{
InitializeComponent();
}
private static Dictionary<int, List> table1 = new Dictionary<int, List>(100);

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{

    }

private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{

    }

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{

    }/// <summary>/// 搜索文本/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button1_Click(object sender, EventArgs e){table1.Clear();//清空全局变量try{listBox1.Items.Clear();//清空控件内容//启动图形事件Database db = HostApplicationServices.WorkingDatabase;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;//过滤选择条件string lay = comboBox1.Text;if (comboBox1.Text == ""){lay = "**";}TypedValue[] values = new TypedValue[]{new TypedValue((int)DxfCode.Start,"*text*"),//选择图形为圆new TypedValue(1, string.Format("*{0}*", textBox1.Text)),new TypedValue(8, string.Format("*{0}*", lay))};SelectionFilter filter = new SelectionFilter(values);PromptSelectionResult psr = ed.SelectAll(filter);//判断是否有选择到图形if (psr.Status == PromptStatus.OK){SelectionSet sset = psr.Value;using (Transaction trans = db.TransactionManager.StartTransaction()){int i = 0;//循环每个要素foreach (SelectedObject item in sset){Entity ent = (Entity)item.ObjectId.GetObject(OpenMode.ForRead);DBText textEntity = ent as DBText;//获取文本内容string sTxt = textEntity.TextString;//获取文本坐标点Point3d pos = textEntity.Position;double x1 = ent.GeometricExtents.MinPoint.X;double y1 = ent.GeometricExtents.MinPoint.Y;double x2 = ent.GeometricExtents.MaxPoint.X;double y2 = ent.GeometricExtents.MaxPoint.Y;List<double> list1 = new List<double>();list1.Add(x1);list1.Add(y1);list1.Add(x2);list1.Add(y2);//将坐标传递给全局变量table1.Add(i, list1);//文本内容写入界面控件中listBox1.Items.Add(sTxt);i++;}trans.Commit();//提交事务}}}catch (System.DivideByZeroException ex){MessageBox.Show(ex.ToString());}}private void listBox1_SelectedIndexChanged(object sender, EventArgs e){//获取选择的行数int index = listBox1.SelectedIndex;if (index > -1){List<double> list = new List<double>();//获取选择行数的坐标list = table1[index];if (list.Count == 3){double X = list[0];double Y = list[1];double H = list[2] * 2;//缩放到指定位置ZoomWindow(new Point3d(X - H, Y - H, 0), new Point3d(X + H, Y + H, 0));}else{double X1 = list[0];double Y1 = list[1];double X2 = list[2];double Y2 = list[3];//缩放到指定位置ZoomWindow(new Point3d(X1, Y1, 0), new Point3d(X2, Y2, 0));}}}/// <summary>/// 缩放到指定位置/// </summary>/// <param name="pt1">第一个点</param>/// <param name="pt2">第二个点</param>public static void ZoomWindow(Point3d pt1, Point3d pt2){Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;//创建一临时的直线用于获取两点表示的范围using (Line line = new Line(pt1, pt2)){//获取两点表示的范围Extents3d extents = new Extents3d(line.GeometricExtents.MinPoint, line.GeometricExtents.MaxPoint);//获取范围内的最小值点及最大值点Point2d minPt = new Point2d(extents.MinPoint.X, extents.MinPoint.Y);Point2d maxPt = new Point2d(extents.MaxPoint.X, extents.MaxPoint.Y);//得到当前视图ViewTableRecord view = ed.GetCurrentView();//设置视图的中心点、高度和宽度view.CenterPoint = minPt + (maxPt - minPt) / 2;view.Height = maxPt.Y - minPt.Y;view.Width = maxPt.X - minPt.X;//更新当前视图ed.SetCurrentView(view);}}/// <summary>/// 选择扩展属性符合的图形/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){//清空全局变量table1.Clear();//清空界面的空间listBox1.Items.Clear();Database db = HostApplicationServices.WorkingDatabase;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;//过滤选择条件string lay = comboBox1.Text;if (comboBox1.Text == ""){lay = "**";}TypedValue[] values = new TypedValue[]{new TypedValue(1001, string.Format("*{0}*", textBox2.Text)),new TypedValue(8, string.Format("*{0}*", lay))};SelectionFilter filter = new SelectionFilter(values);PromptSelectionResult psr = ed.SelectAll(filter);//判断选择是否有图形if (psr.Status == PromptStatus.OK){SelectionSet sset = psr.Value;ObjectId[] ids = sset.GetObjectIds();using (Transaction trans = db.TransactionManager.StartTransaction()){int i = 0;foreach (SelectedObject item in sset){Entity ent = (Entity)item.ObjectId.GetObject(OpenMode.ForRead);//获取图形的最小点和最大点double x1 = ent.GeometricExtents.MinPoint.X;double y1 = ent.GeometricExtents.MinPoint.Y;double x2 = ent.GeometricExtents.MaxPoint.X;double y2 = ent.GeometricExtents.MaxPoint.Y;List<double> list1 = new List<double>();list1.Add(x1);list1.Add(y1);list1.Add(x2);list1.Add(y2);table1.Add(i, list1);//获取图形的扩展属性ResultBuffer rb = ent.XData;List<string> list = new List<string>();//将扩展属性的值添加到列表中foreach (TypedValue tv in rb){list.Add(tv.Value.ToString());}i++;//将扩展属性添加到控件中listBox1.Items.Add(String.Join("、", list.ToArray()));}trans.Commit();}}}private void button3_Click(object sender, EventArgs e){comboBox1.Items.Clear();Database db = HostApplicationServices.WorkingDatabase;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;using (Transaction trans = db.TransactionManager.StartTransaction()){LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);foreach (ObjectId item in lt){LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(item, OpenMode.ForRead);if (ltr != null){comboBox1.Items.Add(ltr.Name);}}}}
}

}

c# cad二次开发实现注记搜索跟扩展属性搜索,并点击即可定位到位置,添加了界面操作相关推荐

  1. c# CAD二次开发 模拟CAD移动图形, 通过圆现在注记,改变图形颜色

    c# CAD二次开发 模拟CAD移动图形, 通过圆现在注记,改变图形颜色 using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD ...

  2. CAD二次开发(C#) 第一节

    前言 由于工作需要,最近在学习二次开发,将其记录于此,以便日后查看. 语法 涉及"特性","进程"知识点,需要有所了解 #region CAD二次开发--第一节 ...

  3. lisp陡坎程序_(终稿)毕业论文设计_Autolisp在CAD二次开发中的应用.doc(最终版)最新版...

    <毕业论文:Autolisp在CAD二次开发中的应用.doc>由会员分享,可免费在线阅读全文,更多与<(终稿)毕业论文设计_Autolisp在CAD二次开发中的应用.doc(最终版) ...

  4. 【CAD二次开发】实现双击实体的响应

    一.基本双击响应实现 通过向导在VS中创建MFC支持的新项目: 项工程中添加普通CDoubleClick类, 基类选择AcDbDoubleClickEdit: 类的头文件为: class CDoubl ...

  5. CAD二次开发--0.开发环境搭建及CAD层次结构

    本文章用于CAD二次开发学习工作总结,参考李冠艺著编的<深入浅出AutoCAD.NET二次开发>. 一.开发前准备: 首先开发前默认有一定的C#编程经验. 对CAD有一定的了解. 安装好V ...

  6. cad二次开发程序的绿色安装

    此问题的引入是因为一个cad二次开发软件,客户要求做成绿色安装.何为绿色安装呢?软件包copy到一台电脑上(已安装CAD),双击exe,打开的界面包含自定义的菜单.菜单的图标能正确显示.每个功能能使用 ...

  7. intersect 相交 范围_关于CAD二次开发中(范围线自相交)相交线的问题

    CAD二次开发对于毕业没多久,又是半路出家的我来说,是一个很大的挑战,遇到过很多难以解决的问题,这次在CAD二次开发遇到一个很苦恼的问题:判断 一个由线段组成的闭合区域中,是否存在着相互之间相交的线段 ...

  8. CAD 二次开发 图层操作(1)创建图层

    CAD二次开发的资料比较少,除了李冠亿先生的<深居浅出AutoCAD二次开发>这本书之外,目前没有找到合适的参考资料.现将自己工作中用的的一些方法贴出来.方便各位网友快速入门. #regi ...

  9. CAD 二次开发 图层操作(3)取得指定图层下的所有对象id

    对于CAD二次开发的人来说,可能需要对某一图层下的实体(点,线,面域,块,三维实体)进行不同的操作.下面的方法,即可实现获取指定图层名称下的所有实体ID. 输入参数为图层名称: 返回值为:对象主键集合 ...

最新文章

  1. html6个圆圈放一排,html中两个选择框如何并排放置(一)
  2. 线程同步synchronized
  3. C语言登顶!|2021年7月编程语言排行榜
  4. 三分钟教你用 Scarlet 写一个 WebSocket App
  5. Flex的事件(十四)
  6. Effective C++学习笔记(Part One:Item 1-4)
  7. 信息学奥赛一本通 1002:输出第二个整数 | OpenJudge NOI 1.1 02
  8. Oracle标准审计实战过程详解
  9. linux关闭io统计,linux 统计每个进程所占用的io数
  10. 浅谈分布式计算的开发与实现(二)
  11. BZOJ 1878: [SDOI2009]HH的项链【莫队】
  12. InvalidArchiveError(‘Error with archive D:\\Program Files\\Anaconda\\pkgs\\numpy-base-1.19.1-py36ha3
  13. matlab教程分析,MATLAB数据分析教程
  14. Java过滤微信昵称特殊字符
  15. GoLang语言:邮件群发器
  16. 介绍一个用于EOS区块链的RPC API接口的PHP开发包SDK
  17. str.substring() 的用法
  18. 百万军中取上将首级如探囊取物, 千万行里改关键源码在弹指瞬间。 功能超强的程序编辑器!
  19. Backward Elimination, Forward Selection and Stepwise
  20. 基于python的Poisson-Gumbel 泊松耿贝尔复合极值分布实现

热门文章

  1. 用友SPS和运行维护费区别的详解
  2. HTML标签——锚点链接小学习(懒癌患者的摸索之路)
  3. 儿子送给妈妈的母亲节礼物
  4. 基于内容的遥感影像场景检索
  5. mac 查看端口号是否被占用
  6. json schema多种形式_Json Schema
  7. 阿当姆斯校正程序代码MATLAB,数值分析实验教程.doc
  8. 新一代Java模板引擎Thymeleaf
  9. 计算机科学与技术(python方向)-计算机科学基础
  10. Python黑马头条推荐系统第二天 离线用户召回集与排序计算