找回密码
 立即注册
查看: 2479|回复: 0

[分享] Implementing a custom AutoCAD object snap mode using .NET (redux)

[复制链接]
发表于 2014-7-30 22:04:40 来自手机 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 csharp 于 2014-7-31 07:58 编辑

http://through-the-interface.typepad.com/through_the_interface/2014/04/implementing-a-custom-autocad-object-snap-mode-using-net-redux.html

Implementing a custom AutoCAD object snap mode using .NET (redux)
I had an email from Martin Duke about this old post a couple of weeks ago. I started to update the original post but then realised that a) I couldn’t easily go that far back using Windows Live Writer and the built-in Typepad editor often messes up code in old posts when I edit them and b) there was some value in revisiting this topic again now that nearly 6 years has passed. I’ll hopefully manage to link to this updated post from the old one without things going awry.
Martin was having some trouble with text display in object snap glyphs: it worked well enough once some geometry has been drawn – even if it didn’t automatically use the colour of the other object snap glyph graphics – but it didn’t work well when a drawing has just been created or loaded. If the previously implemented object snap was used in a fresh drawing, the text didn’t get displayed.
0.jpg
As soon as additional geometry was created in the drawing, however, the text did get displayed as expected.
1.jpg
The answer, it turns out, was to use an SHX font: this allowed the transient text to be displayed properly from the start and with the colour the glyph markers should have.
2.jpg
I also took the opportunity to centre the text properly on the snap point, which is ultimately a matter of taste: I think I even moved it away from the snap point on purpose 6 years ago. ;-)
It would clearly be nice to have TrueType fonts display properly, but this is an artifact of the 2D graphics system (and is logged as an issue in our internal tracking system). The behaviour is different when using a 3D Visual Style, for whatever that’s worth.
Here’s the updated C# code that shows how this can be made to work in this way:
using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using AcGi = Autodesk.AutoCAD.GraphicsInterface; [assembly: ExtensionApplication( typeof(OsnapApp.CustomOSnapApp)) ] namespace OsnapApp
展开


I’m easing back into the swing of things after my 10+ days out of the office. I’ll hopefully get the time to post on more new AutoCAD 2015 APIs during the coming few days.
Update:
Added a fix for a crash when hovering over zero-length lines.


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2026-12-1 22:05 , Processed in 0.170631 second(s), 27 queries , Gzip On.

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表