Пример #1
0
        public static ObjectId CroppingSurface5(TinSurface surface, Polyline border)
        {
            Document activeDoc   = Tools.GetActiveAcadDocument();
            Database sourceDb    = activeDoc.Database;
            var      points      = border.GetPoints();
            string   surfaceName = "Cropped_" + surface.Name + "<[Next Counter(CP)]>";

            using (Database destDb = new Database(true, false))
            {
                HostApplicationServices.WorkingDatabase = destDb;
                ObjectId newSurfaceId = TinSurface.CreateByCropping(destDb, surfaceName, surface.Id, points);
                HostApplicationServices.WorkingDatabase = sourceDb;

                using (Transaction transDest = Tools.StartTransaction(destDb))
                {
                    TinSurface newSurface = transDest.GetObject(newSurfaceId, OpenMode.ForRead) as TinSurface;

                    /*newSurface = newSurface.Clone() as TinSurface;
                     *
                     * newSurface.SetDatabaseDefaults(sourceDb);
                     * Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = activeDoc;
                     * Tools.AppendEntity(sourceDb, newSurface);*/

                    //newSurface = newSurface.Clone() as TinSurface;
                    transDest.Commit();
                    newSurface = newSurface.Clone() as TinSurface;
                    newSurface.SetDatabaseDefaults(sourceDb);
                    newSurface.SetToStandard(sourceDb);
                    newSurface.StyleId = surface.StyleId;

                    IntPtr ptr = newSurface.UnmanagedObject;
                    var    obj = TinSurface.Create(ptr, false);

                    using (Transaction srcTrans = Tools.StartTransaction(sourceDb))
                    {
                        newSurfaceId = TinSurface.Create(sourceDb, "test_surface");

                        newSurface.SetDatabaseDefaults(sourceDb);
                        newSurface.SetToStandard(sourceDb);
                        newSurface.SetDefaultLayer();
                        newSurface.StyleId = surface.StyleId;

                        //newSurface = srcTrans.GetObject(TinSurface.Create(sourceDb, "test_surface"), OpenMode.ForWrite) as TinSurface;
                        //newSurface.CopyFrom(obj);
                        newSurface.Rebuild();
                        srcTrans.Commit();
                    }
                    using (Transaction srcTrans = Tools.StartTransaction(sourceDb))
                    {
                        newSurface = srcTrans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface;

                        newSurface.UpgradeOpen();

                        newSurface.CopyFrom(obj);
                        //newSurface.Name = "test_surface2";

                        newSurface.SetDatabaseDefaults(sourceDb);
                        newSurface.SetToStandard(sourceDb);
                        newSurface.SetDefaultLayer();

                        newSurface.StyleId = surface.StyleId;
                        newSurface.Rebuild();

                        srcTrans.Commit();
                    }

                    using (Transaction srcTrans = Tools.StartTransaction(sourceDb))
                    {
                        newSurface = srcTrans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface;
                        newSurface.UpgradeOpen();

                        newSurface.SetDatabaseDefaults(sourceDb);
                        newSurface.SetToStandard(sourceDb);
                        newSurface.SetDefaultLayer();

                        srcTrans.Commit();
                        newSurface.Rebuild();
                        //newSurface.RebuildSnapshot();
                        newSurface.CreateSnapshot();
                    }

                    //Tools.AppendEntity(sourceDb, obj as TinSurface);
                }
            }

            return(ObjectId.Null);
        }