Opening and Closing a Design

The following section of code contains three separate procedures, the first two are different methods of opening a design from a file and the final procedure closes the design.

 

The difference between the first two procedures is in how they open the design. The first procedure has the name of the file to be opened written into the code. This will open the same specified file every time.

 

The second procedure opens a dialog box in Excel, allowing the user to select the file they wish to open. Which procedure is most suitable depends on the situation.

 

Dim msApp As New Maxsurf.Application

 

Sub OpenFile()

    'Opens the named File

   

    Dim FileName As String

        'Creates a Variable for the File name

   

    FileName = "C:\Program Files\Maxsurf\Sample Designs\Workboats\Trawler_1Surface.msd"

        'Defines the FileName Variable. Changing this

        'will change the file that is loaded

    msApp.Design.Open FileName, False, False

 

End Sub

_                                                            _

 

Sub OpenFileDialog()

    'Opens a file selected in the Dialog Box

    Dim Filter As String

    Dim FileName As String

   

    Filter = "Maxsurf Design File (*.msd), *msd"

    'The Filter only allows certain file types to be loaded

    FileName = Application.GetOpenFilename(Filter, , "Open Maxsurf File", , False)

   

    msApp.Design.Open FileName, False, False

   

End Sub

_                                                            _

 

Sub CloseDesign()

    msApp.Design.Close False

 

End Sub

 

The two Maxsurf Objects being used in the script are

msApp.Design.Open FileName, False, False

and

msApp.Design.Close False

 

The options available when opening a file are to specify the filename (as a String), whether you would like to merge the new design with the current design (Boolean) and whether you would like to save the current design (Boolean).

 

The close method provides an option to save the file before closing (Boolean)