【问题标题】:How to get Body Color in CATIA VBA macro?如何在 CATIA VBA 宏中获取体色?
【发布时间】:2015-12-03 16:47:23
【问题描述】:

是否可以读取 CATBody 的颜色?比如:

   For Each myBody In myPart.Bodies
             myColor = myBody.Color 
    Next

【问题讨论】:

    标签: vba catia


    【解决方案1】:

    是的,这是可能的,但并不完全直截了当。颜色可通过VisPropertiesSelection 获得。此外,这是 Catia API 的一种奇怪情况,您需要使用后期绑定(我无法告诉您原因)

    这是一个例子:

    Option Explicit
    Sub BodyColors()
    
    Dim sel As Selection
    Dim selected As SelectedElement
    Dim vis As Variant 'VisPropertySet 'This must be variant for late binding. Otherwise you get an error.
    Dim RGB(3) As Long 'or you can use an array
    Dim r, g, b As Long
    
    
    Dim myPart As Part
    Dim myBody As Body
    
    Set myPart = CATIA.ActiveDocument.Part
    Set sel = CATIA.ActiveDocument.Selection
    For Each myBody In myPart.Bodies
        sel.Clear
        sel.Add myBody
        Set vis = sel.VisProperties
        vis.GetRealColor r, g, b 'you must pass the values into the function
        Debug.Print myBody.Name & ": "; r & "," & g & "," & b
    Next
    sel.clear
    End Sub
    

    【讨论】:

    • 早期绑定出现这些问题的原因是,r、g、b 尺寸错误,Dim r、g、b As Long 表示,r 和 g 是变体,只是 b 是 Long,由于 .GetRealColor 函数需要 long,它不允许您将变量作为参数传递,因此,如果您将 rgb 定义为 Dim r As Long、g As Long、b As Long,您也可以使用早期绑定,并避免也先设置 vis。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多