当前位置: 首页>>代码示例>>C#>>正文


C# Database.WblockCloneObjects方法代码示例

本文整理汇总了C#中Database.WblockCloneObjects方法的典型用法代码示例。如果您正苦于以下问题:C# Database.WblockCloneObjects方法的具体用法?C# Database.WblockCloneObjects怎么用?C# Database.WblockCloneObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database.WblockCloneObjects方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: copyFlat

 private static void copyFlat(string fileFlat, ObjectId idBt)
 {
     using (var dbFlat = new Database(false, true))
     {
         dbFlat.ReadDwgFile(fileFlat, FileOpenMode.OpenForReadAndAllShare, false, "");
         dbFlat.CloseInput(true);
         using (var bt = dbFlat.BlockTableId.Open( OpenMode.ForRead) as BlockTable)
         {
             foreach (var idBtr in bt)
             {
                 using (var btr = idBtr.Open( OpenMode.ForRead) as BlockTableRecord)
                 {
                     if (Revit.Apartment.IsBlockNameApartment(btr.Name))
                     {
                         using (var map = new IdMapping())
                         {
                             ObjectIdCollection ids = new ObjectIdCollection(new[] { idBtr });
                             dbFlat.WblockCloneObjects(ids, idBt, map, DuplicateRecordCloning.Ignore, false);
                         }
                         return;
                     }
                 }
             }
         }
     }
 }
开发者ID:vildar82,项目名称:AR_ApartmentsBase,代码行数:26,代码来源:ApartmentPlacement.cs

示例2: CopyDict

 public static void CopyDict(Database dbDest)
 {
     // Копирование словаря АКР в базу
     var idDict = getDict();
     if (idDict.IsNull)
     {
         throw new Exception("Словарь АКР в текущем чертеже не найден.");
     }
     var ids = new ObjectIdCollection();
     ids.Add(idDict);
     var map = new IdMapping();
     dbDest.WblockCloneObjects(ids, dbDest.NamedObjectsDictionaryId, map, DuplicateRecordCloning.Replace, false);
 }
开发者ID:vildar82,项目名称:PanelColorAlbum,代码行数:13,代码来源:DictNOD.cs

示例3: ChangeBlockFrame

 public void ChangeBlockFrame(Database db, bool insertDescription)
 {
     // Замена блока рамки если он есть в чертеже фасада
      if (IsOk)
      {
     using (IdMapping iMap = new IdMapping())
     {
        var ids = new ObjectIdCollection();
        ids.Add(_idBtrFrame);
        db.WblockCloneObjects(ids, db.BlockTableId, iMap, DuplicateRecordCloning.Replace, false);
     }
     // Запись атрибутов (Наименование, и другие если есть)
     changeBlkRefFrame(db, Settings.Default.BlockFrameName, insertDescription);
      }
 }
开发者ID:vildar82,项目名称:PanelColorAlbum,代码行数:15,代码来源:FrameSheet.cs

示例4: ChangeCoverAndTitle

        public void ChangeCoverAndTitle(Database db)
        {
            // Замена блоков обложки и титульного лисчта
             if (!IsOkCover && !IsOkTitle)
             {
            return;
             }

             var ids = new ObjectIdCollection();
             if (IsOkCover)
             {
            ids.Add(IdCoverBtr);
             }
             if (IsOkTitle)
             {
            ids.Add(IdTitleBtr);
             }
             using (IdMapping iMap = new IdMapping())
             {
            db.WblockCloneObjects(ids, db.BlockTableId, iMap, DuplicateRecordCloning.Replace, false);
             }
        }
开发者ID:vildar82,项目名称:PanelColorAlbum,代码行数:22,代码来源:CoverAndTitle.cs

