首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Catia板材编号标题栏

Catia板材编号标题栏
EN

Stack Overflow用户
提问于 2015-10-14 21:25:47
回答 1查看 2.1K关注 0票数 0

我想得到一些VBA代码,它将告诉我在Catia绘图中的图纸数量。每张图纸上都会放置一个标题栏。每个标题栏上的文本字段将传达图纸数量。因此,如果图形中有三张图纸,则会有三张图纸中的一张(位于标题栏图纸1中)、2张(位于标题栏图纸2中)和3张图纸中的3张(位于标题栏图纸3中)。如果宏可以自动更新所有图纸上的所有标题栏。

任何帮助都非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2015-10-15 23:00:04

其概念是遍历DrawingDocumentSheets集合中的所有DrawingSheet对象,您应该将所有标题栏元素放在“背景视图”中。接下来,我们需要更新或创建现有的标题栏文本元素。这些是DrawingText对象。我们尝试通过名称访问DrawingText (该名称必须是唯一的!)。如果它不存在,我们就创建它。如果它确实存在,我们将更新值。

下面是制作标题栏的开始:

代码语言:javascript
运行
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33126624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档