using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
namespace selectTable
{
public class Class1
{
[CommandMethod("selTb")]
public void selectTable()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = ed.Document.Database;
PromptSelectionResult psr = ed.GetSelection();
SelectionSet sst = psr.Value;
ObjectId[] oi = sst.GetObjectIds();
PromptPointResult ppr = ed.GetPoint("Выбрать место вст. тб.");
Table tbB = new Table();
tbB.SetSize(10, 3);
tbB.Position = ppr.Value;
string[][] array = new string[oi.Length][];
for (int i = 0; i < array.Length; i++)
{
array[i] = new string[2];
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
for (int i = 0; i < oi.Length; i++)
{
Table tbA = (Table)tr.GetObject(oi[i], OpenMode.ForRead);
for (int j = 0; j < array[i].Length; j++)
{
array[i][j] = tbA.Cells[i, j].TextString;
}
}
tbB.Cells[0, 0].TextString = array[0][0];
tbB.Cells[0, 1].TextString = array[0][1];
tbB.Cells[1, 0].TextString = array[1][0];
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(tbB);
tr.AddNewlyCreatedDBObject(tbB, true);
tr.Commit();
}
}
}
}