示例5: ImportBlocks

        public void ImportBlocks()
        {
            
            AcadApp.DocumentCollection dm = AcadApp.Application.DocumentManager;
            Editor ed = dm.MdiActiveDocument.Editor;
            Database destDb = dm.MdiActiveDocument.Database;
            Database sourceDb = new Database(false, true);
            PromptResult sourceFileName;
            try
            {
                //从命令行要求用户输入以得到要导入的块所在的源DWG文件的名字
                sourceFileName = ed.GetString("\nEnter the name of the source drawing: ");
                //把源DWG读入辅助数据库
                sourceDb.ReadDwgFile(sourceFileName.StringResult, System.IO.FileShare.Write, true, "");
                //用集合变量来存储块ID的列表
                ObjectIdCollection blockIds = new ObjectIdCollection();
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
                sourceDb.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    //打开块表
                    BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId,
                    OpenMode.ForRead, false);
                    //在块表中检查每个块
                    foreach (ObjectId btrId in bt)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId,
                        OpenMode.ForRead, false);
                        //只添加有名块和非layout块(layout块是非MS和非PS的块) 
                        if (!btr.IsAnonymous && !btr.IsLayout)
                            blockIds.Add(btrId);
                        btr.Dispose();	//释放块表记录引用变量所占用的资源
                    }
                    bt.Dispose();//释放块表引用变量所占用的资源
                    //没有作改变,不需要提交事务
                    myT.Dispose();
                }
                
                IdMapping mapping = new IdMapping();
                mapping = sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, DuplicateRecordCloning.Replace, false);

                ed.WriteMessage("\nCopied " + blockIds.Count.ToString() + " block definitions from " + sourceFileName.StringResult + " to the current drawing.");
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\nError during copy: " + ex.Message);
            }
            sourceDb.Dispose();
        }
开发者ID:freudshow,项目名称:raffles-codes,代码行数:49,代码来源:Class1.cs

示例6: copyObjectFromTemplate

 // Копирование стиля таблиц ПИК из файла шаблона
 private static ObjectId copyObjectFromTemplate(Database db, Func<Database, string, ObjectId> getObjectId, string styleName, ObjectId ownerIdTable)
 {
     ObjectId idStyleDest = ObjectId.Null;
     // файл шаблона
     var userGroup = PikSettings.UserGroupsCombined.First();
     string fileTemplate = Path.Combine(PikSettings.LocalSettingsFolder, "Template", userGroup,
         userGroup + ".dwt");
     if (File.Exists(fileTemplate))
     {
         using (Database dbTemplate = new Database(false, true))
         {
             dbTemplate.ReadDwgFile(fileTemplate, FileOpenMode.OpenForReadAndAllShare, false, "");
             dbTemplate.CloseInput(true);
             ObjectId idStyleInTemplate = getObjectId(dbTemplate, styleName);
             if (!idStyleInTemplate.IsNull)
             {
                 using (IdMapping map = new IdMapping())
                 {
                     using (var ids = (new ObjectIdCollection(new ObjectId[] { idStyleInTemplate })))
                     {
                         db.WblockCloneObjects(ids, ownerIdTable, map, DuplicateRecordCloning.Replace, false);
                         idStyleDest = map[idStyleInTemplate].Value;
                     }
                 }
             }
         }
     }
     return idStyleDest;
 }
开发者ID:vildar82,项目名称:AcadLib,代码行数:30,代码来源:DbExtensions.cs

示例7: renameAndRedefBlocksInDb

        private static int renameAndRedefBlocksInDb(List<RedefineBlock> blocksRedefine, 
            List<RedefineBlock> renameBlocks, FileInfo file, int countFilesRedefined, List<Error> errors, Database dbExt)
        {
            // Переименование блоков в этом файле
            var renameErrors = RenameBlocks(dbExt, renameBlocks);
            errors.AddRange(renameErrors);

            if (blocksRedefine != null && blocksRedefine.Count > 0)
            {
                List<RedefineBlock> redefBlockInThisDb = new List<RedefineBlock>();
                using (var bt = dbExt.BlockTableId.Open(OpenMode.ForRead) as BlockTable)
                {
                    foreach (var item in blocksRedefine)
                    {
                        if (bt.Has(item.Name))
                        {
                            redefBlockInThisDb.Add(item);
                        }
                        else
                        {
                            errors.Add(new Error($"Нет блока '{item.Name}' в чертеже {file.Name}",
                                System.Drawing.SystemIcons.Warning));
                            //Inspector.AddError($"Нет блока '{item.Name}' в чертеже {file.Name}",
                            //    System.Drawing.SystemIcons.Warning);
                        }
                    }
                }

                using (var map = new IdMapping())
                {
                    var ids = new ObjectIdCollection(redefBlockInThisDb.Select(b => b.IdBtr).ToArray());
                    // Копирование блока с переопредедлением.
                    dbExt.WblockCloneObjects(ids, dbExt.BlockTableId, map, DuplicateRecordCloning.Replace, false);
                    //ed.WriteMessage("\n" + file.FullName + " - ок.");
                    countFilesRedefined++;
                    // Обновление анонимных блоков для дин блоков
                    using (var t = dbExt.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId id in ids)
                        {
                            var btr = map[id].Value.GetObject(OpenMode.ForRead) as BlockTableRecord;
                            if (btr == null || !btr.IsDynamicBlock) continue;
                            btr.UpdateAnonymousBlocks();
                        }

                        // Изменение точки вставки блока
                        foreach (var redefBl in redefBlockInThisDb)
                        {
                            if (redefBl.IsChangeBasePoint)
                            {
                                redefBl.ChangeBasePointInRedefineBase(dbExt, map[redefBl.IdBtr].Value);
                            }
                        }

                        t.Commit();
                    }

                    foreach (var item in redefBlockInThisDb)
                    {
                        errors.Add(new Error($"Переопределен блок '{item.Name}' в чертеже {file.Name}",
                            System.Drawing.SystemIcons.Information));
                        //Inspector.AddError($"Переопределен блок '{item.Name}' в чертеже {file.Name}",
                        //    System.Drawing.SystemIcons.Information);
                    }
                }
            }

            return countFilesRedefined;
        }
