Exemplo n.º 1
0
        public static ObjectIdCollection AppendObjectsToDatabase(DBObjectCollection objects, Database database, bool createUndo)
        {
            var objIds = new ObjectIdCollection();

            if (objects.Count == 0)
            {
                return(objIds);
            }

            if (createUndo)
            {
                database.StartUndoRecord();
            }

            using (var transaction = database.TransactionManager.StartTransaction())
            {
                var blockTable       = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
                var blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                foreach (var ent in objects.OfType <Entity>())
                {
                    objIds.Add(blockTableRecord.AppendEntity(ent));
                    transaction.AddNewlyCreatedDBObject(ent, true);
                }
                transaction.Commit();
            }
            return(objIds);
        }