Hello,
I'm writing a simple routine to take the measurment value from several selected dimensions and place them organized in a table. I am having a problem with the final output, so perhaps I have the wrong approach. When the command is finished, the table displays a 'uncalculated' field in the cell (####). When I move to edit the cell, the field value shows the appropriate text. Then I cancel the edit. Then the table shows the calculated value (1'-0"). Here is my code, and thank you for any advice:
Private Shared Sub ProcessDimensions(dims As List(Of Autodesk.AutoCAD.DatabaseServices.RotatedDimension), ByRef trans As Transaction, ByRef btrSpace As BlockTableRecord, doc As Document) 'separate dimensions by horizontal and vertical, and sort by measurement Dim vertDims As New SortedDictionary(Of Double, Autodesk.AutoCAD.DatabaseServices.RotatedDimension) Dim horizontalDims As New SortedDictionary(Of Double, Autodesk.AutoCAD.DatabaseServices.RotatedDimension) For Each rDim As RotatedDimension In dims Select Case Math.Round(rDim.Rotation, 6) Case 0 If Not horizontalDims.ContainsKey(rDim.Measurement) Then horizontalDims.Add(rDim.Measurement, rDim) End If Case CommonTools.DegreesToRadians(90) If Not vertDims.ContainsKey(rDim.Measurement) Then vertDims.Add(rDim.Measurement, rDim) End If Case CommonTools.DegreesToRadians(180) If Not horizontalDims.ContainsKey(rDim.Measurement) Then horizontalDims.Add(rDim.Measurement, rDim) End If Case CommonTools.DegreesToRadians(270) If Not vertDims.ContainsKey(rDim.Measurement) Then vertDims.Add(rDim.Measurement, rDim) End If End Select Next 'now we have sorted lists of vertical dims and horizontal dims 'Start a new table Dim dTable As Table = nothing Dim psr As Autodesk.AutoCAD.EditorInput.PromptSelectionResult Dim pso As New Autodesk.AutoCAD.EditorInput.PromptSelectionOptions pso.MessageForAdding = "Select the clearance dimensions table" pso.MessageForRemoval = "Remove dimensions" pso.AllowDuplicates = False pso.SingleOnly = True psr = doc.Editor.GetSelection(pso) If psr.Status = Autodesk.AutoCAD.EditorInput.PromptStatus.OK Then For Each so As Autodesk.AutoCAD.EditorInput.SelectedObject In psr.Value Dim ent As Entity = trans.GetObject(so.ObjectId, OpenMode.ForRead) If TypeOf ent Is Autodesk.AutoCAD.DatabaseServices.Table Then dTable = ent Exit For End If Next End If If dTable IsNot Nothing Then dTable = trans.GetObject(dTable.Id, OpenMode.ForWrite) Dim rowNum As Int16 = 1 For Each rDim As RotatedDimension In vertDims.Values rowNum += 1 Dim cell As Cell = dTable.Cells.Item(rowNum, 0) Dim strField As String = "%<\AcObjProp Object(%<\_ObjId " strField += Replace(Replace(rDim.ObjectId.ToString, ")", ""), "(", "") strField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%" 'Debug.Print(strField) cell.SetValue(strField, ParseOption.ParseOptionNone) Next rowNum = 1 For Each rDim As RotatedDimension In horizontalDims.Values rowNum += 1 Dim cell As Cell = dTable.Cells.Item(rowNum, 1) Dim strField As String = "%<\AcObjProp Object(%<\_ObjId " strField += Replace(Replace(rDim.ObjectId.ToString, ")", ""), "(", "") strField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%" 'Debug.Print(strField) Dim newField As New Field(strField, True) newField.Evaluate() Dim fieldEval As FieldEvaluationStatusResult = newField.EvaluationStatus If fieldEval.Status = FieldEvaluationStatus.Success Then cell.SetValue(newField, ParseOption.ParseOptionNone) 'trans.AddNewlyCreatedDBObject(newField, True) End If Next dTable.RecomputeTableBlock(True) trans.Commit() End If End Sub
jvj
Solved! Go to Solution.
Solved by JamieVJohnson2. Go to Solution.
Any chance I can get some help with this one? So far, I've learned that The cells in a table can have a collection of sub items, known as content, and one can directly add and remove said content. I've also learned that changing the cell.DataFormat or Cell.Contents.item(0).DataFormat, can cause AutoCAD 2012 to crash. Any other insights?
jvj
I love it when I solve my own problems...
BEST Practice when adding values to a Table Cell:
Cell.TextString = field code as string.
You can call Cell.TextString or Table.Cells.Item(row,column).TextString
All other methods of entering a data as a field will not work, trust me, I've tried them all before I found this one.
...Always in the last place you look...
But I still can't figure out why after I add my data, the table clears out 3 cells in addition, and I didn't even address these cells, because they are on a different row alltogether. Funny thing, if I rerun the routine on the same table, a forth cell is cleared, then fifth, sixth, until the table runs out of extra rows and columns. Then it crashes the transaction manager's flush graphics routine, and the table dissapears, until I regen. Anybody seen that behavior before?
jvj
I'm still working out issues, but it appears that after setting the TextString recomputing the table block reduces the instance of the cells being deleted.
tble.Cells[0, columnPaveStyle].TextString = pvmtSettings.Title;
tble.RecomputeTableBlock(true);