using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.ApplicationServices; using System.Collections.Generic; using Autodesk.AutoCAD.GraphicsInterface; [assembly: CommandClass(typeof(AssocArrayAPI.Commands))] namespace AssocArrayAPI { public class toverrule : DrawableOverrule { public override bool WorldDraw(Drawable drawable, WorldDraw Wd) { BlockReference myBlock = drawable as BlockReference; if ((myBlock.Database != null)) { List ListEnts = new List(); if (!GetExplodedEnts(myBlock, ref ListEnts)) { return true; } foreach (Entity Ent in ListEnts) { Ent.WorldDraw(Wd); Ent.Dispose(); } } // base.WorldDraw(drawable, Wd); return true; } public static bool GetExplodedEnts(BlockReference myBlock, ref List ListEnts) { try { DBObjectCollection MyDBObjColl = new DBObjectCollection(); { myBlock.Explode(MyDBObjColl); Line Line1 = new Line(); foreach (DBObject mydbobj in MyDBObjColl) { if (mydbobj is Line) { Line1 = mydbobj as Line; Autodesk.AutoCAD.DatabaseServices.Polyline MyPolyLine1 = new Autodesk.AutoCAD.DatabaseServices.Polyline(); MyPolyLine1.SetDatabaseDefaults(); MyPolyLine1.AddVertexAt(0, new Point2d(Line1.StartPoint.X, Line1.StartPoint.Y), 0, 200, 200); MyPolyLine1.AddVertexAt(1, new Point2d(Line1.EndPoint.X + 3000, Line1.EndPoint.Y + 3000), 0, 200, 200); MyPolyLine1.Closed = true; ListEnts.Add(MyPolyLine1); } else { mydbobj.Dispose(); } } Line1.Dispose(); } MyDBObjColl.Dispose(); return true; } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message); return false; } } public override int SetAttributes(Autodesk.AutoCAD.GraphicsInterface.Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.DrawableTraits traits) { int res = base.SetAttributes(drawable, traits); int test = res & 32; if (Convert.ToBoolean(test)) { res = res - 32; } return res; } } public class BlockOsnapOverrule : OsnapOverrule { public override void GetObjectSnapPoints( Entity e, ObjectSnapModes snapMode, System.IntPtr gsSelectionMark, Point3d pickPoint, Point3d lastPoint, Matrix3d viewTransform, Point3dCollection snapPoints, IntegerCollection geometryIds, Matrix3d insertionMat ) { #if DEBUG try { #endif BlockReference myBlock = e as BlockReference; List ListEnts = new List(); if (!toverrule.GetExplodedEnts(myBlock,ref ListEnts)) { return; } foreach( Entity SubEnt in ListEnts ) { SubEnt.GetObjectSnapPoints( snapMode, gsSelectionMark.ToInt32(), pickPoint, lastPoint, viewTransform, snapPoints, geometryIds, insertionMat ); SubEnt.Dispose(); } #if DEBUG } catch( System.Exception ex ) { Application.DocumentManager .MdiActiveDocument .Editor .WriteMessage ("\n***** Exception: {0}\n\n\n",ex.ToString ()); } #endif } } public class Commands { private static toverrule BlockOverrule1; private static BlockOsnapOverrule blockOsnapOverrule1; [CommandMethod("mmmm")] public static void yyyyy() { if (BlockOverrule1 == null) { BlockOverrule1 = new toverrule(); blockOsnapOverrule1 = new BlockOsnapOverrule(); Overrule.AddOverrule(RXClass.GetClass(typeof(BlockReference)), BlockOverrule1, false ); Overrule.AddOverrule(RXClass.GetClass(typeof(BlockReference)),blockOsnapOverrule1 ,false); Overrule.Overruling = true; Application.DocumentManager.MdiActiveDocument.Editor.Regen(); } } } }