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

[分享] Overruling explode in AutoCAD 2010 using .NET

[复制链接]
发表于 2013-5-27 01:37:28 | 显示全部楼层 |阅读模式

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

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

×

I am really starting to love the new Overrule API in AutoCAD 2010, and I still feel as though I’m just scratching the surface. This question came in overnight from Danny Polkinhorn (thanks, Danny! :-) :

It's exciting to see a very usable implementation of 'custom' objects in .NET. Obviously, this implementation protects what could be proprietary business intelligence from being sent around, but it brings up a question. What process would you use to 'explode' these elements so that you could send the drawing to someone without your code, but with the custom elements in it?

My first thought was to just see what happened when the EXPLODE command encountered the overruled lines & circles created with the code in the last post. At first I was a little discouraged:

Command: EXPLODE
Select objects: Specify opposite corner: 9 found
9 were not able to be exploded.
Select objects: *Cancel*
None found.
My worry, at this stage, was that the EXPLODE command was excluding “simple” objects such as lines and circles during its selection process, which would mean that even if we were able to overrule the explode behaviour of our special lines & circles we would have difficulty getting our code called. Thankfully this is not the case, but I only found this out as I implemented a TransformOverrule and overruled Explode for my lines and circles.

Before looking into the specifics, here’s a quick list of the various Overrules available in AutoCAD 2010 with their overrideable methods:


Overrule (the base class)
  • GripOverrule
    • GetGripPoints
    • GetStretchPoints
    • MoveGripPointsAt
    • MoveStretchPointsAt
    • OnGripStatusChanged
  • OsnapOverrule
    • GetObjectSnapPoints
    • IsContentSnappable
  • SubentityOverrule
    • AddSubentPaths
    • DeleteSubentPaths
    • GetCompoundObjectTransform
    • GetGripPointsAtSubentPath
    • GetGsMarkersAtSubentPath
      GetSubentClassId
    • GetSubentPathGeomExtents
    • GetSubentPathsAtGsMarker
    • MoveGripPointsAtSubentPaths
    • OnSubentGripStatusChanged
    • SubentPtr
    • TransformSubentPathsBy
  • TransformOverrule
    • CloneMeForDragging
    • Explode
    • GetTransformedCopy
    • HideMeForDragging
    • TransformBy
  • GeometryOverrule
    • GetGeomExtents
    • IntersectWith
  • PropertiesOverrule
    • GetClassID
    • List
  • ObjectOverrule
    • Cancel
    • Close
    • DeepClone
    • Erase
    • Open
    • WblockClone
  • DrawableOverrule
    • SetAttributes
    • ViewportDraw
    • ViewportDrawLogicalFlags
    • WorldDraw

So far we’ve only actually used the DrawableOverrule, implementing SetAttributes() and WorldDraw().

[Aside: as I compiled the above list I had one of those “woah” moments. It was bit like the feeling I remember as a child while reading “The Elfstones of Shannara”, the – much better – sequel to “The Sword of Shannara” (Terry Brooks’ first fantasy novel). In “The Sword of Shannara” the main character used some elfstones for protection, but it’s only in the sequel that you find out just how powerful they are, and that they’re actually only one of several different varieties of elfstones. Anyone who hasn’t been a fantasy/sci-fi geek in their time is almost certainly rolling their eyes (if they’re not being physically sick) at this point, so I’d better get back on track. I still enjoy a good sci-fi novel, by the way, but these days I find I can’t do fantasy that isn’t Tolkien.]

It’s clear that to customize the explode for our lines and circles we’re going to need a TransformOverrule.

Here’s the C# code from the last post, with our additional TransformOverrules. I’ve changed a few of the class names to reflect the fact they are overrule draw behaviour vs. transform behaviour, but otherwise the code is basically the same as last time, apart from the addition of the LinePipeTransformOverrule and CirclePipeTransformOverrule classes (and the code to register/unregister them).

The Explode functions take pretty much the same geometry we used to draw the “enhanced” objects, but this time it gets returned to the system and is used to replace the original entities. This code doesn’t do anything fancy about the entity colour, etc., but we could certainly do so, if we chose.

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.GraphicsInterface; using Autodesk.AutoCAD.Colors; namespace Overrules { public abstract class PipeDrawOverrule : DrawableOverrule { const string regAppName = "TTIF_PIPE"; public PipeDrawOverrule() { // Tell AutoCAD to filter on our application name // (this means our overrule will only be called // on objects possessing XData with this name)
展开

As before we can create a bunch of lines and circles, assign them radii using the MP command, and then display them using the OVERRULE1 command:


0.jpg

Now when we perform our EXPLODE, selecting the various objects, and instead of a rejection message we get a set of Solid3D objects replacing our lines and circles:

1.jpg

Too cool! :-)

As you can hopefully see, the more you look at the Overrule API in AutoCAD 2010, the more power you uncover. Keep the comments & questions coming – it’s fun to see how this little application is evolving based on your feedback.


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

本版积分规则

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

GMT+8, 2026-12-1 21:45 , Processed in 0.188618 second(s), 33 queries , Gzip On.

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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