开发者ID:vildar82,项目名称:RedefineBlockInFolder,代码行数:69,代码来源:Commands.cs

示例8: CopyBlockFromExternalDrawing

        /// <summary>
        /// Копирование определенич блока из внешнего чертежа
        /// </summary>
        /// <param name="blNames">Имена блоков</param>
        /// <param name="fileDrawing">Полный путь к чертежу из которого копируется блок</param>
        /// <param name="destDb">База чертежа в который копируетсяя блок</param>
        /// <exception cref="Exception">Если нет блока в файле fileDrawing.</exception>
        /// <returns>Список пар значений имени блока и idBtr</returns>        
        public static Dictionary<string, ObjectId> CopyBlockFromExternalDrawing(IList<string> blNames, string fileDrawing, Database destDb,
                                                DuplicateRecordCloning mode = DuplicateRecordCloning.Ignore)
        {
            var resVal = new Dictionary<string, ObjectId>();
            var uniqBlNames = blNames.Distinct(StringComparer.OrdinalIgnoreCase);

            using (var extDb = new Database(false, true))
            {
                extDb.ReadDwgFile(fileDrawing, System.IO.FileShare.ReadWrite, true, "");
                extDb.CloseInput(true);

                var valToCopy = new Dictionary<ObjectId, string>();

                using (var bt = (BlockTable)extDb.BlockTableId.Open(OpenMode.ForRead))
                {
                    foreach (var blName in uniqBlNames)
                    {
                        ObjectId id;
                        if (bt.Has(blName))
                        {
                            id = bt[blName];
                            valToCopy.Add(id, blName);
                        }
                    }
                }
                // Копир
                if (valToCopy.Count > 0)
                {
                    // Получаем текущую базу чертежа
                    using (IdMapping map = new IdMapping())
                    {
                        using (var ids = new ObjectIdCollection(valToCopy.Keys.ToArray()))
                        {
                            destDb.WblockCloneObjects(ids, destDb.BlockTableId, map, mode, false);
                            foreach (var item in valToCopy)
                            {
                                resVal.Add(item.Value, map[item.Key].Value);
                            }
                        }
                    }
                }
            }

            // Если задан режим переопределения - то перерисовка геометрии динамических блоков
            if (mode == DuplicateRecordCloning.Replace)
            {
                using (var t = destDb.TransactionManager.StartTransaction())
                {
                    var bt = destDb.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                    foreach (var item in resVal)
                    {
                        if (item.Value.IsValidEx())
                        {
                            var btr = item.Value.GetObject(OpenMode.ForRead) as BlockTableRecord;
                            if (btr.IsDynamicBlock)
                            {
                                try
                                {
                                    btr.UpgradeOpen();
                                    btr.UpdateAnonymousBlocks();
                                }
                                catch { }
                            }
                        }
                    }
                    t.Commit();
                }
            }

            return resVal;
        }
开发者ID:vildar82,项目名称:AcadLib,代码行数:79,代码来源:Block.cs

