欢迎加我的QQ群:193522571,一起来讨论、交流!

AutoCAD.Net/C#.Net QQ群:193522571 镜像mirror后原来块实体中的XDATA丢失了?

更多讨论请加我的QQ群:193522571

下面代码是我前面的代码,发现对于块参照,镜像后,XDATA中会丢失!

        public static ObjectId Mirror(this ObjectId id, Point3d mirrorPt1, Point3d mirrorPt2, bool eraseSourceObject)
        {
            Line3d miLine = new Line3d(mirrorPt1, mirrorPt2);
            Matrix3d mt = Matrix3d.Mirroring(miLine);
            ObjectId mirrorId = id;
            Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
            if (eraseSourceObject == true)
                ent.TransformBy(mt);
            else
            {
                Entity entCopy = ent.GetTransformedCopy(mt);
                mirrorId = id.Database.AddToCurrentSpace(entCopy);
            }
            return mirrorId;
        }

 

下面代码增加了深度克隆deepclone,然后再进行矩阵转换就不会发生丢失了!

        public static ObjectId Mirror(this ObjectId id, Point3d mirrorPt1, Point3d mirrorPt2, bool eraseSourceObject)
        {
            Line3d miLine = new Line3d(mirrorPt1, mirrorPt2);
            Matrix3d mt = Matrix3d.Mirroring(miLine);
            ObjectId mirrorId = id;
            Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
            Database db = id.Database;
            if (!eraseSourceObject)
            {
                var ids = new ObjectIdCollection();
                ids.Add(id);
                var mapping = new IdMapping();
                db.DeepCloneObjects(ids, db.CurrentSpaceId, mapping, false);
                mirrorId = mapping[id].Value;
            }
            ent.TransformBy(mt);
            return mirrorId;
        }
posted @ 2021-03-06 16:14  swtool  阅读(216)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!