doshin
doshin

Reputation: 13

CATIA-VBA error: Function or interface marked restricted ... automation type not supported in Visual Basic

I've recorded a line creation in a VBA macro file, and it generated the following code:

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

Now The issue is that when i run the code as is after recording I get the following error:

Error in loading dll.

Than I add sketch1Variant object at line * and run the code again. This time I get the

"Function or interface marked restricted, or the function uses an automation type not supported in Visual Basic" error for line **.

I don't know what's wrong. Any info is highly appreciated. Thank you in advance.

Upvotes: 0

Views: 3042

Answers (1)

C R Johnson
C R Johnson

Reputation: 1101

The basic rule is this: When using VBA, any CATIA method which takes an array as an argument, or returns through an argument must be called on a variant object.

You have declared Sketch1Variant as Sketch. And SetAbsoluteAxisData takes an array as an argument.

What you want is this:

Dim Sketch1 as Sketch

Dim Sketch1Variant as Variant 

(or just leave the "as variant" part off).

With this change you should be able to get past your problem.

In the future please do a web search first, because this is a VERY common question. coe.org is a good site to search.

Upvotes: 2

Related Questions