Infrastructure |
About CATSafeArrayVariant |
Many methods which return a value do not return a single value, but an array of values. For example, the GetOrigin property of the Viewpoint3D object returns a 3D point as an array of three coordinates. This array is returned as an output argument.
Such arguments are visible in the VB/VBA object browser as a variant but the reference documentation lists them as CATSafeArrayVariant.
You can retrieve in the MyVPOrigin variable the origin of the 3D viewpoint of the active viewer in the active window as follows:
ReDim MyVPOrigin(2) CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.GetOrigin MyVPOrigin
You should directly use the ReDim statement to assign a size to the array while declaring it as a variable size array, and then call the GetOrigin method. Assigning a size of 2 allocates an array containing three values.
To access each coordinate, you need to go deeper:
Contrary to collections, a CATSafeArrayVariant's index begins at 0. To set a new triplet of values, you can write:
MyVPOrigin = Array(150, 200, 50) CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.PutOrigin MyVPOrigin
or
CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.PutOrigin Array(150, 200, 50)
But to modify the y coordinate only, write:
MyVPOrigin(1) = 200CATIA.ActiveWindow.ActiveViewer.Viewpoint3D.PutOrigin MyVPOrigin
When you don't know the size of an array, use the UBound function. It returns the rank of the highest element in the array. For example the following example returns 2 in Highestrank:
Highestrank = Ubound(MyVPOrigin)
[Top]
Copyright © 1994-2004, Dassault Systèmes. All rights reserved.