Sami Piira
Georgios Eleftheriadis
Welcome SamizHC,
Try this
...................
Dim MySelection
Dim MyArray() As Face
Dim strReturn As String
'Initialization Section
'Initialize MyArray
Dimension
....................
Set
MySelection=CATIA.ActiveDocument.Selection
MySelection.Clear
strReturn=
MySelection.SelectElement2( Array("Face") , "Select a Face:",
False)
If strReturm="Normal" Then
ReDim
Preserve MyArray(Ubound(MyArray)+1)
Set
MyArray(Ubound(MyArray))=MySelection.Item2(1).Value
End If
....................
This is not a complete function/sub. It just shows the
concept/mechanism
I hope it helps.
-GEL
Steven Roemish
I can't figure out your "SelectElement2( Array("Face")" statement. Is it supposed to let the user select more than one surface?
I would have thought that the line would have read something like this:
strReturn= MySelection.SelectElement2("Face" , "Select a Face:", False)
What does "Array" do in your line statement?
Georgios Eleftheriadis
1. The line of code you mentioned is as shown in my post ie
strReturn= MySelection.SelectElement2( Array("Face") , "Select a Face:", False)
2. The first argument of the Selection2 method must be of CATIASafeArrayVariant ie an array(not a string). In this way the programmer allows to the user to select more than one type of CATIA objects (for examble "Point" or "Line", where in this case the code line shall be
strReturn= MySelection.SelectElement2( Array("Point", "Line") , "Select a Point or a Line:", False)
)
3. As mentioned in the post this is not a complete function/sub. If the programmer needs to make several selections or multil-selections then he has to Do...Loop or to use the SelectElement2, SelectElement2...etc
4. Array is a VBA function which returns a Variant containing an array. It is the way to array several elements without creating an array variable and so consuming computer resources.
Little Cthulhu
GEL is right, an array seems like a classic solution for you issue.
Although VBA provides another way to store items in a single container. It involves usage of Collection class.
To create container:
Dim MyCollection as New Collection
or
Dim MyCollection as Collection
Set MyCollection = New Collection
To store an item in container:
MyCollection.Add MyItem
To retrieve an item by it's index:
MyItem = MyCollection.Item(3)
To remove an item from container by it's index:
MyCollection.Remove 3
To count items in container:
INbItems = MyCollection.Count
In my opinion Collections are easier to use than arrays, and they are supported by CATscript as well.
Sami Piira
I'm bit embarrassed when I found out what the problem was.
My array was working perfectly all this time but I just wasn't using Selection in proper a way, once it was resolved everything worked like charm.
