如何使用 vba CATIA 创建翻译功能?

How to create a function for translate using vba CATIA?

我正在研究 vba CATIA,我正在尝试创建一个用于转换操作的函数。但是我在将函数的输出分配给对象时出错。

期待解决方案。

提前致谢!!

Function CreateTranslate(source As Object, value As Double, direction As Double)

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

If direction = 1 Then
        Set hybridShapeFactory1 = part1.HybridShapeFactory
        Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1#, 0#, 0#)

Else
    If direction = 2 Then
            Set hybridShapeFactory1 = part1.HybridShapeFactory
            Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0#, 1#, 0#)
        Else
            If direction = 3 Then
                Set hybridShapeFactory1 = part1.HybridShapeFactory
                Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0#, 0#, 1#)
              End If
      End If
End If


    Set CreateTranslate = hybridShapeFactory1.AddNewEmptyTranslate()

    Set reference1 = part1.CreateReferenceFromObject(source)
    CreateTranslate.ElemToTranslate = reference1

    CreateTranslate.direction = hybridShapeDirection1
    CreateTranslate.DistanceValue = value

End Function

调用函数:

 Set result_of_translate = hybridShapeFactory1.AddNewEmptyTranslate()
 result_of_translate = CreateTranslate(Kotfl, 0, 1)

为return对象创建函数时,必须使用Set语句将对象赋值给变量或属性。

Set result_of_translate = CreateTranslate(Kotfl, 0, 1)