Best place to reference the Inventor api from vb.net

Best place to reference the Inventor api from vb.net

J_Dumont
Advocate Advocate
1,687 Views
8 Replies
Message 1 of 9

Best place to reference the Inventor api from vb.net

J_Dumont
Advocate
Advocate

I'm writing my first vb.net program for Inventor and I would appreciate any advice on placing my reference to the Inventor api.

For example, I created a form and I placed the code as shown below when the Form loads.

I also capture some properties and display one value in a label and another in a text box.

 

' Get the Inventor Application object.
Dim invApp As Inventor.Application
invApp = GetObject(, "Inventor.Application")

' Get the active document.
Dim odoc As Inventor.Document
odoc = invApp.ActiveDocument
Dim oDocName As String
oDocName = odoc.DisplayName

'Display the Assembly Name in Form
lblAssyName.Text = oDocName

' Get the "Design Tracking Properties" property set.
Dim designTrackPropSet As Inventor.PropertySet
designTrackPropSet = odoc.PropertySets.Item("Design Tracking Properties")

' Get the "Project" property from the property set.
Dim descAssyProject As Inventor.Property
descAssyProject = designTrackPropSet.Item("Project")

' Display Project Number on Form
TxtProjectNumber.Text = descAssyProject.Value

 

However, Visual Studio shows the variable is not declared in the following sub program.

 

Private Sub BtnOK_Click(sender As Object, e As EventArgs) Handles BtnOK.Click
If TxtProjectNumber.Text = "" Then
MsgBox("Assembly Project Number cannot be blank")
TxtProjectNumber.Focus()
Else
AssyProjectNumber = TxtProjectNumber.Text
' Set the value of the property using the current value of the text box.
descAssyProject.value = TxtProjectNumber.Text


End If

End Sub

 

 

0 Likes
1,688 Views
8 Replies
Replies (8)
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor

Hi.

Create a module main

Put your code in it and a

Dim f as forms

F.show

 

In your project start with the module main. Found in the properties.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 9

J_Dumont
Advocate
Advocate

Thank you for the quick response.

I'm having some issues with creating the Module.

I started my project using the Windows Forms Application.

Do I need to switch the Application type?

 

 

0 Likes
Message 4 of 9

J_Dumont
Advocate
Advocate

I forgot to mention that creating an add-in is my goal for this program.

I also need to add the libraries from PDFSharp that will help me process the pdf files I will be creating.

 

0 Likes
Message 5 of 9

J_Dumont
Advocate
Advocate

I'm testing the code to display a form and accept user input.

This code seems to briefly display the form.

How do I keep the form displayed to accept input?

 

 

Module Module1

Sub Main()
Dim oForm As FormXYZ
oForm = New FormXYZ()
oForm.Visible = True
oForm.Show()

 

End Sub

End Module

 

0 Likes
Message 6 of 9

_dscholtes_
Advocate
Advocate
However, Visual Studio shows the variable is not declared in the following sub program.

Private Sub BtnOK_Click(sender As Object, e As EventArgs) Handles BtnOK.Click
If TxtProjectNumber.Text = "" Then
MsgBox("Assembly Project Number cannot be blank")
TxtProjectNumber.Focus()
Else
AssyProjectNumber = TxtProjectNumber.Text
' Set the value of the property using the current value of the text box.
descAssyProject.value = TxtProjectNumber.Text

End If

End Sub

 

 

That's probably because you did not put dim AssyProjectNumber as String in your sub BtnOk_Click before assigning it a value (txtProjectNumber.Text)

Regarding your first attempt at a plugin, did you notice the top post check-out-the-self-paced-guide-my-first-plug-in? This plug-in contains a form and you can even download the code being discussed in each of the lessons.

0 Likes
Message 7 of 9

J_Dumont
Advocate
Advocate

Thank you for your advice. It really helped me move forward.

I found the issue that was halting my code.

I am working with vault and if the files were checked in the code was unable to update the properties. Once I checked the files out the Custom iProperties updated properly.

I first developed this code using iLogic and I was prompted to check the files out and the code updated files.

However, with VB.Net, this is not the case.

 

Below is an excerpt from Autodesk Knowledge Network.

Inventor 2018 and later no longer allow write-protected files, such as content center parts, to be modified by the API or iLogic rules to maintain consistency with the UI behavior.

 

Here's a URL for the workaround.

 

https://knowledge.autodesk.com/support/inventor/troubleshooting/caas/sfdcarticles/sfdcarticles/iLogi...

 

 

 

 

0 Likes
Message 8 of 9

dgreatice
Collaborator
Collaborator

Hi, did you know about this lessons?

 

Inventor Addin (Plug-In) and Windows application is difference method. 

https://knowledge.autodesk.com/search-result/caas/simplecontent/content/my-first-inventor-plug-overv...

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 9 of 9

J_Dumont
Advocate
Advocate

Thank you for the URL. I have not seen this before. I have gone through other tutorials but I look forward to studying these lessons.

 

 

0 Likes