51
Tables / How to change cell value in previously selected table (A2010)
« Last post by fixo on February 24, 2013, 09:40:48 PM »Code: [Select]
// Select table on screen, then perform command SelCell:
[CommandMethod("SelCell", CommandFlags.UsePickSet)]
public static void testSelectFromTable()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId id = ObjectId.Null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptSelectionResult res = ed.SelectImplied();
if (res.Status == PromptStatus.OK)
{
SelectionSet sset = res.Value;
id = sset.GetObjectIds()[0];
Table table = tr.GetObject(id, OpenMode.ForRead) as Table;
PromptPointOptions pto = new PromptPointOptions("\nPick inside a single cell: ");
PromptPointResult pres = ed.GetPoint(pto);
if (pres.Status != PromptStatus.OK)
{
ed.WriteMessage("\nInvalid point specification!");
return;
}
Point3d pt = pres.Value;
TableHitTestInfo hit = table.HitTest(pt, Vector3d.ZAxis);
int i = hit.Row;
int j = hit.Column;
Cell cell = table.Cells[i, j];
CellRange cr = CellRange.Create(table, i, j, i, j);
table.SubSelection = cr;
Vector3d vec = table.Normal;
Point3dCollection pts = cell.GetExtents();
double ht = table.Rows[cell.TopRow].Height;
double wid = table.Columns[cell.LeftColumn].Width;
table.SelectSubRegion(pts[0], pts[2], vec, vec, SelectType.Window, false, true, new FullSubentityPath[] { });
if (table.HasSubSelection)
{
cr = table.SubSelection;
if (cr.IsSingleCell)
{
cell = table.Cells[cr.TopRow, cr.LeftColumn];
string celltxt = cell.GetTextString(FormatOption.ForExpression);
ed.WriteMessage("\n{0}\n", celltxt);
table.UpgradeOpen();
cell.Contents[0].TextString = "Abracadabra";// add your value here
}
}
if (table.HasSubSelection)
{
ed.WriteMessage("\nSubSelection remove");
ed.GetString("\nPress any key: ");
table.ClearSubSelection();
}
}
tr.Commit();
}
}
Recent Posts