.NET CAD二次開發學習第一天

来源:https://www.cnblogs.com/yannisCad/archive/2019/04/09/10677522.html
-Advertisement-
Play Games

基於浩辰CAD2019 需求: 開發線轉圓簡單命令。命令過程:1) 請選擇圖中直線(要求支持一次選多個):2) 彈出對話框,輸入圓的圖層名和半徑3) 點對話框中確定按鈕,結束命令。命令執行效果:所選每條直線的起點和終點處,自動生成兩個圓;同時,所有直線自動整體平移MOVE一個向量AcGeVector ...


基於浩辰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)
{

}
}
}


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 指針很簡單 引子 學電腦語言,首先推薦C語言.無論是數據結構還是演算法,站在C語言的角度,會讓我們理解的更加清晰透徹. 但是,指針不太"友好",讓很多人抓狂,頭疼.不少人選擇了放棄,繞行.百度上有千千萬個解決方法,而我們放棄的理 由和簡單,路在腳下,向前還?是向後? C語言之所以經久不衰,就是因為指 ...
  • 每種方法中上面的是Excel的行數,下麵的是Excel的列數。方法七:經過加工修改已經可以讀出來的是有效數據行 using Excel = Microsoft.Office.Interop.Excel;//Excel表讀寫 Excel.Application app = new Excel.Appl ...
  • 原文鏈接:https://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code-first.aspx StringLength特性可以應用於實體的string類型的屬性上,它 ...
  • 原文鏈接:https://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-in-code-first.aspx MaxLength特性指定了屬性的值所允許的最大值,然後在 ...
  • 最近在學WebSocket,服務端需要監聽多個WebSocket客戶端發送的消息。 開始的解決方法是每個WebSocket客戶端都添加一個線程進行監聽,代碼如下: /// <summary> /// 監聽埠 創建WebSocket /// </summary> /// <param name="h ...
  • 備註:本人使用開發工具:VS2017,.NET Core 2.2,其中VS2017原本自帶2.1,我單獨從官網下載了2.2的程式集安裝包,但是沒有下配套的運行環境,運行項目時出了一個問題。 以下是我在發佈Core項目後部署到IIS後運行時遇到的一些問題: 1-發佈設置: 在發佈過程中,項目一直還原n ...
  • [CommandMethod("CBline")] //對稱畫線 public void CBline() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor edit = doc.Editor; Databa ...
  • 主要代碼: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using GrxCAD.Runtime;using GrxCAD ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...