打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CAD二次开发 学习笔记(1)
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: CommandClass(typeof(JigTest.LineJig))]
namespace JigTest
{
/// <summary>
/// 命令类
/// </summary>
public class LineJig
{
/// <summary>
/// 命令方法
/// </summary>
[CommandMethod('linejig')]
public void DoIt()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions options = new PromptPointOptions('\n 指定起点');
ed.WriteMessage('\n 准备接收用户输入的点');
PromptPointResult result = ed.GetPoint(options);//阻塞方法
ed.WriteMessage('\n 已获取用户输入的点');
ed.WriteMessage($'\n 起点坐标:{result.Value.X},{result.Value.Y},{result.Value.Z}');
Database db = Application.DocumentManager.MdiActiveDocument.Database;
LineJigImpl jig = new LineJigImpl(result.Value);
Application.DocumentManager.MdiActiveDocument.Editor.Drag(jig);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(jig.GetEntity());
tr.AddNewlyCreatedDBObject(jig.GetEntity(),true);
tr.Commit();
}
}
}
/// <summary>
/// Jig实现类
/// </summary>
class LineJigImpl : EntityJig
{
Point3d m_StartPoint, m_EndPoint;
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
/// <summary>
/// 构造函数
/// </summary>
/// <param name='start'>起点</param>
public LineJigImpl(Point3d start) : base(new Line())
{
editor.WriteMessage('\n 执行构造函数');
m_StartPoint = start;
editor.WriteMessage($'\n m_StartPoint初始值:{m_StartPoint}');
editor.WriteMessage($'\n m_EndPoint默认值:{m_EndPoint}');
}
/// <summary>
/// 动态/即时/实时采样器
/// </summary>
/// <param name='prompts'>即时提示</param>
/// <returns></returns>
protected override SamplerStatus Sampler(JigPrompts prompts)
{
editor.WriteMessage('\n 执行Sampler;');
JigPromptPointOptions options = new JigPromptPointOptions('\n 指定终点');
options.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted;
PromptPointResult result = prompts.AcquirePoint(options);
Point3d tempPoint = result.Value;
if (tempPoint != m_EndPoint) m_EndPoint = tempPoint;
else return SamplerStatus.NoChange;
if (result.Status == PromptStatus.Cancel) return SamplerStatus.Cancel;
else return SamplerStatus.OK;
}
/// <summary>
/// (动态/即时/实时)更新显示/动态显示
/// </summary>
/// <returns></returns>
protected override bool Update()
{
editor.WriteMessage('\n 执行Update;');
try
{
((Line)Entity).StartPoint = m_StartPoint;
((Line)Entity).EndPoint = m_EndPoint;
editor.WriteMessage($'\n m_EndPoint当前值:{m_EndPoint}');
}
catch (System.Exception)
{
return false;
}
return true;
}
/// <summary>
/// 获取实体,便于外部调用
/// </summary>
/// <returns></returns>
public Entity GetEntity()
{ return Entity; }
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VBA和VB应用程序之异同和相互移植
AutoCAD C#二次开发
批量获取图形视图中心坐标
C# 应用 - 使用 HttpWebRequest 发起 Http 请求
C#操作CAD
WPF 颜色渐变
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服