C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

マクロで干渉レポートを作成する

こちらのコメントに記載した、マクロで干渉レポートを作成するサンプルを
作成しました。
クリックした面に法線を作成する - C#ATIA


コードはこちら。

'vba sample_ClashReport_ver0.01  using-'ver0.0.10'
'指定した2つのプロダクトの干渉チェックをします

Option Explicit

Sub CATMain()
    'ドキュメントのチェック
    If Not CanExecute("ProductDocument") Then Exit Sub
    
    'トッププロダクト取得
    Dim TopProd As Product: Set TopProd = CATIA.ActiveDocument.Product
    Dim Path As String: Path = TopProd.Parent.Path
    If Path = vbNullString Then
        MsgBox "トッププロダクトは、一度保存されたファイルにして下さい!"
        Exit Sub
    End If
    
    '選択
    Dim Msg As String: Msg = "個目のプロダクトを選択してください"
    Dim Prod1 As Product: Set Prod1 = KCL.SelectItem("1" & Msg, "Product")
    If KCL.IsNothing(Prod1) Then Exit Sub
    
    Dim Prod2 As Product: Set Prod2 = KCL.SelectItem("2" & Msg, "Product")
    If KCL.IsNothing(Prod2) Then Exit Sub
    
    '選択チェック
    If Prod1 Is Prod2 Then
        MsgBox "同一プロダクトの干渉チェックは出来ません!"
        Exit Sub
    End If
    
    '干渉チェック
    Dim Grps As Groups: Set Grps = TopProd.GetTechnologicalObject("Groups")
    Dim Grp1 As Group: Set Grp1 = Grps.Add
    Call Grp1.AddExplicit(Prod1)
    Dim Grp2 As Group: Set Grp2 = Grps.Add
    Call Grp2.AddExplicit(Prod2)
    
    Dim Clashes As Clashes: Set Clashes = TopProd.GetTechnologicalObject("Clashes")
    Dim Clash As Clash: Set Clash = Clashes.Add
    
    With Clash
        .Clearance = 0.1
        .ComputationType = catClashComputationTypeBetweenTwo
        .InterferenceType = catClashInterferenceTypeClearance
        .FirstGroup = Grp1
        .SecondGroup = Grp2
        .Compute
    End With
    
    '干渉結果
    If Clash.Conflicts.Count > 0 Then
        Dim CRPath As String: CRPath = Path & "\ClashReport\ClashReport"
        Call Clash.Export(CatClashExportTypeXMLResultOnly, CRPath)
        CreateObject("Shell.Application").ShellExecute CRPath & ".xml"
        
        SendKeys "{ESC}", False 'この行が無いと、マクロ実行後のCATIAの挙動が怪しい
    Else
        MsgBox "干渉はありません"
    End If
End Sub

レポートファイルを作成する都合上、トップのプロダクトは一度保存されている
必要があります。

実行した際は、このような感じになります。

干渉チェックする際の条件等は、コードを修正する必要があります。