- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- 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<Entity> ListEnts = new List<Entity>();
- 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<Entity> 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<Entity> ListEnts = new List<Entity>();
- 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();
- }
- }
- }
|
评分
-
查看全部评分
|