Author Topic: Cell styles in TableStyle...  (Read 13891 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Cell styles in TableStyle...
« on: July 22, 2010, 10:59:49 AM »
AutoCAD's table style has collection of cell styles (default it's are 'Title', 'Header' and 'Data').

How can I create/modify/delete custom cell style?

Class TableStyle has collection 'CellStyles', which content names of table cell styles. It's collection is ArrayList and contain method 'Add', and property 'IsReadOnly'. Property 'CellStyles' contain string objects; property 'IsReadOnly' = false, but if I add new string in 'CellStyles' - it's not happen.

Bryco

  • Water Moccasin
  • Posts: 1851
Re: Cell styles in TableStyle...
« Reply #1 on: July 22, 2010, 05:21:53 PM »
Perhaps you need to create the style then
Autodesk.AutoCAD.DatabaseServices.TableStyle.SetTextStyle(Autodesk.AutoCAD.DatabaseServices.ObjectId, string)

fixo

  • Guest
Re: Cell styles in TableStyle...
« Reply #2 on: July 22, 2010, 06:26:14 PM »
Hi Bryco
Please, share with us your code snippet
I really have not found in docs how to create cell style
It's very urgent task fo me too
Oleg

~'J'~

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Cell styles in TableStyle...
« Reply #3 on: July 23, 2010, 04:26:56 AM »
Perhaps you need to create the style then
Autodesk.AutoCAD.DatabaseServices.TableStyle.SetTextStyle(Autodesk.AutoCAD.DatabaseServices.ObjectId, string)
At what here TextStyle? I need other.
Code: [Select]
  1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  [color=green]//Acad[/color]
   6:  using acad = Autodesk.AutoCAD.ApplicationServices.Application;
   7:  using Autodesk.AutoCAD.ApplicationServices;
   8:  using Autodesk.AutoCAD.DatabaseServices;
   9:  using Autodesk.AutoCAD.EditorInput;
  10:  using Autodesk.AutoCAD.Runtime;
  11:  using Autodesk.AutoCAD.Interop;
  12:  
  13:  namespace AcadBlockEditor
  14:  {
  15:      public class Class1
  16:      {
  17:          Document dwg;
  18:          Editor ed;
  19:          Database db;
  20:  
  21:          [CommandMethod("q1", CommandFlags.Modal)]
  22:          public void TestMethod()
  23:          {
  24:              dwg = acad.DocumentManager.MdiActiveDocument;
  25:              ed = dwg.Editor;
  26:              db = dwg.Database;
  27:              try
  28:              {
  29:                  using (Transaction tr = dwg.TransactionManager.StartTransaction())
  30:                  {
  31:                      DBDictionary tsd = (DBDictionary) tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead);
  32:                      foreach (DBDictionaryEntry item in tsd)
  33:                      {
  34:                          [color=green]//ed.WriteMessage(string.Format("{0}{1}{0}", "\n", item.Key));[/color]
  35:                          TableStyle ts = (TableStyle) tr.GetObject(item.Value, OpenMode.ForRead);
  36:                          ed.WriteMessage(string.Format("{0}Table style name: '{1}'", "\n", ts.Name));
  37:                          ed.WriteMessage(string.Format("{0}(TableStyle.CellStyles.IsReadOnly ='{1}')", "\n", ts.CellStyles.IsReadOnly));
  38:                          [color=green]//Print all cell style names of table style[/color]
  39:                          PrintCellStylesInfo(ts);
  40:                          string stName = "MyStyle";[color=green]// name for my new cell style[/color]
  41:                          lock (dwg.LockDocument())
  42:                          {
  43:                              ed.WriteMessage(string.Format("\nBefore modify: Cell Styles Count: {0}", ts.CellStyles.Count));
  44:                              ts.UpgradeOpen();                            
  45:                              ts.CellStyles.Add(stName);
  46:                              ed.WriteMessage(string.Format("\nAfter modify: Cell Styles Count: {0}\n", ts.CellStyles.Count));
  47:                              ts.SetCellClass(CellClass.Label, stName);
  48:                              tr.Commit();
  49:                          }                        
  50:                          ed.WriteMessage(string.Format("{0}{1}{0}", "\nAfter modify:", new string('*', 30)));
  51:                          [color=green]//Print all cell style names of table style[/color]
  52:                          PrintCellStylesInfo(ts);
  53:                      }                  
  54:                  }
  55:              }
  56:              catch (System.Exception e)
  57:              {
  58:                  ed.WriteMessage(e.Message);
  59:              }            
  60:          }
  61:  
  62:          private void PrintCellStylesInfo(TableStyle ts)
  63:          {
  64:              foreach (var cs in ts.CellStyles)
  65:              {
  66:                  ed.WriteMessage(string.Format("{0}CellStyle Type: '{1}'; CellStyle.ToString: {2}", "\n", cs.GetType(), cs.ToString()));
  67:              }            
  68:          }
  69:      }
  70:  }

result:



Bryco

  • Water Moccasin
  • Posts: 1851
Re: Cell styles in TableStyle...
« Reply #4 on: July 24, 2010, 12:08:08 PM »
if you change "Standard" + "YourTextstyleName" to what you need
this changes the styles

