首页 文章

从CATIA V5中的.catpart中提取测量值

提问于
浏览
1

我有.CATPART和我手动完成了测量 . 我想使用CAT VBA创建宏并从.CATPART中提取测量值并将其导出到excel .

3 回答

  • 0

    想象一下最简单的情况:

    Sub CATMain()
    
    ''Get ActiveDocument
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument
    
    ''Get Part
    Dim part1 As Part
    Set part1 = partDocument1.Part
    
    ''Get list of parameter of part
    Dim oParams As Parameters
    Set oParams = part1.Parameters
    
    Dim PatternFind As String
    PatternFind = "Measure"
    
    ''MsgBox all values of the parameter that contains 'Measure'
    For Each item In oParams
        If InStr(item.Name, PatternFind) <> 0 Then
            MsgBox (item.Name & " = " & item.value)
        End If
    Next
    
    End Sub
    

    [树视图]

    • 第1部分

    • 措施

    • MeasureEdge.1

    • 长度= 10毫米

    • MeasureEdge.2

    • 长度= 100毫米

    您应该进行必要的修改以导出到Excel .

  • 0

    抱歉,存储在零件或产品中的度量不会在API中公开 .

  • 0

    我从来没有找到解决方案,但这里有一个代码,可以从用户选择中获取测量结果 . 您无法解析所有测量值,但您可以选择它们并解析选择(此示例仅适用于所选的一个测量,如果可能,您必须适应许多测量):

    Set oSelection = CATIA.ActiveDocument.Selection
    On Error Resume Next
    sName = oSelection.Item2(1).Value.Name
    On Error Goto 0
    'selection should be named with "catiabase"
    If InStr(LCase(sName), "catiabase") = 0 Then Exit Function
    'Get Name
    'PROBLEM: This search will empty the selection if no measurement is selected
    oSelection.Search "Name=Length,sel"
    'No Length, no measurement (here i need only 1 selection)
    If oSelection.Count2 <> 1 Then Exit Function
    
    'Get name of measurement
    sName = oSelection.Item2(1).Value.Name 'not the same as previous!
    

    You can also find here a method to get distance value between two parts,但它需要知道你想要距离的部分

相关问题