.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

table trouble

0 REPLIES 0
Reply
Message 1 of 1
Anonymous
262 Views, 0 Replies

table trouble

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"

InsertColumns(
System.Int32 col,
System.Double width,
System.Int32 columns)
Parameters
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))
{
try
{
//if it exists, just get it
listStyle = (TableStyle)trans.GetObject(tblStyle.GetAt("DWG-LIST"), OpenMode.ForRead);
}
catch
{
//Doesn't exist, so create it
tblStyle.UpgradeOpen();
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);
}
}
trans.Commit();
}
}
return styDef;
}

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

using (Database dBase = HostApplicationServices.WorkingDatabase)
{
using (Transaction trans = dBase.TransactionManager.StartTransaction())
{
if (dwgList.Count > 0)
{
try
{
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;
myTable.SetRowHeight(rowHeight);
//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
blkTblRec.AppendEntity(myTable);
//Let the transaction know about it
trans.AddNewlyCreatedDBObject(myTable, true);
myTable.Dispose();
blkTbl.Dispose();
blkTblRec.Dispose();
}
catch (System.Exception ex)
{
Utilities.Message(ex);
}
}
trans.Commit();
}
}
}
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost