VB.Net Addin - Get reference to open form

VB.Net Addin - Get reference to open form

TA.Fehr
Advocate Advocate
1,487 Views
8 Replies
Message 1 of 9

VB.Net Addin - Get reference to open form

TA.Fehr
Advocate
Advocate

Hopefully this is a simple one that I'm just missing.

I've created an exe program that I would like to incorporate in an add-in. I've published the exe to a dll, included it in my add-in reference, declared the dll and called the main form but here's where I run into issues.
If I declare the dll form as a global the add-in unloads automatically. I've tried a few other options but with no success.

In this case, the sub runs fine and "Success" is displayedIn this case, the sub runs fine and "Success" is displayedIn this case the sub will not runIn this case the sub will not runIn this case "Success" is displayed and then errors outIn this case "Success" is displayed and then errors out

0 Likes
Accepted solutions (1)
1,488 Views
8 Replies
Replies (8)
Message 2 of 9

JamieVJohnson2
Collaborator
Collaborator

Show dialog takes the focus away until the object is closed.  Perhaps use just Show command.  That opens the window, and leave the focus on the other thread alone.  So think about this, show dialog in the first example, would prevent the message box from ever running, until you close the window.  Show dialog in the last example would cause an error if the main thread, aka Inventor, refuses to let something else take away its focus (for AutoCAD, you have to lock the document before you can do that).

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 3 of 9

TA.Fehr
Advocate
Advocate

Thanks for the suggestion, however I was unable to get it to work.

I'm thinking that it has to do specifically with the .dll file. I do not need to have a show declaration for the error to trip.

Capture2.PNG

I may need to look elsewhere, but all I did for the dll was to change my exe over to a class library, resolve the errors and build. All the articles online seem to suggest this is the proper way so I'm really not sure what I'm doing wrong.

0 Likes
Message 4 of 9

JamieVJohnson2
Collaborator
Collaborator

One question to raise, could be this:  If you can not load the type Main, is it possible that it (your dll) is using a different .Net version than the version of Inventor you are using?  Inventor 2019 uses .Net 4.7.  (much older versions use .Net 4.6.2)

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 5 of 9

TA.Fehr
Advocate
Advocate

This doesn't seem to be the issue either. The dll is built on 4.0 framework, and the add-in is built with 4.5.2 and I have run both of them independently with Inventor 2019. I updated both to 4.7.2 but the issue is still with the loading of the .dll.

The generic description is that the file or one of its dependencies could not be located. Is there anywhere else to put the dll except to import via the references 

Capture.PNG

0 Likes
Message 6 of 9

bradeneuropeArthur
Mentor
Mentor

Hi,

 

This is the way to open a form in the add in.

Dim NewFrm as YourFormName = new YourFormName()

NewFrm.show
' or
NewFrm.showdialog

'.......
' and in your form define this
Public Sub New() InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
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 !

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

Message 7 of 9

TA.Fehr
Advocate
Advocate

That was my understanding and I have implemented the code as you stated, but this doesn't resolve the issue.

I thought it might have something to do with another dll referenced by the called dll so I added every reference in the called dll but this doesn't change the fact that the error reports it cannot locate the dll that is in the resources folder.

 

I've found a few other solutions suggesting changing the build to x86, but one build requries x64. I've also tried clearing the referenced dll's and reloading them but nothing is working.

 

I'm sure the solution is very simple, and the longer I work on this, the more incompetent I begin to feel.

0 Likes
Message 8 of 9

GeorgK
Advisor
Advisor
Dim MyLocalForm As New Your_Form_to_open
'MyLocalForm.Show() 'Form not bind to Inventor
MyLocalForm.Show(New WindowWrapper(m_inventorApplication.MainFrameHWND)) 'Form bind to Inventor
0 Likes
Message 9 of 9

TA.Fehr
Advocate
Advocate
Accepted solution

OK, I have solved the issue.

Just for testing purposes I made a small class that displayed a messagebox. I tested importing this class into another small project that displayed a form with a button linking to the dll of the first class. I confirmed that this functioned as expected.

When I added the test dll to the Inventor add-in, the same error occurred, which told me it wasn't with the dll but rather with the add-in. I had built the add-in from another working add-in I had made last year, and although it tested out, I started from scratch using Brian Ekins template found here.

Once the template had successfully loaded, I added my dll to the resources, defined the main form and everything worked as expected.

 

So I'm not sure what in the add-in was causing the error.

Thanks so much for the pointers @bradeneuropeArthur  and @JamieVJohnson2 

0 Likes