Db.Table _tbl = null;
public void acTablMod(object senderObj, EventArgs evtArgs)
{
App.Document acDoc = App.Application.DocumentManager.MdiActiveDocument;
Db.Database acCurDb = acDoc.Database;
Ed.Editor acEd = acDoc.Editor;
Double www = _tbl.Columns[0].Width;
acEd.WriteMessage(_tbl.Columns[0].Width.ToString());
// А вот тут код падает и при попытке UpgradeOpen(), дальнейший код не выполняется
if (_tbl.IsWriteEnabled == false)
{
_tbl.UpgradeOpen();
}
_tbl.Cells[2, 0].TextString = "1111";
_tbl.DowngradeOpen();
}
[Rtm.CommandMethod("AddTableEvent")]
public void AddTableEvent()
{
App.Document acDoc = App.Application.DocumentManager.MdiActiveDocument;
Db.Database acCurDb = acDoc.Database;
using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
{
Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;
Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
Db.OpenMode.ForWrite) as Db.BlockTableRecord;
Gem.Point3d acPoint = new Gem.Point3d(0.0, 0.0, 0.0);
_tbl = new Db.Table();
Db.ObjectId tbID = CreateAndSetTableStyle(ref acPoint, "test tabl");
_tbl = (Db.Table)acTrans.GetObject(tbID, Db.OpenMode.ForWrite);
_tbl.InsertRows(2, 800, 1);
_tbl.Cells[2, 0].TextString = "gttth";
_tbl.Modified += new EventHandler(acTablMod);
acTrans.Commit();
}
}
[Rtm.CommandMethod("RemoveTableEvent")]
public void RemoveTableEvent()
{
if (_tbl != null)
{
App.Document acDoc = App.Application.DocumentManager.MdiActiveDocument;
Db.Database acCurDb = acDoc.Database;
using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
{
_tbl = acTrans.GetObject(_tbl.ObjectId, Db.OpenMode.ForRead) as Db.Table;
if (_tbl.IsWriteEnabled == false)
_tbl.UpgradeOpen();
_tbl.Modified -= new EventHandler(acTablMod);
_tbl = null;
acTrans.Commit();
}
}
}
private Db.ObjectId CreateAndSetTableStyle(ref Gem.Point3d acPnt, string name)
{
string sTableStyleName = "Vedomosti";
App.Document acDoc = App.Application.DocumentManager.MdiActiveDocument;
Db.Database acCurDb = acDoc.Database;
Ed.Editor acEd = acDoc.Editor;
Db.ObjectId TableStyleId;
Db.ObjectId tbID = new Db.ObjectId();
using (Db.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
Db.TableStyle ts;
Db.DBDictionary TableDict = (Db.DBDictionary)acTrans.GetObject(acCurDb.TableStyleDictionaryId, Db.OpenMode.ForRead);
if (TableDict.Contains(sTableStyleName))
{
TableStyleId = TableDict.GetAt(sTableStyleName);
}
else
{
ts = new Db.TableStyle();
ts.SetTextHeight(350, (int)Db.RowType.HeaderRow);
ts.SetTextHeight(350, (int)Db.RowType.DataRow);
ts.SetTextHeight(500, (int)Db.RowType.TitleRow);
ts.SetAlignment(Db.CellAlignment.MiddleCenter, (int)Db.RowType.HeaderRow);
ts.SetAlignment(Db.CellAlignment.MiddleCenter, (int)Db.RowType.TitleRow);
ts.SetAlignment(Db.CellAlignment.MiddleCenter, (int)Db.RowType.DataRow);
ts.IsHeaderSuppressed = false;
ts.IsTitleSuppressed = false;
TableStyleId = ts.PostTableStyleToDatabase(acCurDb, sTableStyleName);
acTrans.AddNewlyCreatedDBObject(ts, true);
}
ts = (Db.TableStyle)acTrans.GetObject(TableStyleId, Db.OpenMode.ForWrite);
Db.Table tb = new Db.Table();
if (TableStyleId == Db.ObjectId.Null)
{
tb.TableStyle = acCurDb.Tablestyle;
}
else
{
tb.TableStyle = TableStyleId;
}
tb.Rows[0].Height = 800;
tb.InsertRows(1, 1600, 1);
tb.InsertColumns(0, 1500, 1);
tb.InsertColumns(1, 7000, 1);
tb.Columns[2].Width = 1500;
tb.Cells[0, 0].TextHeight = 500;
tb.Cells[0, 0].TextString = name;
tb.Cells[0, 0].Alignment = Db.CellAlignment.MiddleCenter;
string[] str = new string[8];
str[0] = "Марка";
str[1] = "Размер";
str[2] = "Кол-во на этаж";
for (int i = 0; i <= 2; i++)
{
tb.Cells[1, i].TextString = str[i];
}
tb.Position = acPnt;
tb.GenerateLayout();
Db.BlockTable acBlkTbl;
Db.BlockTableRecord acBlkTblRec;
try
{
acBlkTbl = (Db.BlockTable)acTrans.GetObject(acCurDb.BlockTableId, Db.OpenMode.ForRead);
acBlkTblRec = (Db.BlockTableRecord)acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace], Db.OpenMode.ForWrite);
acBlkTblRec.AppendEntity(tb);
tbID = tb.ObjectId;
acTrans.AddNewlyCreatedDBObject(tb, true);
acTrans.Commit();
}
catch (Exception ex)
{
acDoc.Editor.WriteMessage("\nНе удалось добавить стиль таблицы в базу чертежа.");
acEd.WriteMessage("\n" + ex.Message);
}
}
return tbID;
}