Example: Opening a Dialog Box from a Menu

In this example, we will create a menu command to export object properties to an XML file via a dialog box.

  1. Create a new extension file (see Creating an Extension File) in a PDM and add the Table metaclass (see Metaclasses (Profile)).
  2. Right-click the Table metaclass and select New > Form. Enter Export in the Name field, and select Dialog Box from the Type list.
  3. Click the Edit Field tool to add an edit field control, and call it Filename.
  4. Right-click the Table metaclass and select New > Method. Enter Export in the Name field, click the Method Script tab and enter the following code:
    Sub %Method%(obj)
    ' Exports an object to a file
    ' Create a dialog to input the export file name
    Dim dlg
    Set dlg = obj.CreateCustomDialog("%CurrentTargetCode%.Export")
        If not dlg is Nothing Then
        ' Initialize filename control value
        dlg.SetValue "Filename", "c:\temp\MyFile.xml"
      
        ' Show dialog
        If dlg.ShowDialog() Then
            ' Retrieve customer value for filename control
            Dim filename
            filename = dlg.GetValue("Filename")
       
            ' Process the export algorithm...
            ' (Actual export code not included in this example)
    
            Output "Exporting object " + obj.Name + " to file " + filename
        End If
      
        ' Free dialog object
        dlg.Delete
        Set dlg = Nothing
    End If
    End Sub
  5. Right-click the Table metaclass and select New > Menu. Enter Export in the Name field, and then click the Add Command tool and select the Export method:

  6. Click OK to save your changes and return to your model. When you next right-click a table in a diagram or the browser, the Export command is available in the contextual menu.