CATIA-VBA错误:功能或接口标记为受限制... Visual Basic中不支持自动化类型

时间:2017-05-17 15:32:58

标签: vba catia

我在VBA宏文件中记录了一行创建,并生成了以下代码:

Sub CATMain()
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument
    Dim part1 As Part
    Set part1 = partDocument1.Part
    Dim bodies1 As Bodies
    Set bodies1 = part1.Bodies
    Dim body1 As Body
    Set body1 = bodies1.Item("PartBody")
    Dim sketches1 As Sketches
    Set sketches1 = body1.Sketches
    Dim originElements1 As OriginElements
    Set originElements1 = part1.OriginElements
    Dim reference1 As Reference
    Set reference1 = originElements1.PlaneYZ
    Dim sketch1, sketch1Variant As Sketch *
    Set sketch1 = sketches1.Add(reference1)
    Dim arrayOfVariantOfDouble1(8)
    arrayOfVariantOfDouble1(0) = 0#
    ...
    arrayOfVariantOfDouble1(8) = 1#
    Set sketch1Variant = sketch1
    sketch1Variant.SetAbsoluteAxisData **
    arrayOfVariantOfDouble1
    part1.InWorkObject = sketch1
    Dim factory2D1 As Factory2D
    Set factory2D1 = sketch1.OpenEdition()
    Dim geometricElements1 As GeometricElements
    Set geometricElements1 = sketch1.GeometricElements
    Dim axis2D1 As Axis2D
    Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
    Dim line2D1 As Line2D
    Set line2D1 = axis2D1.GetItem("HDirection")
    line2D1.ReportName = 1
    Dim line2D2 As Line2D
    Set line2D2 = axis2D1.GetItem("VDirection")
    line2D2.ReportName = 2
    Dim point2D1 As Point2D
    Set point2D1 = factory2D1.CreatePoint(21.285706, -30.501825)
    point2D1.ReportName = 3
    Dim point2D2 As Point2D
    Set point2D2 = factory2D1.CreatePoint(112.826553, -68.875053)
    point2D2.ReportName = 4
    Dim line2D3 As Line2D
    Set line2D3 = factory2D1.CreateLine(21.285706, -30.501825, 112.826553, -68.875053)
    line2D3.ReportName = 5
    line2D3.StartPoint = point2D1
    line2D3.EndPoint = point2D2
    sketch1.CloseEdition
    part1.InWorkObject = body1
    part1.Update
End Sub

现在 问题是当我在录制后按原样运行代码时出现以下错误:

  

加载DLL时出错。

比我在第*行添加sketch1Variant对象并再次运行代码。 这次我得到了

  

“标记为受限制的函数或接口,或者该函数使用Visual Basic中不支持的自动化类型”行**的错误。

我不知道出了什么问题。 任何信息都非常感谢。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

基本规则是这样的:当使用VBA时,必须在变量对象上调用任何以数组作为参数或通过参数返回的CATIA方法。

您已将Sketch1Variant声明为Sketch。 SetAbsoluteAxisData将数组作为参数。

你想要的是这个:

Dim Sketch1 as Sketch

Dim Sketch1Variant as Variant 

(或者只是将“as variant”部分关闭)。

通过此更改,您应该能够解决问题。

将来请先进行网络搜索,因为这是一个非常常见的问题。 coe.org是一个很好的搜索网站。