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

Autodesk.AutoCAD.DatabaseServices.Table random FlushGraphics error

13 REPLIES 13
Reply
Message 1 of 14
JamieVJohnson2
1870 Views, 13 Replies

Autodesk.AutoCAD.DatabaseServices.Table random FlushGraphics error

Error,

 

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

   at Autodesk.AutoCAD.ApplicationServices.TransactionManager.FlushGraphics()

 

also cites a position in the code where i'm calling transaction.commit.

 

This happens once in a while, but not all the time.  In this code I'm not creating a new table, just manipulating one the user selected.  This routine (probably already posted here once before) creates fields in 2 columns that link to selected dimensions' measurement values, and two other columns with formula fields that round up or down from the first two columns as logically necessary.

 

My workaround so far, has been to regen, save the file, close and open it again.  The second time around everything works ok.  I have noticed this happen more often when I add rows to a table manually (but not when I remove them).  Another unknown quirk is when the code finished with extra rows still in the table, it wipes out the data in the next 3 cells following the last row used, but I don't think that last one is directly related.  I've had this issue with AutoCAD table .net api since 2011-13.

 

Code available upon request (lots of fines and related files).

 

Can somebody help me resolve this flush graphics error?

 

jvj

jvj
13 REPLIES 13
Message 2 of 14

Hi,

 

As you can understand, it is really tough to tell what is going wrong in the code. My suggestion would be to provide very simple code (buildable) with exact steps to reproduce the issue. 

 

Note, most of the time, it the context in which code runs creates the issue. Like calling the code from reactor call back, or having a complex logic in reactor callbacks which is getting trigged because of some action in your code.

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 14

Well, I can assure you that the code is not called through a 'reactor' or 'event' call back.  There is no 'automatic' response process happening here.  The user has to type in a command to activate this code.

