- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey,
I'm creating a form in VB.net that controls parameters in an Inventor 3D model. Here is the sub routine I am using to pass the parameters:
Public Sub ChangeParameter(paramName As String, setValue As Double)
'Make Sure Inventor is Running
CheckInventor()
Try
'set the flag to false
Dim paramFound As Boolean = False
Dim oParameter As Parameter = Nothing
Dim oParameters As Inventor.Parameters = oInventorApp.ActiveDocument.ComponentDefinition.Parameters
'loop through all of the parameters
For Each oParameter In oParameters
If UCase(paramName) = UCase(oParameter.Name) Then
'set the flag
paramFound = True
'change the parameter and make sure it is specified in inches
oParameter.Expression = System.Convert.ToString(setValue) & " in"
'update the drawing
oInventorApp.ActiveDocument.Update()
'since the parameter was found, exit the loop
Exit For
End If
Next
'alert the user if the specified parameter was not found
If paramFound = False Then
Beep()
MsgBox("Parameter name: " & paramName & " was not found.", vbOKOnly, "Parameter not found")
End If
Catch ex As Exception
'alert the user if there is a problem
MsgBox(ex.Message & -"Error: ChangeParameter")
End Try
End Sub
I am accessing the sub-routine from the form using the following:
Private Sub cboChmbrSzChmbr_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboChmbrSzChmbr.SelectedIndexChanged
'Update Chamber Size in Inventor
CheckInventor()
ChangeParameter("SHELL_PIPE_SIZE", cboChmbrSzChmbr.SelectedItem)
End Sub
Here is the sub used to check if Inventor is open:
Public Sub CheckInventor()
oInventorApp = GetObject(, "Inventor.Application")
If Err.Number Then
MsgBox("Inventor must be running.")
End
End If
If oInventorApp.Documents.Count = 0 Then
MsgBox("An assembly document must be active.")
End
End If
'if you get to this point, then make the active document the
'oassemblyDocument
oAssemblyDocument = oInventorApp.ActiveDocument
However, I get the following error when I run the program & select an item from the cboChmbrSzChmbr combobox:
Can anyone help me out with this?
Solved! Go to Solution.