VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Looping through layouts to identify a table

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
cve60069
2215 Views, 2 Replies

Looping through layouts to identify a table

hello

 

I have a drawing that has 19 layouts. Each layout has a table. I want to loop through each layout and identify each table.

 

My code so far. 

 

Sub DoDataSheets()

'Module to write to the Data Sheets

'Declare the Global Variables
' Number of Data Sheets to write to.
Const nSheets As Integer = 19

'Identify the tables

Dim tableArray(nSheets) As AcadTable

'Set Entities
Dim entity As Object
Dim tTable As AcadTable
Dim tableIndex, loopIndex As Integer
tableIndex = 1


For Each entity In ThisDrawing.PaperSpace

If entity.EntityName = "AcDbTable" Then


Debug.Print "tableIndex", tableIndex


'Set tableArray(tableIndex) = entity


tableIndex = tableIndex + 1
'
End If


Next entity

 

End Sub

 

My result is always 1

 

Regards

 

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: cve60069

AcadDocument/ThisDrawing.PaperSpace only refers to the block of currently active layout, thus your code would always ONLY find table on current layout, not all other 18 layout that are inactive.

 

You have 2 options:

 

1. Make each layout active and then use the same code, like:

 

Dim lay  As AcadLayout

For Each lay In ThisDrawing.Layouts

    ThisDrawing.ActiveLayout=lay

    ''Then your existing code here

    For Each entity in ThisDrawng.PaperSpace

      If TypeOf netity Is AcadTable Then

        .....

      End If

    Next

Next

 

With this approach, AutoCAD has to update screen when active layout changes, which make result in screen regen, which takes time.

 

2. Loop through each layout's Block, which is where the entities of each Layout are stored:

 

Dim lay As AcadLayout

For Each lay In ThisDrawing.Layouts

  For Each entity in lay.Block

      If TypeOf netity Is AcadTable Then

        ....

      End If

  Next

Next

 

Actually, you can also use AcadSelectionSet with filter to get all AcadTable objects, and, if you need to know a table belongs to which Layout, you can use AcadTable.OwnerId to compare with each Layout's Block's ObjectId, thus determine which Layout the table belongs to.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
cve60069
in reply to: norman.yuan

Norman

 

Thanks for the advice.

 

I am now able to loop through a drawing with many layouts, find the tables and write the contents of one table into the other tables.

 

Many thanks and I attach the solution.

 

Regards

 

Daniel

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report