With this one can add a cellstyle, delete a cellstyle, set the textstyle for a cellstyle.
It requires you to add some textstyles and a tablestyle
1) Apparantly it is impossible (whatever you do don't actually try it)
2) It probably is no use to the OP , as it is in no way what he wanted.
3) Who wants to use interop anyway.
[CommandMethod("tts")]
public static void TableStyleTest()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
string tableStyleName = "YourTableStyle";
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TableStyle tableStyle;
DBDictionary dic = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
foreach (DictionaryEntry eDict in dic)
{
tableStyle = tr.GetObject
((ObjectId)eDict.Value, OpenMode.ForRead) as TableStyle;
if (tableStyle.Name == tableStyleName)
{
tableStyle.UpgradeOpen();
ArrayList ca = tableStyle.CellStyles;
interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId);
interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;
TextStyleTable textstyletable=tr.GetObject
(db.TextStyleTableId,OpenMode.ForRead) as TextStyleTable;
object ob2 = Ap.ActiveDocument.ObjectIdToObject(textstyletable.ObjectId.OldId);
interop.Common.IAcadTextStyles tss = ob2 as interop.Common.IAcadTextStyles;
if(ca.Contains("U1")) ts.DeleteCellStyle("U1");
ts.CreateCellStyle("U1");
ts.SetCellClass("U1", 1);
if (ca.Contains("U2")) ts.DeleteCellStyle("U2");
ts.CreateCellStyle("U2");
ts.SetCellClass("U2", 2);
if (ca.Contains("U3")) ts.DeleteCellStyle("U3");
ts.CreateCellStyle("U3");
ts.SetCellClass("U3", 3);
ed.WriteMessage(tss.Item("User1").ObjectID.ToString());
if(textstyletable.Has("User1"))
ts.SetTextStyleId("U1", tss.Item("User1").ObjectID);
if (textstyletable.Has("User2"))
ts.SetTextStyleId("U2", tss.Item("User2").ObjectID);
if (textstyletable.Has("User3"))
ts.SetTextStyleId("U3", tss.Item("User3").ObjectID);
}
}
tr.Commit();
}
} // end TableStyleTest