日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#之CAD二次开发(10) 用户交互之选择集

發布時間:2024/3/24 C# 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#之CAD二次开发(10) 用户交互之选择集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 0. 前言

?

CAD中通過用戶交互來選擇對象,也可以通過.NET API模擬不同對象選擇選項。

當執行多個選擇集時,可以創建一個ObjectIdCollection對象來跟蹤已選擇的對象。

可以用如下的函數進行選擇對象:

?

1. GetSelection() 用戶在圖形中選擇實體2. SelectAll() 選擇所有實體3. SelectCrossingWindow() 選擇窗口及和窗口四邊相交的實體4. SelectCrossingPolygon 選擇多邊形中及和多邊形相交的實體5. SelectFence 欄選6. SelectImplied 選擇當前圖形中已經選擇的實體7. SelectLast 選擇圖形中最后一盒繪制的實體8. SelectPrevious 選擇上一個選擇集9. SelectWindows 選擇窗口中的實體10. SelectWindowsPolygon 選擇多邊形中的實體11. SelectCrossingWindow 通過點坐標選擇圖形

?

# 1. 選擇集過濾

?

如果我們只需要選擇圖形中的部分文件就需要定義過濾規則

選擇過濾器有一對TypedValue參數構成,TypedValue的第一個參數是過濾器的類型(例如 對象),第二個參數是需要過濾的值(例如圓)。

過濾器類型的一個DXF組碼,用于指定使用何種過濾器

常用過濾器類型列表:

?

?

例如只選取圖形中的圓形:

?

# 2. 示例代碼

?

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace _05_選擇集 {public class Class1{[CommandMethod("SeleDemo")]public void SeleDemo(){Database db = HostApplicationServices.WorkingDatabase;Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;//PromptSelectionResult psr = ed.SelectAll(); // 選擇窗口中所有圖形// 只選擇窗口中的圓形TypedValue[] values = new TypedValue[]{new TypedValue((int)DxfCode.Start,"Circle")};SelectionFilter filter = new SelectionFilter(values);// 過濾器//PromptSelectionResult psr = ed.GetSelection(filter); // 選取圖形對象//if(psr.Status == PromptStatus.OK)//{// SelectionSet sSet = psr.Value;// this.ChangeColor(sSet);//}PromptSelectionResult psr = ed.GetSelection(filter);List<ObjectId> ids = new List<ObjectId>();if (psr.Status == PromptStatus.OK){SelectionSet sSet = psr.Value;List<Point3d> points = new List<Point3d>();points = this.GetPoint(sSet);for (int i = 0; i < points.Count; i++){PromptSelectionResult ss1 = ed.SelectCrossingWindow(points.ElementAt(i), points.ElementAt(i));ids.AddRange(ss1.Value.GetObjectIds());}}this.ChangeColor(ids);}private List<Point3d> GetPoint(SelectionSet sSet){List<Point3d> points = new List<Point3d>();ObjectId[] ids = sSet.GetObjectIds();Database db = HostApplicationServices.WorkingDatabase;using (Transaction trans = db.TransactionManager.StartTransaction()){for (int i = 0; i < ids.Length; i++){Entity ent = (Entity)ids[i].GetObject(OpenMode.ForRead);Point3d center = ((Circle)ent).Center;double radius = ((Circle)ent).Radius;points.Add(new Point3d(center.X + radius, center.Y, center.Z));}trans.Commit();}return points;}/// <summary>/// 改變顏色/// </summary>/// <param name="sSet">選取對象</param>private void ChangeColor(SelectionSet sSet){ObjectId[] ids = sSet.GetObjectIds();Database db = HostApplicationServices.WorkingDatabase;using (Transaction trans = db.TransactionManager.StartTransaction()){for (int i = 0; i < ids.Length; i++){Entity ent = (Entity)ids[i].GetObject(OpenMode.ForWrite);ent.ColorIndex = 1; // 紅色}trans.Commit();}}private void ChangeColor(List<ObjectId> ids){Database db = HostApplicationServices.WorkingDatabase;using (Transaction trans = db.TransactionManager.StartTransaction()){for (int i = 0; i < ids.Count; i++){Entity ent = (Entity)ids[i].GetObject(OpenMode.ForWrite);ent.ColorIndex = 3; // 紅色}trans.Commit();}}} }

?

原文請關注公眾號:數據智能筆記

?

說明一下:圖片為什么帶水印,我是從我的知乎轉載過來的,我要在知乎和公眾號一起發文,所以沒有多余時間再編輯一個平臺了,可以關注我的公眾號看原文!

總結

以上是生活随笔為你收集整理的C#之CAD二次开发(10) 用户交互之选择集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。