-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk..DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Colors;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Text.RegularExpressions;
- using System.Collections;
- namespace YFBZ
- {
- public class Class1
- {
- const int WM_RBUTTONDOWN = 516;
- int flag = 0;
- private void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e)
- {
- if (e.Message.message == WM_RBUTTONDOWN)
- {
- flag = 1;
- }
- }
- [CommandMethod("yfzj")]
- public void yfbzj()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- handle01:
- PromptEntityOptions options = new PromptEntityOptions(" \n请选择圆弧");
- options.SetRejectMessage("\n所选择实体不是圆弧,请重新选择");
- options.AddAllowedClass(typeof(Arc), true);
- PromptEntityResult per = ed.GetEntity(options);
- ObjectId arced;
- if (per.Status == PromptStatus.Cancel)
- {
- return;
- }
- if (per.Status == PromptStatus.OK)
- {
- arced = per.ObjectId;
- }
- else
- {
- arced = per.ObjectId;
- return;
- }
- using (DocumentLock acLock = doc.LockDocument())
- {
- using (Transaction tran = db.TransactionManager.StartOpenCloseTransaction())
- {
- Arc arc = tran.GetObject(arced, OpenMode.ForRead) as Arc;
- Point3d pt1 = arc.StartPoint;
- Point3d pt2 = arc.EndPoint;
- Point3d cen = arc.Center;
- Line line1 = new Line(cen, pt1);
- Line line2 = new Line(cen, pt2);
- line1.ColorIndex = 5;
- line2.ColorIndex = 5;
- double R = arc.Radius;
- double Length = arc.Length;
- double l = arc.GetDistanceAtParameter(Length / 2);
- Point3d pt = arc.GetPointAtDist(Length / 2);
- double cenRo = Math.Abs(arc.StartAngle - arc.EndAngle);
- double BottomRo = (Math.PI - cenRo) / 2;
- double xianLength = Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) + (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y));
- double T = xianLength / 2 / Math.Sin(BottomRo);
- Point3d pt3 = xTextStyleTools.midPoint(cen, pt);
- db.AddToModelSpace(line1);
- db.AddToModelSpace(line2);
- for (; ; )
- {
- Point3d point1 = pt3;
- DBText text1 = new DBText();
- text1.TextString="R = "+R.ToString("0.000");
- ObjectId text1Id = db.AddToModelSpace(text1);
- DBText text2 = new DBText();
- //text1.Height = 3;
- text2.TextString="K = "+ Length.ToString("0.000");
- //text2.Height = 3;
- ObjectId text2Id = db.AddToModelSpace(text2);
- DBText text3 = new DBText();
- text3.TextString = "α = "+ xTextStyleTools.DFM(cenRo);
- ObjectId text3Id = db.AddToModelSpace(text3);
- DBText text4 = new DBText();
- text4.TextString = "T = " + T.ToString("0.000");
- ObjectId text4Id = db.AddToModelSpace(text4);
- YFBZ.EntYFJip pointBz = new YFBZ.EntYFJip(text1Id, text2Id, text3Id,text4Id, point1);
- PromptResult resJip = ed.Drag(pointBz);
- if (resJip.Status == PromptStatus.Cancel)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- text1 = (DBText)tr.GetObject(pointBz.m_text1, OpenMode.ForWrite);
- text1.Erase();
- text2 = (DBText)tr.GetObject(pointBz.m_text2, OpenMode.ForWrite);
- text2.Erase();
- text3 = (DBText)tr.GetObject(pointBz.m_text3, OpenMode.ForWrite);
- text3.Erase();
- text4 = (DBText)tr.GetObject(pointBz.m_text4, OpenMode.ForWrite);
- text4.Erase();
- tr.Commit();
- }
- break;
- }
- Autodesk.AutoCAD.ApplicationServices.Application.PreTranslateMessage += new PreTranslateMessageEventHandler(Application_PreTranslateMessage);
- if (flag == 1)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
|