Get started with Visual Basic 2008
- 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.
- Open Visual Basic 2008 Express, and create a project of type Class Library.
- 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.
- 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.
- 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.
- 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.
- Add a Label for the TextBox to show the parameter name.
- Being careful to avoid the Label and the TextBox, double-click the dialog box background to display the code editor. The following code displays.
- Move your cursor immediately below the line-
Public Class Dialog1
- Add this line -
Public d0 As Double
- 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.
- On the new line, add -
d0 = TextBox1.Text
Your code looks like -
- 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.
- 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\
- 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.
- Save your work again using Save All, and open Inventor.
- 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
- Open Visual Studio.
- Create a project of type Class Library.
- 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.
- Click View Toolbox to preview the available controls.
- 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.
- Double-click the dialog box background.
The code editor displays in a new subroutine named Dialog1_Load.
- In this subroutine, add this line before the end of the subroutine -
TextBox1.Text = d0
- Move your cursor below the line -
Public Class Dialog1
- Add this line -
Public d0 As Double
- 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
- Build the project and save it using File Save All.
A DLL is created when the project is built. You can either:
- Copy the DLL to the iLogicAdd directory, which is located under the Autodesk Inventor program bin directory (usually in C:\Program Files\Autodesk\Inventor {version}\Bin\iLogicAdd).
- Change the project settings to send the DLL to that directory automatically. Use the iLogic Configuration command to change the directory where iLogic looks for the DLL. See “Expanding iLogic capabilities” for more information on using DLL files in rules.
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.