当前位置: 首页 > news >正文

CAD xy坐标标注(跟随鼠标位置实时移动)——C#插件实现

效果如下:

(使用方法:命令行输入 “netload” 加载此dll插件,然后输入“zbbz”运行,选择文件夹即可。支持字体大小变化,输入“zbbd”可设置坐标字体变大或缩小的倍数)

部分代码如下:


#if DEBUG
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.GraphicsInterface;
using IFoxCAD.Cad;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using System.Windows.Shapes;namespace IfoxDemo
{public class Class1{[CommandMethod("XX")]public void Jigworlddraw(){//Debugger.Break();double dist = 5;//横线的长度double textHeight = 1;double vertDist = textHeight * 1.2;//坐标标注距离横向的长度Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;Database db = HostApplicationServices.WorkingDatabase;PromptPointResult ppr = ed.GetPoint("\n请指定坐标点:\n");if (ppr.Status != PromptStatus.OK){return;}Point3d pointStart = ppr.Value;//获取第一个点var m_Polyline = new Polyline();//定义线m_Polyline.AddVertexAt(0, new Point2d(pointStart.X, pointStart.Y), 0, 0, 0);double mpwX = pointStart.X;double mpwY= pointStart.Y;m_Polyline.AddVertexAt(1, new Point2d(mpwX, mpwY), 0, 0, 0);m_Polyline.AddVertexAt(2, new Point2d(mpwX, mpwY), 0, 0, 0);DBText textx = new DBText()//定义x坐标{Height = textHeight,TextString = Math.Round(pointStart.X, 3).ToString(),//Position = new Point3d(mpwX + dist / 2, mpwY + vertDist, 0)};DBText texty = new DBText()//定义y坐标{Height = textHeight,TextString = Math.Round(pointStart.Y, 3).ToString(),//Position = new Point3d(mpwX + dist / 2, mpwY - vertDist, 0)};Entity[] allentity = new Entity[3] { m_Polyline ,textx,texty};using var jig = new JigEx((mpw, queue) =>{mpwX = mpw.X;mpwY = mpw.Y;m_Polyline.SetPointAt(1,new Point2d (mpw.X,mpw.Y));if (mpw.X >= pointStart.X){m_Polyline.SetPointAt(2, new Point2d(mpw.X + dist, mpw.Y));textx.Position = new Point3d(mpwX + dist / 2, mpwY + vertDist, 0);texty.Position = new Point3d(mpwX + dist / 2, mpwY - vertDist, 0);textx.HorizontalMode = TextHorizontalMode.TextMid;textx.VerticalMode = TextVerticalMode.TextVerticalMid;texty.HorizontalMode = TextHorizontalMode.TextMid;texty.VerticalMode = TextVerticalMode.TextVerticalMid;textx.AlignmentPoint = textx.Position;texty.AlignmentPoint = texty.Position;textx.AdjustAlignment(db);texty.AdjustAlignment(db);}else{m_Polyline.SetPointAt(2, new Point2d(mpw.X - dist, mpw.Y));textx.Position = new Point3d(mpw.X - dist / 2, mpw.Y + vertDist, 0);texty.Position = new Point3d(mpw.X - dist / 2, mpw.Y - vertDist, 0);textx.HorizontalMode = TextHorizontalMode.TextMid;textx.VerticalMode = TextVerticalMode.TextVerticalMid;texty.HorizontalMode = TextHorizontalMode.TextMid;texty.VerticalMode = TextVerticalMode.TextVerticalMid;textx.AlignmentPoint = textx.Position;texty.AlignmentPoint = texty.Position;textx.AdjustAlignment(db);texty.AdjustAlignment(db);}});jig.DatabaseEntityDraw(worlddraw => worlddraw.Geometry.Draw(allentity));jig.SetOptions("\n选注记点");var r1 = jig.Drag();if (r1.Status != PromptStatus.OK)return;using var tr = new DBTrans();tr.CurrentSpace.AddEntity(allentity);}[CommandMethod("XXX")]public void Jig(){double dist = 3;//横线的长度double textHeight = 1;double vertDist = textHeight*1.2;//坐标标注距离横向的长度Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;Database db = HostApplicationServices.WorkingDatabase;PromptPointResult ppr = ed.GetPoint("\n请指定坐标点:\n");if (ppr.Status != PromptStatus.OK){return;}Point3d pointStart = ppr.Value;using var jig = new JigEx((mpw, queue) =>{var m_Polyline = new Polyline();m_Polyline.AddVertexAt(0, new Point2d(pointStart.X, pointStart.Y), 0, 0, 0);// 初始时,第二和第三个点设置为与第一个点相同(将在Sampler中更新)m_Polyline.AddVertexAt(1, new Point2d(mpw.X+0.1, mpw.Y+0.1), 0, 0, 0);DBText textx = new DBText() { Height = textHeight, TextString = Math.Round(pointStart.X, 3).ToString(),//HorizontalMode = TextHorizontalMode.TextMid,VerticalMode = TextVerticalMode.TextVerticalMid };DBText texty = new DBText() { Height = textHeight, TextString = Math.Round(pointStart.Y, 3).ToString(),//HorizontalMode = TextHorizontalMode.TextMid,VerticalMode = TextVerticalMode.TextVerticalMid };// textx.AdjustAlignment(db);//texty.AdjustAlignment(db);if (mpw.X>= pointStart.X){m_Polyline.AddVertexAt(2, new Point2d(mpw.X+ dist, mpw.Y+0.1), 0, 0, 0);textx.Position = new Point3d(mpw.X + dist / 2, mpw.Y + vertDist, 0);texty.Position = new Point3d(mpw.X + dist / 2, mpw.Y - vertDist, 0);textx.HorizontalMode = TextHorizontalMode.TextMid;textx.VerticalMode = TextVerticalMode.TextVerticalMid;texty.HorizontalMode = TextHorizontalMode.TextMid;texty.VerticalMode = TextVerticalMode.TextVerticalMid;textx.AlignmentPoint = textx.Position;texty.AlignmentPoint = texty.Position;textx.AdjustAlignment(db);texty.AdjustAlignment(db);}else{m_Polyline.AddVertexAt(2, new Point2d(mpw.X - dist, mpw.Y+0.1), 0, 0, 0);textx.Position = new Point3d(mpw.X - dist / 2, mpw.Y + vertDist, 0);texty.Position = new Point3d(mpw.X - dist / 2, mpw.Y - vertDist, 0);textx.HorizontalMode = TextHorizontalMode.TextMid;textx.VerticalMode = TextVerticalMode.TextVerticalMid;texty.HorizontalMode = TextHorizontalMode.TextMid;texty.VerticalMode = TextVerticalMode.TextVerticalMid;textx.AlignmentPoint = textx.Position;texty.AlignmentPoint = texty.Position;textx.AdjustAlignment(db);texty.AdjustAlignment(db);}m_Polyline.Closed = false; // 确保多段线不是闭合的queue.Enqueue(m_Polyline);queue.Enqueue(textx);queue.Enqueue(texty);});jig.SetOptions("\n选下一个点");var r1 = jig.Drag();if (r1.Status != PromptStatus.OK)return;using var tr = new DBTrans();tr.CurrentSpace.AddEntity(jig.Entities);}}
}
#endif

global using System;
global using IfoxDemo;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using Autodesk.AutoCAD.ApplicationServices;
global using Autodesk.AutoCAD.EditorInput;
global using Autodesk.AutoCAD.Runtime;
global using Autodesk.AutoCAD.Geometry;
global using Autodesk.AutoCAD.DatabaseServices;
global using IFoxCAD.Cad;
global using Application = Autodesk.AutoCAD.ApplicationServices.Application;
global using Polyline = Autodesk.AutoCAD.DatabaseServices.Polyline;
namespace IfoxDemo
{public class GlobalUsing{}
}

(CAD二次开发插件制作)见↓↓↓↓


http://www.mrgr.cn/news/81012.html

相关文章:

  • 使用qemu搭建armv7嵌入式开发环境
  • 基于SSM+Vue的个性化旅游推荐系统
  • 从想法到实践:Excel 转 PPT 应用的诞生之旅
  • uniapp blob格式转换为video .mp4文件使用ffmpeg工具
  • javase-15、正则表达式
  • 【序】前端监控:打造高效稳定的用户体验
  • 备忘一个FDBatchMove数据转存的问题
  • 分析excel硕士序列数据提示词——包含对特征的筛选,非0值的过滤
  • Halcon单相机+机器人=眼在手上#标定心得
  • SQL进阶技巧:如何计算商品需求与到货队列表进出计划?
  • Linux Shell 脚本编程基础知识篇(一)
  • Restaurants WebAPI(三)——Serilog/FluenValidation
  • Jenkins
  • lc148链表排序——链表版归并排序
  • AI的进阶之路:从机器学习到深度学习的演变(二)
  • 【老白学 Java】泛型应用 - 卡拉 OK(四)
  • git merge 冲突 解决 show case
  • FFmpeg 4.3 音视频-多路H265监控录放C++开发二十一.2,RTP协议-RTP协议概述,协议详情
  • JS数组方法汇总
  • 【算法】编程拓展-C语言-期末复习
  • 代码随想录算法训练营第十一天-239.滑动窗口最大值
  • 基于pytorch的深度学习基础3——模型创建与nn.Module
  • 009 Qt_显示类控件_QLCDNumber、ProgressBar、Calendar
  • 深度学习Python基础(2)
  • 移植 OLLVM 到 LLVM18,修复控制流平坦化报错
  • EdgeX Core Service 核心服务之 Meta Data 元数据