Table Selection

Table Selection

Anonymous
Not applicable
600 Views
2 Replies
Message 1 of 3

Table Selection

Anonymous
Not applicable

Hi to all.

I have a little problem with table selection in 4 differnt already opened drawings.

 

The scope is to populate the table with data that are contents in a txt file previously stored in an array SourceFileName(I).

 

The below code should select 4 drawings wich contain table, select the table and populate certain rows and columns.

 

Seems that the code work properly only for the first table and not for the 2nd (index 26 to 50), the 3rd  (index 51 to 75) and 4th (76 ti 100).

 

The code is executed for all sections but the value are not transfer to the table.

Pls somebody could help me ??

 

For I = 0 To MyLineCount
    Select Case I
    Case 0 To 25
    For Each Doc In ThisDrawing.Application.Documents
        If Doc.Name = "INDICE.dwg" Then
            Doc.Activate
            Exit For
        End If
    Next
    For Each Entity In ThisDrawing.ModelSpace
        If Entity.EntityName = "AcDbTable" Then
            Set Tabella1 = Entity
            Exit For
        End If
    Next Entity
    Tabella1.SetCellValue I + 7, 2, SourceFileName(I)
    Tabella1.SetCellValue I + 7, 3, SourceFileName(I)
     '
     '
     '
    Case 26 To 50
    For Each Doc In ThisDrawing.Application.Documents
        If Doc.Name = "INDICE_2.dwg" Then
            Doc.Activate
            Exit For
        End If
    Next
    For Each Entity2 In ThisDrawing.ModelSpace
        If Entity2.EntityName = "AcDbTable" Then
            Set Tabella2 = Entity2
            Exit For
        End If
    Next Entity2
    Tabella2.SetCellValue I + 2, 2, SourceFileName(I)
    Tabella2.SetCellValue I + 2, 3, SourceFileName(I) '
    '
    '
  
    Case 51 To 75
    For Each Doc In ThisDrawing.Application.Documents
        If Doc.Name = "INDICE_3.dwg" Then
            Doc.Activate
            Exit For
        End If
    Next
    For Each Entity3 In ThisDrawing.ModelSpace
        If Entity3.EntityName = "AcDbTable" Then
            Set Tabella3 = Entity3
            Exit For
        End If
    Next Entity3
    Tabella3.SetCellValue I + 2, 2, SourceFileName(I)
    Tabella3.SetCellValue I + 2, 3, SourceFileName(I)
    '
    '
    '
    If I = 76 Then
        ThisDrawing.Application.Documents.Close
    End If
    Case 76 To 100
    For Each Doc In ThisDrawing.Application.Documents
        If Doc.Name = "INDICE_4.dwg" Then
            Doc.Activate
            Exit For
        End If
    Next
    For Each Entity4 In ThisDrawing.ModelSpace
        If Entity4.EntityName = "AcDbTable" Then
            Set Tabella4 = Entity4
            Exit For
        End If
    Next Entity4
    Tabella1.SetCellValue I + 2, 2, SourceFileName(I)
    Tabella1.SetCellValue I + 2, 3, SourceFileName(I)
    '
    '
     End Select
Next

End Sub

 

0 Likes
601 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Have you tried to step through your code line by line to see if it is doing what it is supposed to be doing.  I know when I am debugging I will set breaks, or through up message boxes that contain information I am expecting just to make sure.

 

 

0 Likes
Message 3 of 3

Hallex
Advisor
Advisor

I think you may select table using selectionset like this:

{code}

Option Explicit

Public Sub SelectTable()

Dim oSset As AcadSelectionSet
Dim oEnt As AcadEntity
Dim oTable As AcadTable
Dim ftype(2) As Integer
Dim fdata(2) As Variant
Dim dxftype As Variant
Dim dxfdata As Variant
Dim intRows As Integer

intRows = CInt(InputBox("How much rows in the table: ", "Select Table", 40))
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'

On Error GoTo Err_Control
    ftype(0) = 0: fdata(0) = "ACAD_TABLE"
    ftype(1) = 91: fdata(1) = intRows '<--- number of rows
    ftype(2) = 410: fdata(2) = "Model" '<--- model tab
          With ThisDrawing.SelectionSets
               While .Count > 0
                    .item(0).Delete
               Wend
          Set oSset = .Add("$TableSet$")
          End With
         
    dxftype = ftype
   
    dxfdata = fdata
   
    '~~~~~~~~~~~~~~~~ Select table ~~~~~~~~~~~~~~~'

   oSset.Select acSelectionSetAll, , , dxftype, dxfdata
  
   If oSset.Count = 0 Then
  
   MsgBox "Nothing selected. Exiting program..."
  
   Exit Sub
  
   Else
  
   Set oEnt = oSset.item(0)
  
   Set oTable = oEnt
  
   MsgBox "Rows: " & oTable.Rows & vbCr & _
   "Columns: " & oTable.Columns
  
   End If
  
Err_Control:
  
   End Sub

{code}

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes