The list objects have one property that is common to all list objects. The Count property of a list object returns the number of items in the list.
i = mList.Count
j = sList.Count
Lists have some of their own properties that will store data for all the items in the list. Lists can also be used to access all the properties of their respective objects through the item method. Properties of the lists themselves do not return a single value but a variant containing an array of values, each array entry corresponding to the value of the property for each item within the list.
For example, the SurfaceList object has the Name property describing the name of each of the surfaces in the list. The following code will display the name of the first surface in the collection;
MsgBox sList.Name(1)
Alternatively, we could store the names of all the surfaces into a variant array, then display one of those names, using this section of code.
sName = sList.Name
'This stores all the surface names in a variant called sName
MsgBox sName(1)
In one call to Maxsurf, this second method has retrieved the names of all the surfaces, and stored them into an array for further use. Using this method can significantly increase the speed of the script, especially when you are using more than one piece of data (one name) or using the same data more than once.
List data is read/write in the same way as collection data. Data can either be set individually to a specific new value, using a For Next statement, or can all be set to one value. Both are demonstrated in the following code segment. The code appends the surface name for all surfaces in the list with a number, according to the surfaces position in the list. The code then changes all the surface types to be developable surfaces (type 3)
Sub ChangesUsingLists()
Dim msDesign As Maxsurf.Design
Set msDesign = msApp.Design
Dim sList As New Maxsurf.SurfaceList
Dim sName As Variant
sList.Add msDesign.Surfaces
sName = sList.Name
For i = 1 To UBound(sName)
sName(i) = sName(i) & " " & i
'MsgBox sName(i)
Next
sList.Name = sName
'Set all surfaces to Developable
sList.Type = 3
msApp.Refresh
End Sub
This script executes much faster than one that loops over each surface in the design and sets each attribute separately, as it significantly reduces the number of subroutine calls made between Maxsurf and the host application. This script requires only three (3) inter-application calls to retrieve and set the data for the surfaces. When compared to the two (2) calls per surface required when looping over the individual surfaces in the design, the savings in time are significant.