To Use Visual Studio to Display a Dialog

Get started with Visual Basic 2008

  1. Download and install Visual Basic 2008 Express from the Microsoft® web site if it is not already installed on your computer. The download is free.
  2. Open Visual Basic 2008 Express, and create a project of type Class Library.
  3. Name the project ClassLibrary1 (the default name), and click OK. Write the name on a piece of paper exactly as you have typed it. This name is important later in these instructions.

    A new window displays, with the Solution Explorer in the top right corner.

  4. In the Solution Explorer, right-click the project name and select Add, then select New Item from the submenu. The Add New Item dialog box displays.
  5. Select the Dialog template, and click Add.

    A graphical view of your dialog box displays in the Windows Form Designer. You can use this interface to add controls to your dialog box.

    The ToolBox on the left side of the screen lists the controls that you can add to the dialog box. For this project, you add a TextBox to show the value of an Inventor parameter and allow you to edit that parameter.

  6. Click and drag TextBox from the Common Controls group of the ToolBox panel to the dialog box, and place it in the gray area of the dialog box. You can resize the dialog box as required.
  7. Add a Label for the TextBox to show the parameter name.
  8. Being careful to avoid the Label and the TextBox, double-click the dialog box background to display the code editor. The following code displays.
  9. Move your cursor immediately below the line-
    Public Class Dialog1
  10. Add this line -
    Public d0 As Double
  11. Position your cursor at the top of subroutine OK_Button_Click, in front of the Me.DialogResult... statement, and press Enter to add a new line.
  12. On the new line, add -
    d0 = TextBox1.Text

    Your code looks like -

  13. Save your work using File Save or, alternatively, File Save All.

    You are almost ready to build the project. When you perform the build operation, Visual Basic creates a DLL file. You can specify where Visual Basic creates this file by modifying the output path for the build operation.

  14. Click the tab with the project title on it, and click the Compile tab again. The output path is -

    Program Files\Autodesk\Inventor {version}\Bin\iLogicAdd\

  15. To build the project, click the Build tab in the menu at the top. If the build proceeds without problems, the message Build succeeded displays in the status bar in the bottom left corner of the screen.
  16. Save your work again using Save All, and open Inventor.
  17. Use Add Rule to create a rule named Form Rule that consists of the following -.
    AddReference "ClassLibrary1"
    Sub Main()
    dim dlg as new ClassLibrary1.Dialog1
    dlg.d0 = d0
    i = dlg.ShowDialog()
    if (i = vbOK)then
    d0 = dlg.d0
    end if
    End Sub
    Note: You can also use Create Rule for a Dialog on the Wizards tab in the Edit Rule dialog box to create this code.

    This rule sends the current value of the Inventor parameter d0 to the dialog box, then shows the dialog box. The person using the dialog box can edit the value in the dialog. When this person clicks OK, the value from the dialog is assigned back to the parameter.

Create a Dialog for Displaying and Modifying Parameter Values

  1. Open Visual Studio.
  2. Create a project of type Class Library.
  3. In the Solution Explorer, right-click on the project name, and select Add New Item Dialog.

    A graphical view of your dialog box displays in the Windows Form Designer. You can use this interface to add controls to your dialog box.

  4. Click View Toolbox to preview the available controls.
  5. Add the TextBox control if you want the ability to display the value of an Inventor parameter and edit it. Add a Label for each Textbox to display the parameter name.
  6. Double-click the dialog box background.

    The code editor displays in a new subroutine named Dialog1_Load.

  7. In this subroutine, add this line before the end of the subroutine -
    TextBox1.Text = d0
  8. Move your cursor below the line -
    Public Class Dialog1
  9. Add this line -
    Public d0 As Double
  10. At the top of the subroutine named OK_Button_Click, add this line -
    d0 = TextBox1.Text

    Your code now looks like -

    Imports System.Windows.Forms
    Public Class Dialog1
    Public d0 As Double 
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click  
      d0 = TextBox1.Text
      Me.DialogResult = System.Windows.Forms.DialogResult.OK
      Me.Close()
    End Sub
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
      Me.DialogResult = System.Windows.Forms.DialogResult.Cancel  
      Me.Close()
    End Sub
    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       TextBox1.Text = d0
    End Sub
    End Class
  11. Build the project and save it using File Save All.

A DLL is created when the project is built. You can either:

The following sample rule uses the dialog box:

AddReference "ClassLibrary1"
Sub Main()
dim dlg as new ClassLibrary1.Dialog1
dlg.d0 = d0
i = dlg.ShowDialog()
if (i = vbOK) then
d0= dlg.d0
end if
End Sub

This rule sends the current value of the Inventor parameter d0 to the dialog box, and then shows the dialog box. The person using the dialog box can edit the value in the dialog box. If that person clicks OK, the value from the dialog box is assigned back to the parameter.

You can generate similar code for a dialog box automatically. On the Edit Rule dialog box, select the Wizards tab, and then select Create Rule for a Dialog.