我想获得一些 VBA 代码,它可以告诉我 Catia 绘图中的图纸数量。每张纸上都会有一个标题栏。每个标题栏上的文本字段将传达图纸数量。因此,如果您在图纸中有三张图纸,您将有 3 张中的 1 张(在标题栏图纸 1 中) 3 张中的 2 张(在标题栏 shhet 2 中)和 3 中的 3 张(在标题栏图纸 3 中)。如果宏可以自动更新所有图纸上的所有标题栏。
非常感谢任何帮助。
这个概念是遍历集合中的所有DrawingSheet
对象,您应该将所有标题块元素放在“背景视图”中。接下来我们需要更新或创建现有的标题栏文本元素。这些是对象。我们尝试按名称访问(这必须是唯一的!)。如果它不存在,我们创建它。如果它确实存在,我们更新该值。Sheets
DrawingDocument
DrawingText
DrawingText
这是制作标题栏的开始:
Option Explicit
Sub UpdateSheetPage()
Dim DrawingDoc As DrawingDocument
Dim DSheet As DrawingSheet
Dim DView As DrawingView
Dim SheetCount As Integer
Dim currentSheet As Integer
'the drawing must be the active docuement window or this will fail. you can do more error checking if needed
On Error GoTo ExitSub
Set DrawingDoc = CATIA.ActiveDocument
SheetCount = DrawingDoc.Sheets.Count
currentSheet = 1 'initialize sheet number
'loop through all sheets and update or create a sheet number
For Each DSheet In DrawingDoc.Sheets
UpdatePageNumber DSheet, currentSheet, SheetCount
currentSheet = currentSheet + 1
Next
ExitSub:
End Sub
Sub UpdatePageNumber(currentDrawingSheet As DrawingSheet, currentSheetNumber As Integer, totalSheets As Integer)
Dim sheetNumber As String
Dim xPos, yPos As Long 'mm
'edit these if needed
xPos = 100 'edit this - only use for new creation
yPos = 100 'edit this
'display format
sheetNumber = "Page " & currentSheetNumber & "/" & totalSheets
Dim backgroundView As DrawingView
Dim dTexts As DrawingTexts
Dim currentText As DrawingText
Set backgroundView = currentDrawingSheet.Views.Item("Background View")
Set dTexts = backgroundView.Texts
On Error GoTo CreateNew
Set currentText = dTexts.GetItem("SheetNumber")
currentText.Text = sheetNumber
Exit Sub
CreateNew:
Set currentText = dTexts.Add(sheetNumber, xPos, yPos)
currentText.Name = "SheetNumber" 'so we can access it later for an update
End Sub