Problem with FTA (VBA)

Dominic Lavigne

Problem with FTA (VBA)
Hi guys, I'm fairly new at CATIA automation programming and I am having a bit of an issue here.
I'm trying to establish a link between annotations (FTA) and the geometry on which the annotation is attached. I found an an example in the documentation (title: Retrieving the Geometry Pointed to by an Annotation")

Unfortunately, I get a compile error when trying to run the following code:

Set annotation = annotations.Item(IdxAnnot)
SurfCount = annotation.GetSurfacesCount()
Dim enumValues () as Variant
ReDim enumValues (SurfCount - 1)
annotation.GetSurfaces(enumValues)
Dim Name As String

For i = LBound(enumValues) to UBound(enumValues)
    Name = enumValues(i) 
    msgBox Name
Next

The problem is the 'annotation.GetSurfaces(enumValues)'

Here is the error message I get (translated from french):
Function or interface referenced with restrictions or function using an Automation type not handled by Visual Basic.

The documentation doesn't say that the this function is deprecated or anything. Any help is welcome.

Thanks,
Dom

Mike Berry

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
I recently added a topic on my blog about this...

http://v5vb.wordpress.com/2010/07/29/restricted-interfaces/

-Mike

Dominic Lavigne

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
Thanks!
I managed to fix it by making it a CATScript instead of a VBA Program.
Even by declaring the array in which you put the surfaces as Variant it didn't work.

Mike Berry

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
I guess thats one way to fix it but the reason it didn't work in VBA is you need to declare your annotation variable as Object or as Variant. The way the array is declared isn't the problem. The restriction here is that you are not allowed to early bind an object (meaning declare the actual type - in your case it is the annotation variable) then call a method that takes an array as an argument...

-Mike

Dominic Lavigne

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
Yeah, that I know. However, even by declaring the Variable as Variant it still gives the error.

This exact code isn't working:
Set annotation = annotations.Item(IdxAnnot)
SurfCount = annotation.GetSurfacesCount()
Dim enumValues () as Variant
ReDim enumValues (SurfCount - 1)
annotation.GetSurfaces(enumValues)
Dim Name As String

For i = LBound(enumValues) to UBound(enumValues)
Name = enumValues(i)
msgBox Name
Next

Edit: my bad, I tought you meant the variable in which the array will be stored.

Dominic Lavigne

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
Allright,

One last thing.

in the for loop of the code above,
Name = enumValues(i)
works correctly as a CATScript (the variable Name is a non-null string after the loop)

However, the same code as VBA always return an empty string.

Any clue about what's going on?

Mike Berry

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
Try losing the parenthesis when you call the GetSurfaces method.

In VBA, you only use parenthesis when you are assigning a return value to a variable.

-Mike

Dominic Lavigne

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
It worked! Thanks a lot!
Posted By MBERRY on 14 Sep 2010 02:52 PM
Try losing the parenthesis when you call the GetSurfaces method.

In VBA, you only use parenthesis when you are assigning a return value to a variable.

-Mike


Cliff Johnson, Cliff

RE: Problem with FTA (VBA)
(in response to Dominic Lavigne)
Alternatively you can use the Call statement for subroutines and keep the parentheses in VBA.

Call GetSurfaces(enumValues)

It should work either way but I have seen one case where a VBA macro I wrote for a customer on my 32-bit laptop had an error when run on one of their 64-bit Catia workstations and changing the statement to use the Call syntax fixed it.