示例9: ImportBlocks

            //[CommandMethod("IB")]
            public static void ImportBlocks()
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;
                Database destDb = doc.Database;
                Database sourceDb = new Database(false, true);

                String sourceFileName;

                try
                {
                    //Get name of DWG from which to copy blocks
                    sourceFileName = "C:\\Program Files\\AutoCAD MEP 2010\\DynaPrograms\\TagHgr.dwg";

                    //Read the DWG file into the database
                    sourceDb.ReadDwgFile(sourceFileName.ToString(), System.IO.FileShare.Read, true, "");

                    //Create a variable to store the list of block Identifiers
                    ObjectIdCollection blockIds = new ObjectIdCollection();

                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;

                    using (Transaction myTm = tm.StartTransaction())
                    {
                        //Open the block table
                        BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

                        //Check each block in the table
                        foreach (ObjectId btrId in bt)
                        {
                            BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);

                            //Only add named and non-layout blocks to the copy file if the don't already exist.
                            if (!btr.IsAnonymous && !btr.IsLayout)
                                blockIds.Add(btrId);
                            btr.Dispose();
                        }
                    }
                    //Copy blocks from source to dest database
                    IdMapping mapping = new IdMapping();
                    sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
                    //Writes the number of blocks copied to cmd line.
                    //ed.WriteMessage("\nCopied: " + blockIds.Count.ToString() + " block definitions from " + sourceFileName + " to the current drawing.");

                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message);
                }
                sourceDb.Dispose();
            }
开发者ID:kmorin,项目名称:pointloadcalc,代码行数:52,代码来源:Class2.cs

示例10: copyPanelToExportFile

        private void copyPanelToExportFile(Database dbExport)
        {
            Dictionary<ObjectId, PanelBlRefExport> dictPanelsToExport = new Dictionary<ObjectId, PanelBlRefExport>();

            foreach (var panelBtr in CPS.PanelsBtrExport)
                foreach (var panelBlref in panelBtr.Panels)
                    dictPanelsToExport.Add(panelBlref.IdBlRefAkr, panelBlref);

            ObjectIdCollection ids = new ObjectIdCollection(dictPanelsToExport.Keys.ToArray());

            using (IdMapping map = new IdMapping())
            {
                var msExport = SymbolUtilityServices.GetBlockModelSpaceId(dbExport);
                dbExport.WblockCloneObjects(ids, msExport, map, DuplicateRecordCloning.Replace, false);

                // скопированные блоки в экспортированном чертеже
                var idsBtrExport = new HashSet<ObjectId>();
                foreach (var itemDict in dictPanelsToExport)
                {
                    itemDict.Value.IdBlRefExport = map[itemDict.Key].Value;
                    using (var blRef = itemDict.Value.IdBlRefExport.Open(OpenMode.ForRead, false, true) as BlockReference)
                    {
                        idsBtrExport.Add(blRef.BlockTableRecord);
                        itemDict.Value.PanelBtrExport.IdBtrExport = blRef.BlockTableRecord;
                    }
                }
            }
        }
开发者ID:vildar82,项目名称:PanelColorAlbum,代码行数:28,代码来源:ExportFacadeService.cs