Code: [Select]
[CommandMethod("tts")]
        public static void TableStyleTest()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            string tableStyleName = "Standard";
            string textStyleName = "YourTextstyleName";
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable tstyles = tr.GetObject
                    (db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                if (!tstyles.Has(textStyleName)) return;
                ObjectId newId = tstyles[textStyleName];
                if (newId == ObjectId.Null) return;
 

                DBDictionary dic = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead) as DBDictionary;
                foreach (DictionaryEntry eDict in dic)
                {
                    TableStyle tableStyle = tr.GetObject
                        ((ObjectId)eDict.Value, OpenMode.ForRead) as TableStyle;
                    if (tableStyle.Name == tableStyleName)
                    {
                        tableStyle.UpgradeOpen();
                        foreach (RowType rt in Enum.GetValues(typeof(RowType)))
                        {
                            if (rt == RowType.UnknownRow) continue;
                            //if (rt = RowType.DataRow) yadayada;
                            ed.WriteMessage("\n" + rt.ToString() + " textstyle is "
                                +(tr.GetObject(tableStyle.TextStyle(rt),OpenMode.ForRead)
                                as TextStyleTableRecord).Name);
                            ObjectId idv = tableStyle.TextStyle(rt);
                           tableStyle.SetTextStyle(newId, (int)rt);
                        }
                }

                }
                tr.Commit();
            }
           

        } // end TableStyleTest

fixo

  • Guest
Re: Cell styles in TableStyle...
« Reply #5 on: July 24, 2010, 12:47:08 PM »
Dear Bryco,
Thanks for the code but it's not I wanted be
IOW I want create a TableStyle (I know that already) and
then PROGRAMMATICALLY add in there my custom cellstyle -
say, similar to how you could be add the cell style in Excel
Unfortunatelly, I can't rich at CellStyle object at all
Hope this make a sense

~'J'~

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Cell styles in TableStyle...
« Reply #6 on: July 24, 2010, 12:57:29 PM »
2 Bryco
Look my second message in this post...

I repeat:

 My question is not about TexStyle. I need to add/modify/delete CellStyle of TableStyle's object in my program code.

Probably, we did not understand each other correct.



p.s. I write code, which can serializable/deserializable TableStyle objects to/from xml format.

For example look this xml...


« Last Edit: July 24, 2010, 03:29:38 PM by Hwd »

Bryco

  • Water Moccasin
  • Posts: 1851
Re: Cell styles in TableStyle...
« Reply #7 on: July 24, 2010, 05:25:59 PM »
I don't know much about tables but
using interop = Autodesk.AutoCAD.Interop;


interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId)
 interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;
   ts.CreateCellStyle("U12");

Jeff H

  • Needs a day job
  • Posts: 6075
Re: Cell styles in TableStyle...
« Reply #8 on: July 25, 2010, 12:43:32 AM »
Have you tried  table.Cells[0,1].CellStyleOverrides

fixo

  • Guest
Re: Cell styles in TableStyle...
« Reply #9 on: July 25, 2010, 04:13:08 AM »
Have you tried  table.Cells[0,1].CellStyleOverrides


Mate, the question is about TABLESTYLE not about TABLE... :pissed:

~'J'~

fixo

  • Guest
Re: Cell styles in TableStyle...
« Reply #10 on: July 25, 2010, 04:14:51 AM »
I don't know much about tables but
using interop = Autodesk.AutoCAD.Interop;


interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId)
 interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;
   ts.CreateCellStyle("U12");
Thanks Bryco,
But it is not a solution though...

~'J'~

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Cell styles in TableStyle...
« Reply #11 on: July 25, 2010, 06:05:31 AM »
I don't know much about tables but
using interop = Autodesk.AutoCAD.Interop;


interop.AcadApplication Ap = (interop.AcadApplication)acadApp.AcadApplication;
object ob = Ap.ActiveDocument.ObjectIdToObject( tableStyle.ObjectId.OldId)
 interop.Common.IAcadTableStyle ts = ob as interop.Common.IAcadTableStyle;
   ts.CreateCellStyle("U12");

Autodesk.AutoCAD.Interop.Common.IAcadTableStyle interface has not CreateCellStyle method. Please, check your assumption before the next answer.

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Cell styles in TableStyle...
« Reply #12 on: July 25, 2010, 06:24:20 AM »
Have you tried  table.Cells[0,1].CellStyleOverrides

My question about TableStyle.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Cell styles in TableStyle...
« Reply #13 on: July 25, 2010, 07:09:55 AM »

Andrey,

I read your question to be about CellStyles too.

Perhaps it would help if you confirmed your exact question.

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Andrey Bushman

  • Swamp Rat
  • Posts: 860
Re: Cell styles in TableStyle...
« Reply #14 on: July 25, 2010, 07:35:17 AM »

Andrey,

I read your question to be about CellStyles too.

Perhaps it would help if you confirmed your exact question.

How to add/modify/delete CellStyle objects of TableStyle entity in program code?

____________________________________________

p.s. Not confuse CellStyle with TextStyle, and TableStyle with Table, please.
Look my screen - Reply #6 on: July 24, 2010, 11:57:29 am

fro2001 write me about Table object, but my question is about TextStyle with CellStyles.
« Last Edit: July 25, 2010, 07:40:13 AM by Hwd »