我想得到一些VBA代码,它将告诉我在Catia绘图中的图纸数量。每张图纸上都会放置一个标题栏。每个标题栏上的文本字段将传达图纸数量。因此,如果图形中有三张图纸,则会有三张图纸中的一张(位于标题栏图纸1中)、2张(位于标题栏图纸2中)和3张图纸中的3张(位于标题栏图纸3中)。如果宏可以自动更新所有图纸上的所有标题栏。
任何帮助都非常感谢。
发布于 2015-10-15 23:00:04
其概念是遍历DrawingDocument
的Sheets
集合中的所有DrawingSheet
对象,您应该将所有标题栏元素放在“背景视图”中。接下来,我们需要更新或创建现有的标题栏文本元素。这些是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
https://stackoverflow.com/questions/33126624
复制相似问题