Access and change inventor parameters using vb.net

Access and change inventor parameters using vb.net

Anonymous
Not applicable
2,058 Views
5 Replies
Message 1 of 6

Access and change inventor parameters using vb.net

Anonymous
Not applicable

I am using vb.net code in visual studio to use a custom form to update the inventor model. I found code on the "mod the machine" site but it is not working for me. Here is what I have:

Dim _invApp As Inventor.Application

Dim oParameter As Inventor.Parameters = _invApp.ActiveDocument.ComponentDefinition.Parameters

 

Private Sub WheelSize_Leave(sender As Object, e As EventArgs) Handles WheelSize.Leave
Dim oWheelSize As Inventor.Parameter = oParameter.Item("Wheel_Size1")
oWheelSize.Expression = WheelSize.Text

 

I get the issues with the ComponentDefinition.Parameters as it is not recognizing that as anything meaningful. Does anyone know what the issue is?

0 Likes
2,059 Views
5 Replies
Replies (5)
Message 2 of 6

rjay75
Collaborator
Collaborator

Without seeing more of the code I'd say it's that you don't have a reference to the currently running Inventor Application. Do you ever set the variable _invApp anywhere. This needs to be set to the running Inventor Application first.

 

How are you running your code? What method are you using to start it?

0 Likes
Message 3 of 6

Anonymous
Not applicable

Here is the code that starts inventor:

 

 

Dim _started As Boolean = False

 

Public Sub InvOpen()

Try
_invApp = GetObject(, "Inventor.Application")
_invApp.Quit()
Dim invAppType As Type = _
GetTypeFromProgID("Inventor.Application")

_invApp = CreateObject("Inventor.Application")
_invApp.Visible = True
_started = True
Catch ex As Exception
Try
Dim invAppType As Type = _
GetTypeFromProgID("Inventor.Application")

_invApp = CreateObject("Inventor.Application")
_invApp.Visible = True


_started = True

Catch ex2 As Exception
MsgBox(ex2.ToString())
MsgBox("Unable to get or start Inventor")
End Try
End Try

End Sub

0 Likes
Message 4 of 6

rjay75
Collaborator
Collaborator

The _invApp is not set yet at this point:

 

Dim _invApp As Inventor.Application

Dim oParameter As Inventor.Parameters = _invApp.ActiveDocument.ComponentDefinition.Parameters

 

The variable _invApp is not set until the Sub InvOpen() is run. In your code you're closing and starting a new instance of Inventor. At that point there's no document open. You can't access the ActiveDocument or anything else til a document is open.

 

Just declare oParameter like you did _invApp at that point.

Dim oParameter As Inventor.Parameters

 

After Inventor is opened and a document is opened you can set oParameter.

0 Likes
Message 5 of 6

Anonymous
Not applicable

Okay, I think I understand what you are saying. I do have code that sets a project and opens a file. At this point i should be able to set oParameters. I will give it a try again but I think I tried it that way before. The interesting thing is the intellisense doesnt give give me componentdefinition as an option......

I will let you know how it goes when I get a chance.

0 Likes
Message 6 of 6

Anonymous
Not applicable

Sorry I didn't get back with you.... I did get it to work. I forget exactly what the key was but all this was very helpful. Thanks!

0 Likes