[CommandMethod("test")]
public void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
var db = doc.Database;
var ed = doc.Editor;
var id = ObjectId.Null;
var markaField = String.Empty;
using (doc.LockDocument())
{
// AppServ.DocumentExtension.GetAcadDocument(AppServCore.Application.DocumentManager.MdiActiveDocument);
using (var tr = db.TransactionManager.StartTransaction())
{
// Запрос на выбор объектов
var acSelSetPrompt = ed.GetSelection() as PromptSelectionResult;
// Если статус ОК, значит выбрано
if (acSelSetPrompt.Status == PromptStatus.OK)
{
var acSSet = acSelSetPrompt.Value;
foreach (SelectedObject acSelSetObj in acSSet)
{
// Проверочка
if (acSelSetObj != null)
{
var blkRef = tr.GetObject(acSelSetObj.ObjectId, OpenMode.ForWrite) as BlockReference;
if (blkRef != null && blkRef.IsDynamicBlock == true)
{
var attrColl = blkRef.AttributeCollection;
foreach (ObjectId obId in attrColl)
{
var attrRef = tr.GetObject(obId, OpenMode.ForRead) as AttributeReference;
if (attrRef.Tag == "МАРКА")
{
markaField = obId.OldIdPtr.ToString();
// markaField = markaField.Trim(new char[] { '(', ')' });
}
}
}
}
}
}
var tableStylesDictionary =
tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForWrite) as DBDictionary;
var tableStyleId = ObjectId.Null;
// Принимаем табличный стиль
var tableStyle = new TableStyle() as TableStyle;
tableStyleId = tableStylesDictionary.SetAt("Standard", tableStyle);
tr.AddNewlyCreatedDBObject(tableStyle, true);
// Создаем таблицу
var table = new Table();
table.SetDatabaseDefaults();
table.TableStyle = tableStyleId;
table.SetSize(1, 1);
table.Rows[0].Height = 15;
table.Columns[0].Width = 15;
table.Cells[0, 0].TextHeight = 5;
var bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
var modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
modelSpace.AppendEntity(table);
string fieldCode = "%<\\AcObjProp Object(%<\\_ObjId " + markaField + ">%).TextString>%";
table.SetTextString(0, 0, fieldCode);
table.GenerateLayout();
// Точка вставки таблицы
var pr = ed.GetPoint("\nУкажите точку вставки таблицы: ") as PromptPointResult;
if (pr.Status == PromptStatus.OK)
{
table.Position = pr.Value;
}
tr.AddNewlyCreatedDBObject(table, true);
id = table.ObjectId;
tr.Commit();
ed.Regen();
}
}
//acdbEvaluateFields(ref id, 16);
}