用于解锁Catia中的视图的宏不起作用

时间:2019-04-23 02:54:15

标签: vba catia

我正在尝试为Catia V5创建宏,该宏将自动解锁所有视图并更新它们。宏会更新所有视图(未锁定时)。 问题是它只能在运行宏之前解锁我当前在工作表上的视图,然后不会更新其他工作表上的其他视图。

因此,视图解锁仅在运行宏之前最后一次激活的工程图图纸上起作用。 但是,如果所有视图均已解锁并且运行宏,它将更新所有视图,但是由于某种原因,当我将其锁定时将其解锁将无法按上述方法进行操作。

Sub CATMain()

Dim oDrawing As DrawingRoot
Dim oViews As DrawingViews
Dim oSheets As DrawingSheets

Set oDrawing = CATIA.ActiveDocument.DrawingRoot
Set oSheets = oDrawing.Sheets
Set oViews = oDrawing.Sheets.ActiveSheet.Views

Dim i, y As Integer

For y = 1 To oSheets.Count
    oDrawing.Sheets.Item(y).Activate
    For i = 1 To oViews.Count
        oViews.Item(i).LockStatus = False
    oDrawing.Sheets.ActiveSheet.Update
    Next
Next

End Sub

我希望宏可以解锁所有视图,并在每张图纸上对其进行更新。

1 个答案:

答案 0 :(得分:2)

我没有使用Catia,但是您的代码应如下所示:

Sub CATMain()

    Dim oDrawing As DrawingRoot
    Dim oView As DrawingView
    Dim oSheet As DrawingSheet
    Set oDrawing = CATIA.ActiveDocument.DrawingRoot

    For Each oSheet in oDrawing.Sheets
       For Each oView in oSheet.Views
          oView.LockStatus = False
          oSheet.Update 'Not sure if required here, might be moved outside the loop?
       Next
    Next
End Sub