예제 #1
0
        /// <summary>
        /// Экспорт блока в файл - файл в корне текущего чертежа с именем блока.
        /// Точка вставки блока - 0,0
        /// </summary>
        public void ExportToFile()
        {
            using (var db = new Autodesk.AutoCAD.DatabaseServices.Database(true, true))
            {
                db.CloseInput(true);

                var ids  = new ObjectIdCollection(new[] { IdBlRef });
                var idMS = SymbolUtilityServices.GetBlockModelSpaceId(db);

                using (IdMapping map = new IdMapping())
                {
                    db.WblockCloneObjects(ids, idMS, map, DuplicateRecordCloning.Replace, false);
                    // перенос блока в ноль
                    var idBlRefMap = map[IdBlRef].Value;
                    if (!idBlRefMap.IsNull)
                    {
                        using (var t = db.TransactionManager.StartTransaction())
                        {
                            var blRef = idBlRefMap.GetObject(OpenMode.ForWrite, false, true) as BlockReference;
                            blRef.Position = Point3d.Origin;

                            // Изменение вида
                            if (blRef.Bounds.HasValue)
                            {
                                try
                                {
                                    zoomDb(db, blRef.Bounds.Value);
                                    // Перенос штриховки на задний план
                                    var btrApart = blRef.BlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord;
                                    var orders   = btrApart.DrawOrderTableId.GetObject(OpenMode.ForWrite) as DrawOrderTable;
                                    var idsHatch = new ObjectIdCollection();
                                    foreach (var idEnt in btrApart)
                                    {
                                        if (idEnt.ObjectClass == RXClass.GetClass(typeof(Hatch)))
                                        {
                                            idsHatch.Add(idEnt);
                                        }
                                    }
                                    if (idsHatch.Count > 0)
                                    {
                                        orders.MoveToBottom(idsHatch);
                                    }
                                    // Превью чертежа из блока квартиры
                                    db.ThumbnailBitmap = new Bitmap(btrApart.PreviewIcon, new Size(320, 270));
                                }
                                catch { }
                            }
                            t.Commit();
                        }
                        db.SaveAs(File, DwgVersion.Current);
                    }
                }
                //Inspector.AddError($"Экспортирован блок {Name} в файл {File}", IdBlRef, icon: System.Drawing.SystemIcons.Information);
            }
        }
예제 #2
0
        internal static bool CloneFromRepository <T>(Db.Database db,
                                                     string strName,
                                                     string RepositorySourcePath)
        {
            bool returnValue = false;

            using (Db.Database dbSource = new Db.Database(false, true))
            {
                try
                {
                    dbSource.ReadDwgFile(RepositorySourcePath,
                                         System.IO.FileShare.Read,
                                         true,
                                         null);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    App.Application.DocumentManager.MdiActiveDocument.Editor.
                    WriteMessage("\nError reading file repository: " +
                                 ex.Message);
                    return(returnValue);
                }

                Db.ObjectIdCollection sourceIds = new Db.ObjectIdCollection();

                using (Db.Transaction tr1 = dbSource.TransactionManager.
                                            StartTransaction())
                {
                    Db.ObjectId destDbMsId = Db.ObjectId.Null;
                    if (typeof(T) == typeof(Db.MLeaderStyle))
                    {
                        destDbMsId = db.MLeaderStyleDictionaryId;
                    }
                    else if (typeof(T) == typeof(Db.LayerTableRecord))
                    {
                        destDbMsId = db.LayerTableId;
                    }

                    Db.ObjectId destId = GetIDbyName <T>(dbSource, strName);

                    if (destId != Db.ObjectId.Null && destDbMsId != Db.ObjectId.Null)
                    {
                        sourceIds.Add(destId);
                        if (sourceIds.Count > 0)
                        {
                            Db.IdMapping mapping = new Db.IdMapping();
                            try
                            {
                                //Клонируем с заменой
                                dbSource.WblockCloneObjects(sourceIds,
                                                            destDbMsId,
                                                            mapping,
                                                            Db.DuplicateRecordCloning.Replace,
                                                            false);

                                returnValue = true;
                            }
                            catch (Rtm.Exception ex)
                            {
                                App.Application.DocumentManager.MdiActiveDocument.Editor.
                                WriteMessage(@"\nError during clone from the repository: "
                                             + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        App.Application.DocumentManager.MdiActiveDocument.Editor.
                        WriteMessage("\nError during clone from repository. " +
                                     "At the repository there is no Object with the specified name!");
                    }

                    tr1.Commit();
                }
            }

            return(returnValue);
        } //CloneFromRepository