Author Topic: Modify tablestyle - get grid color  (Read 1523 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Modify tablestyle - get grid color
« on: June 02, 2021, 10:08:28 AM »
Hi,

I'm struggling getting the actual color grid of a tablestyle.

Here is how I do it :

Code - C++: [Select]
  1. DBDictionary tabS = (DBDictionary)tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForWrite);
  2.  
  3. foreach (DBDictionaryEntry dbEntry in tabS)
  4. {
  5.          TableStyle tabStyle = (TableStyle)tr.GetObject(dbEntry.Value, OpenMode.ForWrite);
  6.  
  7.          string cCol_inner_title = tabStyle.GridColor(GridLineType.InnerGridLines, RowType.TitleRow).ColorIndex.ToString();
  8.          string cCol_inner_header = tabStyle.GridColor(GridLineType.InnerGridLines, RowType.HeaderRow).ColorIndex.ToString();
  9.          string cCol_inner_row = tabStyle.GridColor(GridLineType.InnerGridLines, RowType.DataRow).ColorIndex.ToString();
  10.  
  11.          // and so on for AllGridLines, OuterGridLines, HorizontalBottom, HorizontalGridLines...
  12. }
  13.  

It always return color 0, however I have put red everywhere.

Thank you !

n.yuan

  • Bull Frog
  • Posts: 348
Re: Modify tablestyle - get grid color
« Reply #1 on: June 03, 2021, 12:21:49 PM »
...
It always return color 0, however I have put red everywhere.

Thank you !

When you say "...have put red everywhere...", do you mean you make the grid line red of an ACTUAL TABLE, or a Table Style, which you as user do not see it directly, but only see its preview in Table Style editing dialog box? Not sure which case you are in.

If it is former, then you should check table itself by its GridColor() method, not its TableStyle's GridColor() method. A table inherits many of its properties from TableStyle, but can overwrite the properties on its own.

latour_g

  • Newt
  • Posts: 184
Re: Modify tablestyle - get grid color
« Reply #2 on: June 03, 2021, 01:23:27 PM »
Hi,

It's the tablestyle that has the red grid line. 


n.yuan

  • Bull Frog
  • Posts: 348
Re: Modify tablestyle - get grid color
« Reply #3 on: June 04, 2021, 10:27:48 AM »
Well, setting table/tableStyle gridline color is quite complicated. The first argument GridLineType of the GridColor() method by no means makes things any easier, rather it makes thing much more difficult, because the gridline types may overlap each other. In this regard, I'd prefer the same corresponding method in COM API (GetGridColor()), where are only 7 GridLineTypes there, as opposed to 12 in .NET/ObjectARX (with overlapped types).

To test actual gridline color, it would depend on whether the grid line is visible or not, which is done with SetGridVisibility() method. This only makes things even more difficult, depending on the region of cells (or whole row/rows, column/columns!!!): whether it is on top, bottom, adjacent to other cell region... So, the table style editing dialog box use a series of button to let user to select the border(gridline) is visible or not. When you set a grid color, you need to first click the last button to make sure no border is visible, and then select color, then click the button(s) to make border shown as desired.

The attached picture shows what I chose to show the title row's border in red.

and this code to test the title row gridline color:

Code: [Select]
        [CommandMethod("TSTes")]
        public static void TestTableStyleGridLineColor()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;

            using (var tran = dwg.TransactionManager.StartTransaction())
            {
                var tsDict = (DBDictionary)tran.GetObject(dwg.Database.TableStyleDictionaryId, OpenMode.ForRead);
                var tStyle = (TableStyle)tran.GetObject(tsDict.GetAt("STANDARD"), OpenMode.ForRead);

                var titleColor1 = tStyle.GridColor(GridLineType.InnerGridLines, RowType.TitleRow).ToString(); //ByBlock
                var titleColor2 = tStyle.GridColor(GridLineType.HorizontalGridLines, RowType.TitleRow).ToString(); //ByBlock
                var titleColor3 = tStyle.GridColor(GridLineType.OuterGridLines, RowType.TitleRow);  //ByBlock
                var titleColor4 = tStyle.GridColor(GridLineType.HorizontalTop, RowType.TitleRow);  // This color is RED
                var titleColor5 = tStyle.GridColor(GridLineType.HorizontalGridLines, RowType.TitleRow);  //ByBlock
                var titleColor6 = tStyle.GridColor(GridLineType.HorizontalInside, RowType.TitleRow);  //This color is RED


                tran.Commit();
            }

        }

Hope this helps.



latour_g

  • Newt
  • Posts: 184
Re: Modify tablestyle - get grid color
« Reply #4 on: June 04, 2021, 02:31:59 PM »
Well it work with your code !

I don't understanding why the same thing in .NET/ObjectARX is not working but I will use COM API then !

Thank you ! :-)