I have tried:
Table.SetCellType(0, 0, TableCellType.BlockCell)
result:
Warning 1 'Public Overridable Sub SetCellType(row As Integer, col As Integer, type As Autodesk.AutoCAD.DatabaseServices.TableCellType)' is obsolete: 'Use Cell functionality instead.'
Then i tried:
Tbl.Cells(0, 0).CellType(TableCellType.BlockCell)
result:
Error 1 Property access must assign to the property or use its value.
Then I tried:
Table.Cells(0,0).CellType = TableCellType.BlockCell
result:
Error 1 Property 'CellType' is 'ReadOnly'.
Can anyone elighten me?
would you mind posting a small sample app so I can see what you need to acheive, then I'll fix it for you
Here's a quick example, not the same message but the same error with the set margins.
<CommandMethod("cadTable")> Public Sub cadTable()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim dwgScale As Integer = db.Dimscale
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim ppr As PromptPointResult = ed.GetPoint("Pick upper left insertion point: ")
If ppr.Status = PromptStatus.OK Then
Dim colHeadNames As New Specialized.StringCollection()
colHeadNames.Add("ABC")
colHeadNames.Add("DEF")
colHeadNames.Add("GHI")
colHeadNames.Add("JKL")
colHeadNames.Add("MNO")
Dim colCount As Integer = colHeadNames.Count - 1
Dim tb As New Autodesk.AutoCAD.DatabaseServices.Table()
tb.TableStyle = db.Tablestyle
tb.SetSize(2, colHeadNames.Count)
tb.Height = 0.125
tb.Columns(0).Width = 0.5 * dwgScale
tb.Columns(1).Width = 0.5 * dwgScale
tb.Columns(2).Width = 1.5625 * dwgScale
tb.Columns(3).Width = 2.0 * dwgScale
tb.Columns(4).Width = 1.4375 * dwgScale
tb.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 256)
tb.Position = ppr.Value
tb.Cells(0, 0).TextString = "EXAMPLE"
tb.Height = 0.125
tb.SetMargin(0, 0, CellMargins.Top, 0.0625 * dwgScale)
tb.SetMargin(0, 0, CellMargins.Bottom, 0.0625 * dwgScale)
tb.Cells(0, 0).TextHeight = 0.15625 * dwgScale
For i As Integer = 0 To colCount
tb.SetMargin(1, i, CellMargins.Top, 0.0625 * dwgScale)
tb.SetMargin(1, i, CellMargins.Bottom, 0.0625 * dwgScale)
tb.Cells(1, i).Alignment = CellAlignment.TopCenter
tb.Cells(1, i).TextString = colHeadNames(i)
tb.Cells(1, i).TextHeight = 0.09375 * dwgScale
Next
tb.BreakEnabled = True
tb.BreakFlowDirection = TableBreakFlowDirection.Right
tb.BreakOptions = TableBreakOptions.AllowManualHeights
tb.BreakOptions = TableBreakOptions.EnableBreaking
tb.BreakOptions = TableBreakOptions.RepeatTopLabels
tb.SetBreakSpacing(0.09375 * dwgScale)
Using doclok As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument
Using t As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = CType(t.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = CType(t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
tb.GenerateLayout()
Dim TblId As ObjectId
TblId = btr.AppendEntity(tb)
t.AddNewlyCreatedDBObject(tb, True)
t.Commit()
End Using
End Using
End If
End Sub
Was this answered? I am looking for table.settextheight and I get the warning
Warning 2 'Autodesk.AutoCAD.DatabaseServices.Table.SetTextHeight(double, int)' is obsolete: '"Use Cell functionality instead."'
and for the Cell Type would this work for you?
DataTypeParameter cellDataType = new DataTypeParameter();
cellDataType.DataType = DataType.XXXX;
cellDataType.UnitType = UnitType.Unitless;
myTable.Cells[-1, -1].DataType = cellDataType;
Thanks SENL1362. I found some stuff from fixo (ty for sharing oleg, andrey bushman, jeff h, and others). Quite a bit of this is in the swamp.
from fixo:
acdb.DataTypeParameter dtp = new acdb.DataTypeParameter();
dtp.DataType = acdb.DataType.Double;
dtp.UnitType = acdb.UnitType.Distance;
if this column is the 1 i want to change to 6 decimal places
mytable.Cells[i, j].Contents[0].DataType = dtp;
mytable.Cells[i, j].Contents[0].Value = drilltable.Rows[i].ItemArray[j];
mytable.Cells[i, j].Contents[0].DataFormat = "%lu2%pr6%"; <--- how intuitive! Is this documented somewhere?
Here are some links:
http://www.acadnetwork.com/index.php?topic=150.0
https://sites.google.com/site/acadhowtodo/net/styles/table-styles
http://www.theswamp.org/index.php?topic=42867.msg480949#msg480949
I wasted some time formatting numeric strings in a datatable / datagridview beforehand that were totally ignored - it's like autocad finds a number and insists on changing it.
Wow i am glad I found this.. i was trying to set the precision of my table cells. The best documentation I found for the Mtext format codes was strangely on the BricsCad website..
https://www.bricsys.com/en-eu/blog/coding-with-field-text-customizing-bricscad-p20
FORMATTING
The text displayed by fields is formatted using the following format codes:
Formatting Format Code
Decimal ( .) places | %. |
Angular Units | %au |
Bytes (filesize) | %by |
Convert | %ct |
Decimal Separator | %ds |
File Name, path, and extension | %fn |
Linear Units | %lu |
Line Weight units | %lw |
Precision | %pr |
Points (x,y,z) | %pt |
Scale Factor | %qf |
Text Case | %tc |
Hexadecimal conversion | %X |
Some notes on format codes:
%X forces numbers to be displayed in hexadecimal notation (base 16)
%ld is a code used by file sizes; I haven't figured out, but it seems to have no effect
%qf is used by scale factors, but employs values I haven't figured out yet
Some codes use the same naming system as related variables. For example, %lu (linear units) uses the same values as the LUnits system variable, such as 1 = scientific units and 2 = decimal units.