示例11: ImportNestedFilters

        public static void ImportNestedFilters(LayerFilter srcFilter, LayerFilter destFilter, Database srcDb, Database destDb)
        {
            using (Transaction t = srcDb.TransactionManager.StartTransaction())
             {
            LayerTable lt = t.GetObject(srcDb.LayerTableId, OpenMode.ForRead, false) as LayerTable;

            foreach (LayerFilter sf in srcFilter.NestedFilters)
            {
               // Получаем слои, которые следует клонировать в db
               // Только те, которые участвуют в фильтре
               ObjectIdCollection layerIds = new ObjectIdCollection();
               foreach (ObjectId layerId in lt)
               {
                  LayerTableRecord ltr = t.GetObject(layerId, OpenMode.ForRead, false) as LayerTableRecord;
                  if (sf.Filter(ltr))
                  {
                     layerIds.Add(layerId);
                  }
               }

               // Клонируем слои во внешнюю db
               IdMapping idmap = new IdMapping();
               if (layerIds.Count > 0)
               {
                  srcDb.WblockCloneObjects(layerIds, destDb.LayerTableId, idmap, DuplicateRecordCloning.Replace, false);
               }

               // Опеределяем не было ли фильтра слоев
               // с таким же именем во внешней db
               LayerFilter df = null;
               foreach (LayerFilter f in destFilter.NestedFilters)
               {
                  if (f.Name.Equals(sf.Name))
                  {
                     df = f;
                     break;
                  }
               }

               if (df == null)
               {
                  if (sf is LayerGroup)
                  {
                     // Создаем новую группу слоев если
                     // ничего не найдено
                     LayerGroup sfgroup = sf as LayerGroup;
                     LayerGroup dfgroup = new LayerGroup();
                     dfgroup.Name = sf.Name;

                     df = dfgroup;

                     LayerCollection lyrs = sfgroup.LayerIds;
                     foreach (ObjectId lid in lyrs)
                     {
                        if (idmap.Contains(lid))
                        {
                           IdPair idp = idmap[lid];
                           dfgroup.LayerIds.Add(idp.Value);
                        }
                     }
                     destFilter.NestedFilters.Add(df);
                  }
                  else
                  {
                     // Создаем фильтр слоев если
                     // ничего не найдено
                     df = new LayerFilter();
                     df.Name = sf.Name;
                     df.FilterExpression = sf.FilterExpression;
                     destFilter.NestedFilters.Add(df);
                  }
               }

               // Импортируем другие фильтры
               ImportNestedFilters(sf, df, srcDb, destDb);
            }
            t.Commit();
             }
        }
开发者ID:vildar82,项目名称:TemplateLayerFilter,代码行数:79,代码来源:TemplateLayerFilter.cs

示例12: ImportBlocks

        public static void ImportBlocks()
        {
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                DocumentCollection dm = Application.DocumentManager;
                Editor ed = dm.MdiActiveDocument.Editor;
                Database destDb = dm.MdiActiveDocument.Database;
                Database sourceDb = new Database(false, true);
                try
                {
                    // Read the DWG into a side database
            #if DEBUG
                sourceDb.ReadDwgFile("../../88.dwg", System.IO.FileShare.Read, true,"");
            #else
                    sourceDb.ReadDwgFile("./Resource/88.dwg", System.IO.FileShare.Read, true, "");
            #endif
                    // Create a variable to store the list of block identifiers
                    ObjectIdCollection blockIds = new ObjectIdCollection();
                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;
                    using (Transaction myT = tm.StartTransaction())
                    {
                        // Open the block table
                        BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

                        // Check each block in the block table
                        foreach (ObjectId btrId in bt)
                        {
                            BlockTableRecord btr =
                              (BlockTableRecord)tm.GetObject(btrId,
                                                            OpenMode.ForRead,
                                                            false);
                            // Only add named & non-layout blocks to the copy list
                            if (!btr.IsAnonymous && !btr.IsLayout)
                                blockIds.Add(btrId);
                            btr.Dispose();
                        }
                    }
                    // Copy blocks from source to destination database
                    IdMapping mapping = new IdMapping();
                    sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage("\nError during copy: " + ex.Message);
                }
                sourceDb.Dispose();
            }
        }
开发者ID:FengLuanShuangWu,项目名称:AutoCADPlugin-HeatSource,代码行数:48,代码来源:Utility.cs

示例13: SetLayerProperties

        private static void SetLayerProperties(LayerTableRecord stdLayer, LayerTableRecord ltr, Database db, Transaction tr)
        {
            ltr.Color = stdLayer.Color;
             ltr.LineWeight = stdLayer.LineWeight;
             ObjectIdCollection acObjIdColl = new ObjectIdCollection();
             acObjIdColl.Add(stdLayer.LinetypeObjectId);
             IdMapping acIdMap = new IdMapping();

             LinetypeTable acLinTbl; acLinTbl = tr.GetObject(db.LinetypeTableId, OpenMode.ForWrite) as LinetypeTable;
             db.WblockCloneObjects(acObjIdColl, acLinTbl.Id, acIdMap,
                                    DuplicateRecordCloning.Ignore, false);
             LinetypeTableRecord currentLineType = GetLineType(tr, stdLayer.LinetypeObjectId, acLinTbl);

             ltr.LinetypeObjectId = currentLineType.Id;
             ltr.IsPlottable = stdLayer.IsPlottable;
             ltr.Description = stdLayer.Description;
        }
开发者ID:vildar82,项目名称:AutoCAD_Standartization,代码行数:17,代码来源:LayerManager.cs


注:本文中的Database.WblockCloneObjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。