namespace TryChangeTableBorders
{
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using AcApp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
public static class TestCommand
{
[CommandMethod("ChangeTableBorders")]
public static void Start()
{
var doc = AcApp.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var result = ed.GetEntity(new PromptEntityOptions("\nPick table"));
using (var tr = doc.TransactionManager.StartTransaction())
{
if (tr.GetObject(result.ObjectId, OpenMode.ForWrite) is Table table)
{
foreach (var range in table.Cells)
{
var cell = table.Cells[range.Row, range.Column];
ChangeCellRangeBorders(cell.IsMerged == true ? cell.GetMergeRange() : cell);
}
table.GenerateLayout();
table.RecomputeTableBlock(true);
}
tr.Commit();
}
}
private static void ChangeCellRangeBorders(CellRange cell)
{
LineWeight? lwtop = cell.Borders.Top.LineWeight;
LineWeight? lwbottom = cell.Borders.Bottom.LineWeight;
LineWeight? lwleft = cell.Borders.Left.LineWeight;
LineWeight? lwright = cell.Borders.Right.LineWeight;
if (lwtop == LineWeight.LineWeight040)
{
cell.Borders.Top.LineWeight = LineWeight.LineWeight200;
cell.Borders.Top.Color = Color.FromColorIndex(ColorMethod.ByColor, 1);
}
if (lwleft == LineWeight.LineWeight040)
{
cell.Borders.Left.LineWeight = LineWeight.LineWeight200;
cell.Borders.Left.Color = Color.FromColorIndex(ColorMethod.ByColor, 2);
}
if (lwright == LineWeight.LineWeight040)
{
cell.Borders.Right.LineWeight = LineWeight.LineWeight200;
cell.Borders.Right.Color = Color.FromColorIndex(ColorMethod.ByColor, 3);
}
if (lwbottom == LineWeight.LineWeight040)
{
cell.Borders.Bottom.LineWeight = LineWeight.LineWeight200;
cell.Borders.Bottom.Color = Color.FromColorIndex(ColorMethod.ByColor, 4);
}
}
}
}