- 积分
- 7301
- 明经币
- 个
- 注册时间
- 2015-12-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 Dani1988 于 2023-10-25 20:42 编辑
先看效果,再发源码。。。。。
- [CommandMethod(nameof(CS5))]
- public static void CS5()
- {
- // 创建文字
- var db = Env.Database;
- DBText upText = new DBText();
- DBText downText = new DBText();
- upText.SetDatabaseDefaults(db);
- downText.SetDatabaseDefaults(db);
- upText.TextString = "我是升哥2018";
- downText.TextString = "QQ:674971560";
- double textHeight = 300;
- upText.Height = downText.Height = textHeight;
- // 设置对齐
- upText.HorizontalMode = downText.HorizontalMode = TextHorizontalMode.TextLeft;
- upText.VerticalMode = downText.VerticalMode = TextVerticalMode.TextVerticalMid;
- upText.AdjustAlignment(db);
- downText.AdjustAlignment(db);
- // 调整位置
- upText.Move(upText.Position, Point3d.Origin + new Vector3d(0, textHeight*0.2, 0));
- downText.Move(downText.Position, Point3d.Origin + new Vector3d(0, -textHeight*1.2, 0));
- // 计算高度
- var textWidth = Math.Max(upText.GeometricExtents.MaxPoint.X - upText.GeometricExtents.MinPoint.X, downText.GeometricExtents.MaxPoint.X - downText.GeometricExtents.MinPoint.X);
- // 创建文字线
- Line textLine = new Line(Point3d.Origin, new Point3d(textWidth, 0, 0));
- //textLine.ColorIndex = 3;
- textLine.SetDatabaseDefaults(db);
- // 获取标注位置
- var r1 = Env.Editor.GetPoint("\n选择点1");
- if (r1.Status != PromptStatus.OK)
- return;
- var pt1 = r1.Value.Ucs2Wcs();
- // 创建引线
- Line leaderLine = new Line(pt1, Point3d.Origin);
- //leaderLine.ColorIndex = 3;
- leaderLine.SetDatabaseDefaults(db);
- // 创建拖拽类
- using var j1 = new JigEx((mpw, _) =>
- {
- var pt2 = mpw;
- leaderLine.EndPoint = pt2;
- leaderLine.ColorIndex = 3;
- textLine.ColorIndex = 3;
- Matrix3d mt = Matrix3d.Displacement(pt2 - (pt2.X >= pt1.X ? textLine.StartPoint : textLine.EndPoint));
- textLine.TransformBy(mt);
- upText.TransformBy(mt);
- downText.TransformBy(mt);
- });
- j1.DatabaseEntityDraw(wd =>
- {
- wd.Geometry.Draw(textLine);
- wd.Geometry.Draw(leaderLine);
- wd.Geometry.Draw(upText);
- wd.Geometry.Draw(downText);
- });
- j1.SetOptions(pt1, CursorType.Crosshair, "\n选择下一点");
- // 开始拖拽
- var r2 = Env.Editor.Drag(j1);
- if (r2.Status != PromptStatus.OK)
- return;
- // 加入数据库
- using var tr = new DBTrans();
- tr.CurrentSpace.AddEntity(leaderLine, textLine, upText, downText);
- }
|
|