The previous four sections of code can be combined into one single piece of code that can be executed as one program. Alternatively, if you have programmed each section individually, the four components can be executed using calls from a fifth program.
The following section of code is the complete combined tutorial:
Dim msApp As New Maxsurf.Application
Public Sub Tutorial()
Dim msDesign As Maxsurf.Design
Set msDesign = msApp.Design
'Creates a surface in Maxsurf
msDesign.Surfaces.Add msSLDefault
i = msDesign.Surfaces.Count
'This finds the number of surfaces in the design
msDesign.Surfaces(i).Visible = False
'Move all the control Points to form a vessel shape.
'All these dimensions are in metres,
'regardless the units set inside of Maxsurf
msDesign.Surfaces(i).SetControlPoint 1, 1, -10, 0, -2
msDesign.Surfaces(i).SetControlPoint 2, 1, -10, 3, -1.5
msDesign.Surfaces(i).SetControlPoint 3, 1, -8, 3, 2
msDesign.Surfaces(i).SetControlPoint 1, 2, 0, 0, -2.5
msDesign.Surfaces(i).SetControlPoint 2, 2, 0, 5, -2
msDesign.Surfaces(i).SetControlPoint 3, 2, 0, 5, 2
msDesign.Surfaces(i).SetControlPoint 1, 3, 7.5, 0, -2
msDesign.Surfaces(i).SetControlPoint 2, 3, 9.5, 0, -2
msDesign.Surfaces(i).SetControlPoint 3, 3, 10, 0, 3
'Create a Grid
'Create waterlines
msDesign.Grids.AddGridLine msGTWaterlines, WL1, -2, 0
msDesign.Grids.AddGridLine msGTWaterlines, WL2, -1, 0
msDesign.Grids.AddGridLine msGTWaterlines, WL3, 1, 0
msDesign.Grids.AddGridLine msGTWaterlines, WL4, 2, 0
'Create Section lines
msDesign.Grids.AddGridLine msGTSections, Sec1, -9, 0
msDesign.Grids.AddGridLine msGTSections, Sec2, -5, 0
msDesign.Grids.AddGridLine msGTSections, Sec3, -1, 0
msDesign.Grids.AddGridLine msGTSections, Sec4, 1, 0
msDesign.Grids.AddGridLine msGTSections, Sec5, 5, 0
msDesign.Grids.AddGridLine msGTSections, Sec6, 9, 0
'Create Buttock Lines
msDesign.Grids.AddGridLine msGTButtocklines, B0, 0, 0
msDesign.Grids.AddGridLine msGTButtocklines, B1, 1.5, 0
msDesign.Grids.AddGridLine msGTButtocklines, B2, 3, 0
'Get the Hydrostatics of the Hull
Dim Displacement As Long
Dim Draft As Long
Dim Beam As Long
msDesign.Hydrostatics.Calculate 1025, -2
Displacement = msDesign.Hydrostatics.Displacement
LWL = msDesign.Hydrostatics.LWL
Draft = msDesign.Hydrostatics.Draft
Beam = msDesign.Hydrostatics.BeamWL
MsgBox "The Displacement is " & Displacement & " tonnes"
MsgBox "The Draft is " & Draft & " m"
msDesign.Surfaces(i).Visible = True
'To update the screens in Maxsurf, use the refresh command
msApp.refresh
End Sub
The alternative to combining all of this code into one procedure is to use calls. The advantage of using calls is that multiple procedures can call on one procedure. For example, a procedure to determine the hydrostatics could be called by several other procedures, and hence only needs to be written once.
For this tutorial example, the procedure to call all the tutorial segments looks like;
Public Sub Tutorial_RunAll()
Call Tutorial_1
Call Tutorial_2
Call Tutorial_3
Call Tutorial_4
End Sub
This script so far has not shown anything particularly useful. The power of automation in Maxsurf comes from being able to manipulate and refine data through integration with other programs such as Microsoft Excel and AutoCAD. This tutorial has provided a basis of programming with the Maxsurf object model; subsequent chapters will look at more powerful uses of Maxsurf automation and integration of Maxsurf with other programs.
Office 97 cannot use enumerated types as
later office versions do. For more information, see the section VBA
on page 13
If you were using Office 97, the above script would need to be programmed using
a value of 2 instead of enumerated constant msGTWaterLines.
All the enumerated values are shown in Appendix A, Enumerated
Types