- 积分
- 846
- 明经币
- 个
- 注册时间
- 2005-7-6
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- * 日期: 2012-3-8 * 时间: 15:24 * using System;using DNA;using Autodesk;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Colors;namespace ZZXDIM{ /// /// Description of MyClass. /// public class MyClass { [CommandMethod("CC", CommandFlags.UsePickSet)] public void dimcc() { Database db = HostApplicationServices.WorkingDatabase; Document acDoc = Application.DocumentManager.MdiActiveDocument; using (Transaction trans = db.TransactionManager.StartTransaction()) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptEntityResult oj = ed.GetEntity("请选择C角处的直线 "); Point3d po3 = oj.PickedPoint; Point3d po1 = ed.GetPoint("请选择标注放置位置: ").Value; po1 = Tools.UcsToWcs(po1); Point3d po2 = new Point3d(); ObjectId id = oj.ObjectId; ObjectId STYID = TEXTSTYE(); po3 = Tools.UcsToWcs(po3); double L = 1.2; if ((oj.Status == PromptStatus.OK) && (po1 != new Point3d(0, 0, 0))) { Entity ent1 = (Entity)trans.GetObject(id, OpenMode.ForRead); string ent2type = ent1.GetType().ToString(); if (ent2type == "Autodesk.AutoCAD.DatabaseServices.Line") { Line l1 = (Line)trans.GetObject(id, OpenMode.ForRead); Point3d plend = l1.EndPoint; Point3d plstr = l1.StartPoint; double xleng = Math.Abs(plend.X - plstr.X); double yleng = Math.Abs(plend.Y - plstr.Y); po2 = new Point3d((plstr.X + plend.X) / 2, (plstr.Y + plend.Y) / 2, 0); L = xleng; } if (ent2type == "Autodesk.AutoCAD.DatabaseServices.Polyline") { Polyline pl = (Polyline)trans.GetObject(id, OpenMode.ForRead); Point3d tty = pl.GetClosestPointTo(po3, true); double ds = pl.GetParameterAtPoint(tty); int iiy = Convert.ToInt32(Math.Floor(ds));//点的是哪一段上的点 Point2d pt1 = pl.GetPoint2dAt(iiy); int gs = pl.NumberOfVertices; Point2d pt2 = new Point2d(); if (gs > iiy + 1) { pt2 = pl.GetPoint2dAt(iiy + 1); } else { pt2 = pl.GetPoint2dAt(0); } double xleng = Math.Abs(pt1.X - pt2.X); double yleng = Math.Abs(pt1.Y - pt2.Y); po2 = new Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, 0); L = xleng; } //样式问题需要进行 //文字高度求解 double tt = System.Convert.ToDouble(Application.GetSystemVariable("DIMTXT")); double tt2 = System.Convert.ToDouble(Application.GetSystemVariable("DIMSCALE")); //建立文字 MText acMText = new MText(); acMText.SetDatabaseDefaults(); acMText.Contents = "C" + L; acMText.Location = po1; acMText.Width = 2; if (tt * tt2 > 0) { acMText.TextHeight = tt * tt2; } acMText.Color = Color.FromColorIndex(ColorMethod.ByAci, 41); if (po1.X < po2.X) { acMText.Attachment = AttachmentPoint.MiddleRight; } else { acMText.Attachment = AttachmentPoint.MiddleLeft; } Tools.AddEntities(new Entity[] { acMText }); // 建立引线标注leader Leader acLdr = new Leader(); acLdr.SetDatabaseDefaults(); acLdr.AppendVertex(po2); ; acLdr.AppendVertex(po1); acLdr.HasArrowHead = true; Tools.AddEntities(new Entity[] { acLdr }); acLdr.Annotation = acMText.ObjectId; acLdr.EvaluateLeader(); trans.Commit(); } else { ed.WriteMessage("所给条件不完全,无法完成指command"); } } } public ObjectId TEXTSTYE() { Database db = HostApplicationServices.WorkingDatabase; Document acDoc = Application.DocumentManager.MdiActiveDocument; using (Transaction trans = db.TransactionManager.StartTransaction()) { ObjectId STYID; TextStyleTable lt = (TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite); if (lt.Has("ZZX")) { STYID = lt["ZZX"]; Application.SetSystemVariable("TEXTSTYLE", "ZZX"); } else { STYID = lt["Standard"]; } trans.Commit(); return STYID; } } }}
|
|