Message 1 of 1 (98 Views)

table trouble

98 Views, 0 Replies
07-18-2006 12:33 PM
Well, I fixed the majority of problems I was having with tables mentioned
in an earlier post (which elicited no help).
Some problems remain though. For one thing, why do I end up with an extra
column? There are NO examples of table creation and the docs are not very
helpful. For example heres what the docs say on "insertcolumn"

System.Int32 col,
System.Double width,
System.Int32 columns)
col Input System.Int32 object.
width Input System.Double object.
columns Input System.Int32 object.

Im not sure what the first parameter is for, the remaining two seem obvious.
I've tried inserting my columns several different ways, but aways end
up with an extra.

Also, table styles dont seem to be fully functional. The "isHeader/TitleSuppressed"
had to be used during table creation rather than in the table style definition in order
to work. Also, specifying different widths on the various gridlines has no
effect at all, either programmatically or though the table style gui.
Most of the other stuff works.
Sure would be nice if there was some decent info on this, a white paper or something.

Does anyone see any problems in my code below??
private ObjectId makeTableStyle()
ObjectId styDef = ObjectId.Null;
Color color1 = Color.FromColorIndex(ColorMethod.ByAci, 1);
Color color2 = Color.FromColorIndex(ColorMethod.ByAci, 2);
Color color3 = Color.FromColorIndex(ColorMethod.ByAci, 3);

using (Database dBase = HostApplicationServices.WorkingDatabase)
using (Transaction trans = dBase.TransactionManager.StartTransaction())
TableStyle listStyle = new TableStyle();
//First, get the tablestyle dictionary
using (DBDictionary tblStyle = (DBDictionary)trans.GetObject(dBase.TableStyleDictionaryId, OpenMode.ForRead, false))
//if it exists, just get it
listStyle = (TableStyle)trans.GetObject(tblStyle.GetAt("DWG-LIST"), OpenMode.ForRead);
//Doesn't exist, so create it
styDef = tblStyle.SetAt("DWG-LIST", listStyle);
listStyle.Name = "drawing list";
listStyle.Description = "list style for cover sheet";
//next two lines dont work here
//listStyle.IsHeaderSuppressed = false;
//listStyle.IsTitleSuppressed = false;
//make a heavy "box" around the table
//Line weights dont work either
listStyle.SetGridLineWeight(LineWeight.LineWeight100, 1, 2);
listStyle.SetGridLineWeight(LineWeight.LineWeight100, 1, 1);
listStyle.SetGridLineWeight(LineWeight.LineWeight100, 8, 1);
listStyle.SetGridLineWeight(LineWeight.LineWeight100, 0x20, 1);
listStyle.SetTextHeight(0.2, 2);//title row
listStyle.SetTextHeight(0.15, 4);//header row
listStyle.SetTextHeight(0.1, 1);//data row
//listStyle.SetTextStyle(objectid, 1);
listStyle.SetAlignment(CellAlignment.MiddleCenter, 2);//title row
listStyle.SetAlignment(CellAlignment.MiddleCenter, 4);//header row
listStyle.SetAlignment(CellAlignment.MiddleCenter, 1);//data row
listStyle.SetColor(color1, 2);//title row
listStyle.SetColor(color2, 4);//header row
listStyle.SetColor(color3, 1);//data row
trans.AddNewlyCreatedDBObject(listStyle, true);
return styDef;

private void addTable()
#if (DEBUG)
Utilities.prompt("\nIn cover sheet add.");

using (Database dBase = HostApplicationServices.WorkingDatabase)
using (Transaction trans = dBase.TransactionManager.StartTransaction())
if (dwgList.Count > 0)
char[] delimiterChars = { '=', ',' };
Point3d position = new Point3d(2.0, 2.0, 0.0);
int numRows = linesPerColumn;
double rowHeight = 0.2;
BlockTable blkTbl = (BlockTable)trans.GetObject(dBase.BlockTableId, OpenMode.ForRead);
BlockTableRecord blkTblRec = (BlockTableRecord)trans.GetObject(blkTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite);
ObjectId styDef = makeTableStyle();

Table myTable = new Table();
myTable.Position = position;
myTable.IsHeaderSuppressed = false;
myTable.IsTitleSuppressed = false;
//keep getting an extra column
myTable.InsertColumns(1, 0.5, 1);
myTable.InsertColumns(1, 0.5, 1);
myTable.InsertColumns(1, 2.0, 1);
myTable.InsertColumns(1, 0.5, 1);
//myTable.InsertRows(1, 0.5, numRows);
for (int i = 0; i < numRows + 2; i++)//Add 2 to account for headers
myTable.InsertRows(1, 0.5, 1);
//myTable.Height = numColumns * rowHeight;
myTable.SetTextString(0, 0, DocData.DocVars.sCoverSheetHeading);
myTable.SetTextString(1, 0, "Dwg No");
myTable.SetTextString(1, 1, "Sht No");
myTable.SetTextString(1, 2, "Title");
myTable.SetTextString(1, 3, "Rev");
//for (int i = 0; i < dwgList.Count; i++)
for (int i = 0; i <= numRows; i++)
string line = (string)dwgList;
string[] words = line.Split(delimiterChars);
string dwgnum = words[0];
string title = words[1];
string rev = "";
if (line.Contains(","))
rev = words[2];
string sht = "";
if (dwgnum.Length == DocData.DocVars.nDrawingIDLength + DocData.DocVars.nSheetIDLength)
sht = dwgnum.Substring(DocData.DocVars.nDrawingIDLength, DocData.DocVars.nSheetIDLength);
dwgnum = dwgnum.Remove(DocData.DocVars.nDrawingIDLength, DocData.DocVars.nSheetIDLength);
myTable.SetTextString(i + 2, 0, dwgnum);//Add 2 to account for headers
myTable.SetTextString(i + 2, 1, sht);
myTable.SetTextString(i + 2, 2, title);
myTable.SetTextString(i + 2, 3, rev);
myTable.TableStyle = styDef;
//Add the reference to PaperSpace
//Let the transaction know about it
trans.AddNewlyCreatedDBObject(myTable, true);
catch (System.Exception ex)

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community