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

如何通过VBA代码激活CATIA中已停用的MechanicalFeature?

批量激活CATIA中已停用特征的VBA实现

我需要批量激活CATIA里所有已停用的特征,思路是获取特征的Activity参数,将其从False改为True即可完成激活。以下是实现该功能的VBA代码:

Sub CATMain()

' 取消注释可开启错误忽略
' On Error Resume Next

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

If Err.Number = 0 Then
    Dim selection1 As Selection
    Set selection1 = partDocument1.Selection
    
    ' 搜索零件设计模块下所有停用的特征,取消注释即可使用
    ' selection1.Search "CATPrtSearch.PartDesignFeature.Activity=FALSE,all"
    ' 搜索机械特征模块下所有停用的特征
    selection1.Search "CATPrtSearch.MechanicalFeature.Activity=FALSE,all"

    If selection1.Count = 0 Then
        MsgBox "未找到已停用的特征"
        Exit Sub
 
    Else
        If MsgBox("共找到 " & selection1.Count & " 个已停用特征" & vbNewLine & "点击「是」激活,点击「否」退出。", vbYesNo) = vbYes Then
            
            For i = 1 To selection1.Count
                ' 直接调用Activate方法的写法(注释掉的备选方案)
                ' selection1.Item2(i).Activate
                ' 通过修改MechanicalFeature的Activity属性激活
                selection1.Item2(i).MechanicalFeature.Activity = True              
                ' 通过Value属性访问Activity的写法(注释掉的备选方案)
                ' selection1.Item2(i).Value.Activity = True
            Next 'i

            part1.Update

        End If

    End If

Else
    MsgBox "当前打开的不是零件文档!请打开单个零件文档后重试。"
End If

End Sub

代码说明

  • 首先判断当前激活的文档是否为零件文档,若不是则弹出提示
  • 使用Selection.Search语句批量筛选出所有停用的特征,可根据需要切换搜索PartDesignFeature(零件设计特征)或MechanicalFeature(机械特征)
  • 弹窗展示找到的停用特征数量,用户确认后遍历修改特征的Activity属性为True,最后更新零件完成激活

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:55:12