找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1562|回复: 1

[分享] BlockOsnapOverrule

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2013-6-12 07:08:04 | 显示全部楼层 |阅读模式

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

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

×
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.Geometry;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.ApplicationServices;
  7. using System.Collections.Generic;
  8. using Autodesk.AutoCAD.GraphicsInterface;

  9. [assembly: CommandClass(typeof(AssocArrayAPI.Commands))]

  10. namespace AssocArrayAPI
  11. {
  12.     public class toverrule : DrawableOverrule
  13.     {
  14.         public override bool WorldDraw(Drawable drawable, WorldDraw Wd)
  15.         {
  16.             BlockReference myBlock = drawable as BlockReference;
  17.             if ((myBlock.Database != null))
  18.             {
  19.                 List<Entity> ListEnts = new List<Entity>();
  20.                 if (!GetExplodedEnts(myBlock, ref ListEnts))
  21.                 {
  22.                     return true;
  23.                 }
  24.                 foreach (Entity Ent in ListEnts)
  25.                 {
  26.                     Ent.WorldDraw(Wd);
  27.                     Ent.Dispose();
  28.                 }
  29.             }
  30.            // base.WorldDraw(drawable, Wd);
  31.             return true;
  32.         }

  33.         public static bool GetExplodedEnts(BlockReference myBlock, ref List<Entity> ListEnts)
  34.         {
  35.             try
  36.             {
  37.             DBObjectCollection MyDBObjColl = new DBObjectCollection();
  38.             {
  39.                 myBlock.Explode(MyDBObjColl);
  40.                 Line Line1 = new Line();
  41.                 foreach (DBObject mydbobj in MyDBObjColl)
  42.                 {
  43.                     if (mydbobj is Line)
  44.                     {
  45.                         Line1 = mydbobj as Line;
  46.                         Autodesk.AutoCAD.DatabaseServices.Polyline MyPolyLine1 = new Autodesk.AutoCAD.DatabaseServices.Polyline();
  47.                         MyPolyLine1.SetDatabaseDefaults();
  48.                         MyPolyLine1.AddVertexAt(0, new Point2d(Line1.StartPoint.X, Line1.StartPoint.Y), 0, 200, 200);
  49.                         MyPolyLine1.AddVertexAt(1, new Point2d(Line1.EndPoint.X + 3000, Line1.EndPoint.Y + 3000), 0, 200, 200);
  50.                         MyPolyLine1.Closed = true;
  51.                         ListEnts.Add(MyPolyLine1);
  52.                     }
  53.                     else
  54.                     {
  55.                       mydbobj.Dispose();
  56.                     }
  57.                 }
  58.                 Line1.Dispose();
  59.             }
  60.             MyDBObjColl.Dispose();
  61.             return true;
  62.           }
  63.              catch (Autodesk.AutoCAD.Runtime.Exception ex)
  64.             {
  65.               Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
  66.                return false;
  67.             }
  68.           }
  69.      
  70.         
  71. public override int SetAttributes(Autodesk.AutoCAD.GraphicsInterface.Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.DrawableTraits traits)
  72.         {
  73.             int res = base.SetAttributes(drawable, traits);
  74.             int test = res & 32;
  75.             if (Convert.ToBoolean(test))
  76.             {
  77.                 res = res - 32;
  78.             }
  79.             return res;
  80.         }
  81.     }

  82.     public class BlockOsnapOverrule : OsnapOverrule
  83.         {
  84.            public override void GetObjectSnapPoints( Entity e, ObjectSnapModes snapMode, System.IntPtr gsSelectionMark, Point3d pickPoint,
  85.                Point3d lastPoint, Matrix3d viewTransform, Point3dCollection snapPoints,
  86.                IntegerCollection geometryIds, Matrix3d insertionMat )
  87. {
  88. #if DEBUG
  89.    try
  90.    {
  91. #endif
  92.       BlockReference myBlock = e as BlockReference;
  93.       List<Entity> ListEnts = new List<Entity>();
  94.       if (!toverrule.GetExplodedEnts(myBlock,ref ListEnts))
  95.       {
  96.          return;
  97.       }
  98.       foreach( Entity SubEnt in ListEnts )
  99.       {
  100.          SubEnt.GetObjectSnapPoints( snapMode, gsSelectionMark.ToInt32(), pickPoint, lastPoint, viewTransform, snapPoints, geometryIds, insertionMat );
  101.          SubEnt.Dispose();
  102.       }
  103. #if DEBUG
  104.    }
  105.    catch( System.Exception ex )
  106.    {
  107.              Application.DocumentManager .MdiActiveDocument .Editor .WriteMessage ("\n***** Exception: {0}\n\n\n",ex.ToString ());
  108.           }
  109. #endif
  110. }
  111.     }

  112.     public class Commands
  113.     {
  114.         private static toverrule BlockOverrule1;
  115.         private static BlockOsnapOverrule blockOsnapOverrule1;
  116.         [CommandMethod("mmmm")]
  117.         public static void yyyyy()
  118.         {
  119.             if (BlockOverrule1 == null)
  120.             {
  121.                 BlockOverrule1 = new toverrule();
  122.                 blockOsnapOverrule1 = new BlockOsnapOverrule();
  123.                             Overrule.AddOverrule(RXClass.GetClass(typeof(BlockReference)), BlockOverrule1, false );
  124.                 Overrule.AddOverrule(RXClass.GetClass(typeof(BlockReference)),blockOsnapOverrule1 ,false);
  125.                 Overrule.Overruling = true;
  126.                 Application.DocumentManager.MdiActiveDocument.Editor.Regen();
  127.             }
  128.         }
  129.     }

评分

参与人数 1D豆 +2 收起 理由
ScmTools + 2 很给力!经验;技术要点;资料分享奖!

查看全部评分

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

已领礼包: 1632个

财富等级: 堆金积玉

发表于 2013-6-12 21:29:51 | 显示全部楼层
最近是否大家都在研究块?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-1 13:03 , Processed in 0.355481 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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