The calling code:

    <CommandMethod("FillOutClearanceDimsTable")> _
    Public Shared Sub FillOutClearanceDimsTable()
        Try
            Dim doc As Document = AApplication.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Using lock As DocumentLock = doc.LockDocument
                Using trans As Transaction = db.TransactionManager.StartTransaction
                    Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
                    Dim btrSpace As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
                    Dim dimensions As New List(Of Autodesk.AutoCAD.DatabaseServices.RotatedDimension)
                    Dim psr As Autodesk.AutoCAD.EditorInput.PromptSelectionResult
                    Dim pso As New Autodesk.AutoCAD.EditorInput.PromptSelectionOptions
                    pso.MessageForAdding = "Select all vertical and horizontal clearance dimensions"
                    pso.MessageForRemoval = "Remove dimensions"
                    pso.AllowDuplicates = False
                    pso.SingleOnly = False
                    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.RotatedDimension Then
                                dimensions.Add(ent)
                            End If
                        Next
                        ClearanceDrawings.ProcessDimensions(dimensions, trans, btrSpace, doc)
                    End If
                    trans.Commit()
                End Using
            End Using
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

 The Process Dimensions Code:

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Windows Imports Microsoft.Win32 Imports System.Reflection Imports System.Drawing Imports AApplication = Autodesk.AutoCAD.ApplicationServices.Application Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices.Filters Module ClearanceDrawings Dim dTable As Autodesk.AutoCAD.DatabaseServices.Table Public Sub ProcessDimensions(ByRef dims As List(Of Autodesk.AutoCAD.DatabaseServices.RotatedDimension), ByRef mTrans As Transaction, ByRef btrSpace As BlockTableRecord, ByRef mDoc As Document) 'separate dimensions by horizontal and vertical, and sort by measurement Dim doc As Document = mDoc Using trans As Transaction = mTrans.TransactionManager.StartTransaction 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 dTable = 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) If dTable.Rows.Count < (vertDims.Count + 2) Then Dim lastRow As Integer = dTable.Rows.Count - 1 Dim rowHeight As Double = dTable.Rows(lastRow).Height Dim rowCount As Integer = (vertDims.Count + 2) - dTable.Rows.Count dTable.InsertRows(lastRow, rowHeight, rowCount) 'dTable.RecomputeTableBlock(True) End If Dim rowNum As Integer = 1 Dim hMax As Double = 0 Dim roundUp As Boolean = False Dim strZero As String = "%<\AcExpr (0) \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" '"0'-0" & Chr(34) 'Dim strDBDims As String = String.Empty 'in here we will store a replica of the dimensions to be pushed into the TTS Main database. 'strDBDims was disabled because we always modify the dimensions after creating this table. For Each vDim As RotatedDimension In vertDims.Values Dim dbHDim As Double = 0 rowNum += 1 Dim vCell As Cell = dTable.Cells.Item(rowNum, 0) Dim strVField As String = "%<\AcObjProp Object(%<\_ObjId " strVField += Replace(Replace(vDim.ObjectId.ToString, ")", ""), "(", "") strVField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%" SetCellValue(vCell, strVField) 'now find the horizontal dimension that exactly corresponds to the vertical dimension Dim vDimPoint As Autodesk.AutoCAD.Geometry.Point3d = Nothing If vDim.XLine1Point.Y - vDim.XLine2Point.Y > 0 Then vDimPoint = vDim.XLine1Point Else vDimPoint = vDim.XLine2Point End If Dim booFound As Boolean = False Dim hCell As Cell = dTable.Cells.Item(rowNum, 1) Dim horDim As RotatedDimension = Nothing For Each hDim As RotatedDimension In horizontalDims.Values 'first look for coincident points If vDimPoint.DistanceTo(hDim.XLine1Point) < 0.0000001 Then booFound = True End If If vDimPoint.DistanceTo(hDim.XLine2Point) < 0.0000001 Then booFound = True End If 'if boofound = false then look for point that share the same x value If Math.Abs(vDimPoint.X - hDim.XLine1Point.X) < 0.0000001 Then booFound = True End If If Math.Abs(vDimPoint.X - hDim.XLine2Point.X) < 0.0000001 Then booFound = True End If If booFound Then horDim = hDim If hDim.Measurement >= hMax Then hMax = hDim.Measurement Else roundUp = True End If Dim strHField As String = "%<\AcObjProp Object(%<\_ObjId " strHField += Replace(Replace(hDim.ObjectId.ToString, ")", ""), "(", "") strHField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%" SetCellValue(hCell, strHField) dbHDim = Math.Round(hDim.Measurement, 😎 Exit For End If Next If booFound = False Then SetCellValue(hCell, strZero) End If 'now set the rounded values vCell = dTable.Cells.Item(rowNum, 2) Dim strRDown As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "-.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" Dim strRUp As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" If roundUp Then SetCellValue(vCell, strRUp) 'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement + 0.49999999), 0))) & ";" Else SetCellValue(vCell, strRDown) 'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement - 0.49999999), 0))) & ";" End If hCell = dTable.Cells.Item(rowNum, 3) strRUp = "%<\AcExpr (B" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" SetCellValue(hCell, strRUp) 'strDBDims += "H" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((dbHDim + 0.49999999), 0))) & ";" Next 'strDBDims = strDBDims.TrimEnd(";") 'UploadDimensionsToDatabase(strDBDims) trans.Commit() End If End Using End Sub End Module

 

 

 The cell value code:

    Public Sub SetCellValue(ByRef cell As Autodesk.AutoCAD.DatabaseServices.Cell, ByRef value As String)
        If cell IsNot Nothing Then
            If cell.FieldId <> ObjectId.Null Then
                Dim field As Field = cell.FieldId.GetObject(OpenMode.ForWrite)
                Dim code As String = field.GetFieldCode()
                field.SetFieldCode(value)
            Else
                cell.TextString = value
            End If
        End If
    End Sub

    Public Function GetCellValue(ByRef cell As Autodesk.AutoCAD.DatabaseServices.Cell) As String
        Dim strValue As String = Nothing
        If cell IsNot Nothing Then
            If cell.FieldId <> ObjectId.Null Then
                Dim field As Field = cell.FieldId.GetObject(OpenMode.ForWrite)
                strValue = field.GetStringValue
            Else
                strValue = cell.TextString
            End If
        End If
        Return strValue
    End Function

 That is the entire basic process.

 

  1. Create a drawing in modelspace to world scale
  2. create viewport in paperspace to some scale (anyscale will do)
  3. draw associative dimensions (7 vertical 7 horizontal -any number will do, but 7 is average for us) in paperspace to the linework in modelspace over the viewport
  4. stack your vertical dimensions in baseline style from bottom up
  5. make sure that each vertical dimension has one node (the highest node of the dimension)  in common with a node of a horizontal dimension vertically (with no tolerance).  (xVertDim - xHorizDim = 0)
  6. (Dimassoc = 2, dimscale=1)
  7. create a 4 column table with 1 title row, 1 header row, and 20 data rows
  8. Fill the table with 0's
  9. Run the routine and follow the prompts.
  10. Notice the table took down 3 more cells than called for.
  11.  To reproduce the error (happens many times but not all) remove or add a row from the table and rerun routine.

jvj

jvj
Message 4 of 14

The process dimensions code again:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Windows
Imports Microsoft.Win32
Imports System.Reflection
Imports System.Drawing
Imports AApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices.Filters

Module ClearanceDrawings

    Dim dTable As Autodesk.AutoCAD.DatabaseServices.Table

    Public Sub ProcessDimensions(ByRef dims As List(Of Autodesk.AutoCAD.DatabaseServices.RotatedDimension), ByRef mTrans As Transaction, ByRef btrSpace As BlockTableRecord, ByRef mDoc As Document)
        'separate dimensions by horizontal and vertical, and sort by measurement
        Dim doc As Document = mDoc
        Using trans As Transaction = mTrans.TransactionManager.StartTransaction
            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
            dTable = 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)
                If dTable.Rows.Count < (vertDims.Count + 2) Then
                    Dim lastRow As Integer = dTable.Rows.Count - 1
                    Dim rowHeight As Double = dTable.Rows(lastRow).Height
                    Dim rowCount As Integer = (vertDims.Count + 2) - dTable.Rows.Count
                    dTable.InsertRows(lastRow, rowHeight, rowCount)
                    'dTable.RecomputeTableBlock(True)
                End If
                Dim rowNum As Integer = 1
                Dim hMax As Double = 0
                Dim roundUp As Boolean = False
                Dim strZero As String = "%<\AcExpr (0) \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" '"0'-0" & Chr(34)
                'Dim strDBDims As String = String.Empty 'in here we will store a replica of the dimensions to be pushed into the TTS Main database. 
                'strDBDims was disabled because we always modify the dimensions after creating this table.
                For Each vDim As RotatedDimension In vertDims.Values
                    Dim dbHDim As Double = 0
                    rowNum += 1
                    Dim vCell As Cell = dTable.Cells.Item(rowNum, 0)
                    Dim strVField As String = "%<\AcObjProp Object(%<\_ObjId "
                    strVField += Replace(Replace(vDim.ObjectId.ToString, ")", ""), "(", "")
                    strVField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%"
                    SetCellValue(vCell, strVField)
                    'now find the horizontal dimension that exactly corresponds to the vertical dimension
                    Dim vDimPoint As Autodesk.AutoCAD.Geometry.Point3d = Nothing
                    If vDim.XLine1Point.Y - vDim.XLine2Point.Y > 0 Then
                        vDimPoint = vDim.XLine1Point
                    Else
                        vDimPoint = vDim.XLine2Point
                    End If
                    Dim booFound As Boolean = False
                    Dim hCell As Cell = dTable.Cells.Item(rowNum, 1)
                    Dim horDim As RotatedDimension = Nothing
                    For Each hDim As RotatedDimension In horizontalDims.Values
                        'first look for coincident points
                        If vDimPoint.DistanceTo(hDim.XLine1Point) < 0.0000001 Then
                            booFound = True
                        End If
                        If vDimPoint.DistanceTo(hDim.XLine2Point) < 0.0000001 Then
                            booFound = True
                        End If
                        'if boofound = false then look for point that share the same x value
                        If Math.Abs(vDimPoint.X - hDim.XLine1Point.X) < 0.0000001 Then
                            booFound = True
                        End If
                        If Math.Abs(vDimPoint.X - hDim.XLine2Point.X) < 0.0000001 Then
                            booFound = True
                        End If
                        If booFound Then
                            horDim = hDim
                            If hDim.Measurement >= hMax Then
                                hMax = hDim.Measurement
                            Else
                                roundUp = True
                            End If
                            Dim strHField As String = "%<\AcObjProp Object(%<\_ObjId "
                            strHField += Replace(Replace(hDim.ObjectId.ToString, ")", ""), "(", "")
                            strHField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%"
                            SetCellValue(hCell, strHField)
                            dbHDim = Math.Round(hDim.Measurement, 8)
                            Exit For
                        End If
                    Next
                    If booFound = False Then
                        SetCellValue(hCell, strZero)
                    End If
                    'now set the rounded values
                    vCell = dTable.Cells.Item(rowNum, 2)
                    Dim strRDown As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "-.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    Dim strRUp As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    If roundUp Then
                        SetCellValue(vCell, strRUp)
                        'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement + 0.49999999), 0))) & ";"
                    Else
                        SetCellValue(vCell, strRDown)
                        'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement - 0.49999999), 0))) & ";"
                    End If
                    hCell = dTable.Cells.Item(rowNum, 3)
                    strRUp = "%<\AcExpr (B" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    SetCellValue(hCell, strRUp)
                    'strDBDims += "H" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((dbHDim + 0.49999999), 0))) & ";"
                Next
                'strDBDims = strDBDims.TrimEnd(";")
                'UploadDimensionsToDatabase(strDBDims)
                trans.Commit()
            End If
        End Using
    End Sub

 

jvj
Message 5 of 14

Thanks for the sharing code. One suggestion, you must avoid mixing “Transaction” and “DBObject.Open” usage. So, try passing “Transaction” to “SetCellValue” and “GetCellValue” functions.

 

If above suggestion fails, then share a non confidential drawing file so that I can test the code from your step 8.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 6 of 14

Made that change, and so far, I'm still wiping out extra cells. The jurry is still out about the flush graphics error, but haven't had it happen in the 1 time I ran it so far. Jamie V. Johnson CAD Manager
jvj
Message 7 of 14

Hi,

 

I'm still wiping out extra cells

can you please share a non confidential drawing file so that I can test the code from your step 8.

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 8 of 14

I did get a flush graphics crash this time.  I started with a file that had no table, inserted the table within a block (from file), exploded the block, exposing the table, then ran the modified routine on it.  I get this:

--------------------------- TTSAutoCADTools --------------------------- System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

   at Autodesk.AutoCAD.ApplicationServices.TransactionManager.FlushGraphics()

   at TTSAutoCADTools.ClearanceDrawings.ProcessDimensions(List`1& dims, Transaction& mTrans, BlockTableRecord& btrSpace, Document& mDoc) in C:\Code\AutoCAD\TTSAutoCADTools\TTSAutoCADTools\ClearanceDimensions.vb:line 146

   at TTSAutoCADTools.Tools.FillOutClearanceDimsTable() in C:\Code\AutoCAD\TTSAutoCADTools\TTSAutoCADTools\Tools.vb:line 247 --------------------------- OK   ---------------------------

In addition, the routine was not allowed to modify the table.  If I close the file, and open it, and run the routine again, it will work just fine.

I'll attach the file this time.  The table in question is the 4 column table "Clearance Dims"

jvj
Message 9 of 14

well, well, now it fails evertime on this file.  I didn't change the code from the last time when it worked.  In addition all attempts to select anything after this has run fails (select first, select during a command, anytime).

 

jvj

jvj
Message 10 of 14

 

 

Ok, instead of creating a new “Transaction” inside the ProcessDimensions using the Transaction passed as parameter as shown below

 

 Public Shared Sub ProcessDimensions(ByRef dims As List(Of Autodesk.AutoCAD.DatabaseServices.RotatedDimension), ByRef mTrans As Transaction, ByRef btrSpace As BlockTableRecord, ByRef mDoc As Document)
            'separate dimensions by horizontal and vertical, and sort by measurement
            Dim doc As Document = mDoc
            ' Using trans As Transaction = mTrans.TransactionManager.StartTransaction
            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
                Dim dd As Double = Math.Round(rDim.Rotation, 6)
                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
            dTable = 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 = mTrans.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 = mTrans.GetObject(dTable.Id, OpenMode.ForWrite)
                If dTable.Rows.Count < (vertDims.Count + 2) Then
                    Dim lastRow As Integer = dTable.Rows.Count - 1
                    Dim rowHeight As Double = dTable.Rows(lastRow).Height
                    Dim rowCount As Integer = (vertDims.Count + 2) - dTable.Rows.Count
                    dTable.InsertRows(lastRow, rowHeight, rowCount)
                    'dTable.RecomputeTableBlock(True)
                End If
                Dim rowNum As Integer = 1
                Dim hMax As Double = 0
                Dim roundUp As Boolean = False
                Dim strZero As String = "%<\AcExpr (0) \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%" '"0'-0" & Chr(34)
                'Dim strDBDims As String = String.Empty 'in here we will store a replica of the dimensions to be pushed into the TTS Main database. 
                'strDBDims was disabled because we always modify the dimensions after creating this table.
                For Each vDim As RotatedDimension In vertDims.Values
                    Dim dbHDim As Double = 0
                    rowNum += 1
                    Dim vCell As Cell = dTable.Cells.Item(rowNum, 0)
                    Dim strVField As String = "%<\AcObjProp Object(%<\_ObjId "
                    strVField += Replace(Replace(vDim.ObjectId.ToString, ")", ""), "(", "")
                    strVField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%"
                    SetCellValue(vCell, strVField, mTrans)
                    'now find the horizontal dimension that exactly corresponds to the vertical dimension
                    Dim vDimPoint As Autodesk.AutoCAD.Geometry.Point3d = Nothing
                    If vDim.XLine1Point.Y - vDim.XLine2Point.Y > 0 Then
                        vDimPoint = vDim.XLine1Point
                    Else
                        vDimPoint = vDim.XLine2Point
                    End If
                    Dim booFound As Boolean = False
                    Dim hCell As Cell = dTable.Cells.Item(rowNum, 1)
                    Dim horDim As RotatedDimension = Nothing
                    For Each hDim As RotatedDimension In horizontalDims.Values
                        'first look for coincident points
                        If vDimPoint.DistanceTo(hDim.XLine1Point) < 0.0000001 Then
                            booFound = True
                        End If
                        If vDimPoint.DistanceTo(hDim.XLine2Point) < 0.0000001 Then
                            booFound = True
                        End If
                        'if boofound = false then look for point that share the same x value
                        If Math.Abs(vDimPoint.X - hDim.XLine1Point.X) < 0.0000001 Then
                            booFound = True
                        End If
                        If Math.Abs(vDimPoint.X - hDim.XLine2Point.X) < 0.0000001 Then
                            booFound = True
                        End If
                        If booFound Then
                            horDim = hDim
                            If hDim.Measurement >= hMax Then
                                hMax = hDim.Measurement
                            Else
                                roundUp = True
                            End If
                            Dim strHField As String = "%<\AcObjProp Object(%<\_ObjId "
                            strHField += Replace(Replace(hDim.ObjectId.ToString, ")", ""), "(", "")
                            strHField += ">%).Measurement \f " & Chr(34) & "%lu4%pr4" & Chr(34) & ">%"
                            SetCellValue(hCell, strHField, mTrans)
                            dbHDim = Math.Round(hDim.Measurement, 8)
                            Exit For
                        End If
                    Next
                    If booFound = False Then
                        SetCellValue(hCell, strZero, mTrans)
                    End If
                    'now set the rounded values
                    vCell = dTable.Cells.Item(rowNum, 2)
                    Dim strRDown As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "-.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    Dim strRUp As String = "%<\AcExpr (A" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    If roundUp Then
                        SetCellValue(vCell, strRUp, mTrans)
                        'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement + 0.49999999), 0))) & ";"
                    Else
                        SetCellValue(vCell, strRDown, mTrans)
                        'strDBDims += "V" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((vDim.Measurement - 0.49999999), 0))) & ";"
                    End If
                    hCell = dTable.Cells.Item(rowNum, 3)
                    strRUp = "%<\AcExpr (B" & (rowNum + 1).ToString & "+.49" & Chr(34) & ") \f " & Chr(34) & "%lu4%pr0" & Chr(34) & ">%"
                    SetCellValue(hCell, strRUp, mTrans)
                    'strDBDims += "H" & (rowNum - 1) & ":" & CStr(CInt(Math.Round((dbHDim + 0.49999999), 0))) & ";"
                Next
                'strDBDims = strDBDims.TrimEnd(";")
                'UploadDimensionsToDatabase(strDBDims)
                'trans.Commit()
            End If
            'End Using
        End Sub

 

also, i still not able to understand your comments "I am still wiping out extra cell". when i run above code, i get a table as shown below

table.jpg

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 11 of 14

the three extra cells I'm getting wiped out (cleared and made empty) are the three after the last used row.  I'm curious now as to why, because it's been 3 versions of AutoCAD that have done this, and I can clearly see that it did not wipe them out on your table.  Perhaps; does this have anything to do with AutoCAD vs AutoCAD Mechanical (which I have been using since 2010)?

 

That didn't work out so well.  I ran the code without the nested transaction, and recieved the data into the table after a longer than normal pause, then the program crashed AutoCAD unexpectedly ( i may have 2 transaction commits being called).  But in this clip, you can see the 3 wiped out cells under the last row.

 

jvj

 

jvj
Message 12 of 14

Took me a while of testing but here are the steps to repeat the flush graphics error (even after your code changes):

  1.  Open file with VS debugger running (probably has nothing to do with the actual error).
  2. Open a file with the table already in it and filled out.
  3. Delete the contents of the table using the select cell a3, to cell d8 method, then pressing delete.
  4. Run Fillout on the emptied out table and get this flush graphics error.  Then press OK.
  5. Notice the table is not showing, and run Regen.
  6. Notice table reappears. (font size may have changed as well, mine got shorter).
  7. Play with the flush graphics issues, by dragging the table around, deleting rows and such, watch how the system goofs up.
  8. Save and close the file.
  9. Re Open the file, table behaves ok.

Also upon further investigation I found that only the third cell of the next to last used row is cleared out. I filled all the cells' with values before I ran the routine.  In addition, I see that it does not mess with that cell if I rerun the routine on the same table, only when I run it on a freshly inserted table.

 

jvj

jvj
Message 13 of 14

Hi

 

Sorry, I am unable to reproduce the issue on AutoCAD 2013 win7 64 bit. I followed your steps and with modified sample, I am not able to reproduce the issue. I am attaching the complete project which I am testing at my end.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 14 of 14

That was fun,

I got a video of your test project, crashing.  It did so first try!!  BUT, this is what I did first:

  1. Opened a file with a filled out table
  2. Added 3 rows in the middle.
  3. Deleted all the data in the data rows
  4. Used properties palette to change the text hieght of cell A3
  5. Used match cell properties to match the cell A3 to all the D data rows.
  6. Entered a 0 in cell A3
  7. Used drag fill from A3 to D3
  8. Used drag fill from D3 to D14(or so, full table)
  9. Selected cells A3 to D14
  10. Used table ribbon text alignment button to set middle center on all selected cells
  11. Started recording video.

The flush graphics error has to be related to editing the table before running this routine.

I can place the video in buzzsaw if you give me a site. (53mb zipped)

jamie.johnson@railengineer.com

jvj

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