Author Topic: Result is not correct for RowTypes  (Read 7764 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Result is not correct for RowTypes
« on: October 19, 2010, 07:43:07 AM »
Hi all.
AutoCAD 2009 x86 SP3, .Net Framework 3.5 SP1.

Result is not correct for RowTypes.
I have Table. First row is RowType.Title, secont = RowType.Header, third - RowType.Header. All other rows is RowType.Data.



I write next code, which was tested on my Table:
Code: [Select]
       [CommandMethod(ns, "xcmd", CommandFlags.Modal)]
        public void CreateXmlTemplate() {
            PromptEntityOptions peo = new PromptEntityOptions("Select table");
            PromptEntityResult result = ed.GetEntity(peo);
            if (result.Status == PromptStatus.OK) {
                using (Transaction t = db.TransactionManager.StartTransaction()) {
                    Table table = (Table)t.GetObject(result.ObjectId, OpenMode.ForRead);
                    for (int i = 0; i < table.NumRows; i++) {
                        ed.WriteMessage(string.Format("\nRow: {0} RowType: {1}", i, table.RowType(i).ToString()));
                    }
                }
            }
        }

I get result:

Quote
Command: netload
Command: xcmd
Select table:
Row: 0 RowType: TitleRow
Row: 1 RowType: HeaderRow
Row: 2 RowType: DataRow
Row: 3 RowType: DataRow
Row: 4 RowType: DataRow
Row: 5 RowType: DataRow
Row: 6 RowType: DataRow

Why third row not is HeaderRow???
« Last Edit: October 19, 2010, 08:13:22 AM by Andrey »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Result is not correct for RowTypes
« Reply #1 on: October 19, 2010, 09:54:17 AM »
Definition from the enum rowtype for a header

Quote
Indicates the row immediately following the title row.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #2 on: October 19, 2010, 10:38:06 AM »
Definition from the enum rowtype for a header

Quote
Indicates the row immediately following the title row.

Also what? We after all can assign manually to any lines of the table styles Title and Header through a properties window and it well works. Why in API incorrectly shows available properties?

In my tables the Header often consists of several lines (so it is necessary).

Please, look:
http://www.youtube.com/watch?v=GTWbhHco5bA
« Last Edit: October 19, 2010, 10:42:51 AM by Andrey »

n.yuan

  • Bull Frog
  • Posts: 348
Re: Result is not correct for RowTypes
« Reply #3 on: October 19, 2010, 10:55:58 AM »
I think the Acad document/properties window/.NET API on Table class is ambiguous, to say the least, or quite confusing.

Style is different from RowType. From the API, you do not see method/property that you can use to set "Row Style" as you do with Properties Window.

OTH, there are only 3 row type:

Title: can only be the first row;
Header, can be the first or second row;
Data: can be any row.

That is, the first row can be any type of row. But if you set it to Header type, then the second row can only be Data type. If you set it as Data type, all row below can only be data;

The second row can be header only when the first row is Title type.

Any rows from the third row can only be Data type.

However, when you use Properties Window (pay attention here, it is "Row Style", not "Row Type"), in the "Row Style" you set a row, say, the third row as in your example, as Header, instead of changing the row type (remember, the third row here can only be Data type), AutoCAD applies the style associated to the header (set in the current TableStyle) to the row.

You can try to set "Row style" in the Properties Window to Title or Header to the differnt rows and run your code see the result as I described in the beginning.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #4 on: October 19, 2010, 11:30:37 AM »
if I set style for cells (not for row/column) and  modify my code:
Code: [Select]
        [CommandMethod(ns, "xcmd", CommandFlags.Modal)]
        public void CreateXmlTemplate() {
            PromptEntityOptions peo = new PromptEntityOptions("Select table");
            PromptEntityResult result = ed.GetEntity(peo);
            if (result.Status == PromptStatus.OK) {
                using (Transaction t = db.TransactionManager.StartTransaction()) {
                    Table table = (Table)t.GetObject(result.ObjectId, OpenMode.ForRead);
                    for (int i = 0; i < table.NumRows; i++) {
                        ed.WriteMessage(string.Format("\nRow: {0} RowType: {1}", i, table.GetCellStyle(i, 0)));
                    }
                }
                //XElement xml = TableTemplateCreate(result.ObjectId);                   
            }
        }
then all works correctly. but I don't want to force users through a properties window to change value of style for cells. (((


Jeff H

  • Needs a day job
  • Posts: 6150
Re: Result is not correct for RowTypes
« Reply #5 on: October 19, 2010, 12:57:45 PM »
Okay maybe this will get you a little further
Code: [Select]
[CommandMethod( "tableRows")]
    public void CreateXmlTemplate()
    {
        Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;
        Editor ed = doc.Editor;       
        PromptEntityOptions peo = new PromptEntityOptions("Select table");
        PromptEntityResult result = ed.GetEntity(peo);
        if (result.Status == PromptStatus.OK)
        {
            using (Transaction t = db.TransactionManager.StartTransaction())
            {
                Table table = (Table)t.GetObject(result.ObjectId, OpenMode.ForWrite);
                for (int i = 0; i < table.Rows.Count; i++)
                {
                table.Rows[i].Style = "Header";[color=red]This will change Row Style to Header[/color]
                ed.WriteMessage("\nRow:  RowType:" + table.Rows[i].Style);[color=red]This will be empty if cell style is Row/Colum[/color]
                }
                t.Commit();
            }
        }
    }

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #6 on: October 19, 2010, 01:21:16 PM »
Okay maybe this will get you a little further
Code: [Select]
...
table.[color=red]Rows[i].Style[/color]
...

"Table" class not exists "Rows" property (ObjectARX 2009).

kaefer

  • Guest
Re: Result is not correct for RowTypes
« Reply #7 on: October 19, 2010, 02:28:13 PM »
"Table" class not exists "Rows" property (ObjectARX 2009).

Hi Andrey,

you do realise that between 17.2 and 18.0 a major API rewrite of the Table class took place? The description by n.yuan of its behaviour applies nonetheless.

Use Table.Cells[row, column].HorizontalLine.Margin instead.Double HorizontalCellMargin { get set; }
Use Cell functionality instead.Boolean IsHeaderSuppressed { get set; }
Use Cell functionality instead.Boolean IsTitleSuppressed { get set; }
Use Table.Columns.Count instead.Int32 NumColumns { get set; }
Use Table.Rows.Count instead.Int32 NumRows { get set; }
Use Table.Cells[row, column].VerticalLine.Margin instead.Double VerticalCellMargin { get set; }
......


I can't post the list of all obsolete members, there are 186 of them and that's over the posting limit.

Cheers, Thorsten
« Last Edit: October 19, 2010, 02:54:22 PM by kaefer »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #8 on: October 19, 2010, 02:54:12 PM »
Hi  kaefer,
It is difficult to me to translate from English. Probably I sometimes not truly transport that write to me.

Screen:



Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #9 on: October 19, 2010, 03:13:09 PM »
you do realise that between 17.2 and 18.0 a major API rewrite of the Table class took place?

Both these versions for ObjectARX 2009?

kaefer

  • Guest
Re: Result is not correct for RowTypes
« Reply #10 on: October 19, 2010, 03:36:39 PM »
you do realise that between 17.2 and 18.0 a major API rewrite of the Table class took place?

Both these versions for ObjectARX 2009?

No. 17.2.x.x is the value of the System.Reflection.AssemblyFileVersionAttribute of your acdbmgd.dll (that is Rel. 2009), while mine and almost everyone elses have at least 18.x.x.x (2010 or 2011).

And to be pedanticfunny, System.Reflection.AssemblyTitleAttribute says: "ObjectDBX .NET Manager Wrapper".

s/r/d/, Thorsten

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Result is not correct for RowTypes
« Reply #11 on: October 19, 2010, 07:40:44 PM »
< ... >

s/r/d/, Thorsten

OK, I have to ask ..
what is s/r/d
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kaefer

  • Guest
Re: Result is not correct for RowTypes
« Reply #12 on: October 19, 2010, 07:59:57 PM »
OK, I have to ask ..
what is s/r/d

I have to answer: "s/regexp/replacement/     Attempt  to match regexp against the pattern space. ..."
For more details, see sed(1); for example http://unixhelp.ed.ac.uk/CGI/man-cgi?sed

Hasn't manager to be funny, Thorsten

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Result is not correct for RowTypes
« Reply #13 on: October 20, 2010, 12:55:41 AM »
I have made so:
Code: [Select]
...
 db.ObjectAppended += new ObjectEventHandler(db_ObjectAppended);//db -> Database
...
        void db_ObjectAppended(object sender, ObjectEventArgs e)
        {
            if (e.DBObject is Table)
            {
                Table table = (Table)e.DBObject; table.UpgradeOpen();               
                for (int i = 0; i < table.NumRows; i++)
                {
                    for (int k = 0; k < table.NumColumns; k++)
                    {
                        string style = string.Empty;
                        switch (i)
                        {
                            case 0:
                                if (table.GetCellStyle(i,k) == "") style = "_Title";
                                break;
                            case 1:
                                if (table.GetCellStyle(i, k) == "") style = "_Header";
                                break;
                            default:
                                if (table.GetCellStyle(i, k) == "") style = "_Data";
                                break;
                        }
                        if (style != string.Empty) table.SetCellStyle(i, k, style);
                    }
                }
                ed.WriteMessage("\nNew Table object to Database was added");
            }           
        }
...
        [CommandMethod(ns, "xcmd", CommandFlags.Modal)]
        public void CreateXmlTemplate()
        {
            PromptEntityOptions peo = new PromptEntityOptions("Select table");
            PromptEntityResult result = ed.GetEntity(peo);
            if (result.Status == PromptStatus.OK)
            {
                using (Transaction t = db.TransactionManager.StartTransaction())
                {
                    Table table = (Table)t.GetObject(result.ObjectId, OpenMode.ForWrite);

                    for (int i = 0; i < table.NumRows; i++)
                    {
                        ed.WriteMessage(string.Format("\nRow: {0} RowType: {1}", i, table.GetCellStyle(i,0)));
                    }
                }
            }
        }
...

Result:



At copying of tables styles of cells are saved

All thanks.

kaefer

  • Guest
Re: Result is not correct for RowTypes
« Reply #14 on: October 20, 2010, 03:06:53 AM »
I have made so:


Hi Andrey,

did you try table.GetCellStyle(r,-1)?

That works as in your picture, albeit with blue squiggles, since it should be table.Cells.[r,-1].Style now.

All the best, Thorsten