Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applying changes to multiple sheets in 1 drawing 1

Status
Not open for further replies.

LucasC

Automotive
Feb 18, 2019
157
0
0
US
I'm trying to apply changes to a revision column on multiple sheet of 1 drawing. If the "apply to all sheets" toggle is on, it performs that action when, a separate, "apply changes" command button is clicked.

What I need help with is which method I should use to loop through each sheet and apply the change. I've tried Do..While, Do, For..each.

Also I don't understand this:

Sheetcount = DrawingDoc.sheets.Count (3 sheets in my test drawing)

Dim SheetIndex As Integer
For SheetIndex = 1 To SheetCount Step 1
Next

SheetIndex now has a value 4??? why? where did the extra integer come from? MS docs says this should = 1 2 3.




Code:
Dim DrawingDoc As DrawingDocument
Set DrawingDoc = CATIA.ActiveDocument

Dim DrawingSheet As DrawingSheets
Set DrawingSheet = DrawingDoc.sheets

Dim sheet As Integer
Dim SheetCount As Integer
[COLOR=#4E9A06]'sheet = sheet + 1[/color]
SheetCount = DrawingDoc.sheets.Count

If ApplyToAll.Value = True Then

Dim SheetIndex As Integer
For SheetIndex = 1 To SheetCount Step 1
Next

Do Until SheetIndex = SheetCount
DrawingSheet.Item(SheetIndex).Activate
[COLOR=#4E9A06]'SheetCount is registering a correct value[/color]
 
Replies continue below

Recommended for you

Unfortunately, I am not familiar with "revision column" and "apply to all sheets" toggle.


SheetIndex becomes 4 as expected - read docs again:

Each time Visual Basic encounters the Next statement, it increments counter by step and returns to the For statement. Again it compares counter to end, and again it either runs the block or exits the loop, depending on the result. This process continues until counter passes end or an Exit For statement is encountered.

The loop doesn't stop until counter has passed end. If counter is equal to end, the loop continues. The comparison that determines whether to run the block is counter <= end if step is positive and counter >= end if step is negative.
 
Disregard "revision column" and "apply toggle" those are buttons on my userform this code is attached to.

My only real question is which method to use to loop through this code properly. or in other words; go to sheet 1, execute the code, go to sheet 2 execute the code and so on until it reaches the last sheet regardless of how many sheets are present.


Ive tried the different methods but I don't think I'm structuring it properly (the If..then seems to interfere with the loop). Ive also tried adding "do until sheetindex = sheetcount". The only thing that seems to happen successfully is it changing a chart on the last sheet since its seeing SheetIndex as its final value.

Code:
Dim DrawingDoc As DrawingDocument
Set DrawingDoc = CATIA.ActiveDocument

Dim DrawingSheet As DrawingSheets
Set DrawingSheet = DrawingDoc.sheets

Dim sheet As Integer
Dim SheetCount As Integer
'sheet = sheet + 1
SheetCount = DrawingDoc.sheets.Count

If ApplyToAll.Value = True Then

Dim SheetIndex As Integer
For SheetIndex = 1 To SheetCount Step 1
Next

Do Until SheetIndex = SheetCount
DrawingSheet.Item(SheetIndex).Activate
 
It's quite simple to do with for...each:

Code:
Dim sh, vw
For each sh in CATIA.ActiveDocument.Sheets
  For each vw in sh.Views
    ' do the code for the view vw on sheet sh
    ...
  Next
Next
 
Its giving me a "Object doesn't support this property or method" error. Are "For...Each" able to be nested inside an "If...Then"?

I see in your example that you are going into a view but the tables I need to edit on the CATDrawing are not in views. They are in the sheet background.

I added some notes to what I tried below

Code:
Dim DrawingDoc As DrawingDocument
Set DrawingDoc = CATIA.ActiveDocument

Dim DrawingSheet As DrawingSheets
Set DrawingSheet = DrawingDoc.sheets

Dim DrawingTables As DrawingTables
Set DrawingTables = DrawingDoc.sheets.ActiveSheet.views.Item("Background View").Tables

Dim DrawingTable1 As DrawingTable
Set DrawingTable1 = DrawingTables.GetItem("Revision_Text_Table")

If ApplyToAll.Value = True Then   [highlight #73D216]'This is a toggle button on my userform[/highlight]

[highlight #FCE94F]For Each DrawingSheet In DrawingDoc[/highlight]  [highlight #73D216]'Error stops it here[/highlight]

For Each DrawingTable1 In DrawingSheet

Dim Table_Revision_Rows
Table_Revision_Rows = DrawingTable1.NumberOfRows

DrawingTable1.SetCellString 1, 1, UCase("REVISIONS")

DrawingTable1.SetCellString Table_Revision_Rows, 1, UCase(Revisions.TB_Revision_Mod.Value)
DrawingTable1.SetCellString Table_Revision_Rows, 2, UCase(Revisions.TB_Revision_RDC.Value)
DrawingTable1.SetCellString Table_Revision_Rows, 3, UCase(Revisions.TB_Revision_Date.Value)
DrawingTable1.SetCellString Table_Revision_Rows, 4, Left(UCase(Revisions.TB_Revision_Drawer.Value), 5)
DrawingTable1.SetCellString Table_Revision_Rows, 5, Left(UCase(Revisions.TB_Revision_Checker.Value), 5)
Next
Next
End If
 
I'm trying to learn not just copy/paste. When you write "For each vw in sh.Views", In my mind, I'm drilling down into a drawing view. In my case the table I want to edit is not in a "View" so it didn't make sense. I interpreted it the best I knew how.

View_dgp2xw.png
 
Oh, I see.

As I always say to learn scripting you have to master CATIA first.

Each regular drawing sheet in CATIA has at least two default views:
1. Background view
2. Main view

Note that view names are NLS strings, so they change depending on user language. However, their indices in Views collection always remain intact.

So this is what you should do:

Code:
For each sh in DrawingDoc.Sheets
  Dim tbl: set tbl = sh.Views.Item(1).Tables.Item("Revision_Text_Table")
  tbl.SetCellString...
 
Status
Not open for further replies.
Back
Top