CAD开发 UCS转WCS(用户坐标转为世界坐标)

在CAD添加实体到模型空间中都是用世界坐标的点添加的。
UCS坐标是用户GetPoint()这种交互集获取得到用户坐标。
关于UCS转WCS如下:

AutoCAD .NET: Transform Picked Point from Current UCS to WCS
We are addressing a very simple task regarding AutoCAD .NET programming in this article. How to transform a picked point from the current (active) UCS to the WCS?

It sounds too obvious to metion.  That was also what we thought about it, and it explains why the topic was not covered explicitly before. However, judging from some code on web, it apparently is not the case. So, let’s take a few seconds here to have a bit review about it.

//...
 
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
 
PromptPointResult ppr = ed.GetPoint("\nSpecify base point: ");
if (ppr.Status != PromptStatus.OK)
    return;
 
Point3d baseUcs = ppr.Value;
CoordinateSystem3d cs = ucs.CoordinateSystem3d;
 
// Transform from UCS to WCS
Matrix3d mat =
    Matrix3d.AlignCoordinateSystem(
    Point3d.Origin,
    Vector3d.XAxis,
    Vector3d.YAxis,
    Vector3d.ZAxis,
    cs.Origin,
    cs.Xaxis,
    cs.Yaxis,
    cs.Zaxis
    );
 
Point3d baseWcs = baseUcs.TransformBy(mat);
Point3d curPt = baseWcs;
 
//...

Checking the code there more times, got more confused about why the simple task had to be done that way, which is redundant, inefficient, and error prone. In fact, as demonstrated hundreds of times before in our posts, a single line of code can transform the picked point, ppr.Value, from the current UCS to the WCS so easily and reliably.

//...
 
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
 
PromptPointResult ppr = ed.GetPoint("\nSpecify base point: ");
if (ppr.Status != PromptStatus.OK)
    return;
 
Point3d curPt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
 
//...

WCS转UCS只需

Point3d UCSPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem.Inverse());

参考链接:https://spiderinnet1.typepad.com/blog/2013/05/autocad-net-transform-picked-point-from-current-ucs-to-wcs.html

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网蜂工具箱坐标标注插件zbbz.vlx是一款可以应用于AutoCAD软件上的实用型插件,免费使用,可以在AutoCAD图纸进行自动坐标标注,操作简单实用。 操作方法: 1、下载解压,获得AutoCAD坐标插件zbbz.vlx文件; 2、将其放在软件安装目录Support下或常用的CAD软件目录下; 3、手工加载方法:每次使用前将zbbz.vlx用鼠标拖入CAD图形上放开即可。 4、自动加载方法:打开CAD,输入命令ap或appload按回车键将会弹出一个对话框,点击"启动组(Startup Suite)"下面的公文包图标(或"内容"(Contents…)); 6、弹出启动组一对话框,点"添加(Add…)"找到你刚才文件所保存的位置,选择zbbz.vlx文件,点"加载(Add)"即可。 7、在CAD中,输入命令zbbz按回车键,弹出设置页面,设置完毕点确定。 8、在CAD中,用鼠标点击需要标记的位置即可 更新记录: 2.54 2018.08.13 1、添加编号修改功能 2、添加语言切换功能(简体中文/English/繁體中文) 3、修复每次运行后捕捉设置消失的BUG。 2.53 2015.03.04 1、修复更新坐标时提示函数未找到的BUG 2.51 2013.06.20 1、修复坐标网格无法生成的BUG 1.78 1、新添文字背景遮挡 1.76(20100517) 修改: 1、按ESC退出无法删除引线的BUG 1.75(20100501) 修改 1、修改部分机子CAD2007以上版本无法运行的BUG 1.74(20100129) 增加: 1、自定义坐标系中两点使用对话框模式 2、添加批量标注中点的支持 修改 1、修改图层当前出错的BUG 2、修改无法直接修改自定义坐标NE值的BUG 3、修改横线长度短一些 1.71(20070630) 增加: 1、批量标注中对象为直线中点模式 修改: 1、修改批量标注时标注方位在左下、右下时标注方向BUG 2、修改批量标注时选择直线模式时无法过滤其他图元的BUG 3、修改批量标注、更新时在用户UCS模式下坐标标注均为世界坐标系问题 2007.06.06 1、更新时添加字体样式一起更新 2007.06.05 1、在CAD2008中调试通过。 2、添加预览箭头功能。 更新: 1、修改更新时线长BUG 2、修改指定字样样式,图层在文件中被清理后出错BUG 3、一些其他小BUG 2007.05.24 此次更新主要是针对广大网友们的要求进行更改,添加了箭头及字体样式的新功能,大量代码重写。能动态显示设置结果。 添加: 1、添加引线箭头样式 2、能手工选择图层、字体样式。 3、支持坐标生成文本文件及DAT文件。 更新: 1、修改更新坐标时的一些BUG 2、批量标注时添加块类别

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值