You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助提取CAT Drawing中按视图生成的线条类Generated Item

提取CAT Drawing视图中线条类Generated Item的解决方案

核心思路

当手动「Drafting Generated Item选择功能」失效时,通过VBA宏遍历图纸视图、精准筛选线条类Generated Item是最可靠的替代方案,以下是具体实现步骤:

步骤1:明确目标对象类型

CAT Drawing中属于线条类的Generated Item对应以下核心对象:

  • Line2D(直线)
  • Polyline2D(折线)
  • Circle2D(圆形线条,若归为Generated Item范畴)
  • Ellipse2D(椭圆形线条,若归为Generated Item范畴)

步骤2:运行VBA宏提取

打开CATIA并加载目标工程图,按以下操作执行宏:

  1. 按下Alt + F8打开宏管理器
  2. 点击「新建」,在VBA编辑器中粘贴以下代码:
Sub ExtractLineGeneratedItems()
    Dim oDrawingDoc As DrawingDocument
    Dim oSheet As DrawingSheet
    Dim oView As DrawingView
    Dim oElement As DrawingElement
    Dim oGeneratedElem As DraftingGeneratedElement
    
    Set oDrawingDoc = CATIA.ActiveDocument
    
    '遍历所有图纸页
    For Each oSheet In oDrawingDoc.Sheets
        '遍历当前图纸页的所有视图
        For Each oView In oSheet.Views
            '遍历视图内的所有元素
            For Each oElement In oView.DrawingElements
                '判断是否为Generated Item且属于线条类
                If TypeOf oElement Is DraftingGeneratedElement Then
                    Set oGeneratedElem = oElement
                    Select Case oGeneratedElem.GeometricElement2D.Type
                        Case catLine2D, catPolyline2D, catCircle2D, catEllipse2D
                            '标记为红色并选中元素,便于识别
                            oGeneratedElem.VisProperties.SetRealColor 255, 0, 0, 0
                            oGeneratedElem.Select
                    End Select
                End If
            Next oElement
        Next oView
    Next oSheet
    
    MsgBox "线条类Generated Item提取完成,已标记为红色并选中", vbInformation
End Sub
  1. 保存宏后点击「运行」,宏会自动遍历所有视图,将符合条件的元素标记为红色并选中。

自定义调整说明

  • 若需导出元素信息(如名称、坐标),可在Case分支内添加写入文本文件的代码
  • 可修改Select Case中的对象类型,仅保留需要的线条类型
  • 若仅需处理特定视图,可添加视图名称判断逻辑(如If oView.Name = "主视图" Then ...)

内容的提问来源于stack exchange,提问作者Dinesh gowd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 06:45:50