Inventor Add-in runs properly first time and need to exit and relaunch Inventor to run it again

Inventor Add-in runs properly first time and need to exit and relaunch Inventor to run it again

J_Dumont
Advocate Advocate
243 Views
3 Replies
Message 1 of 4

Inventor Add-in runs properly first time and need to exit and relaunch Inventor to run it again

J_Dumont
Advocate
Advocate

Hello,

 

I have an add-in that works very well but after I close the form I cannot run the program again. I need to close Inventor and relaunch. Is there a method to stop or end the program?

 

here is the code that closes the form.

 

 Private Sub BtnCancel_Click(sender As Object, e As EventArgs) Handles BtnCancel.Click
    If BtnCancel.Text = "Close" Then
      oForm.Dispose()
      Process.Start("explorer.exe", PDFFolderName)
    Else
      oForm.Dispose()
    End If
End Sub

0 Likes
244 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor
How is the form declared?
Please share the complete code.
Form.hide will maybe be better in this case. Let me figure out when I have the code.

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 4

J_Dumont
Advocate
Advocate

Hi Arthur,

Too much code to copy and paste but below shows how I define, load and close.

I hope this helps.

 

The form is declared in Module1

Module Module1
    Public oDocCount As String 'Get total occurance for use in Progress Bar
    Public designTrackPropSet As Inventor.PropertySet
    Public oForm As New BOMtoPDF

 

The form is displayed from commandfunstions.vb

Public Sub BOMtoPDFFunction()
    AppSettingsRead() 'Get configuration settings from app.config xml file
    oForm.ShowDialog()
    oForm.Visible = True

 

The form is closed in BOMtoPDF.vb

Private Sub BtnCancel_Click(sender As Object, e As EventArgs) Handles BtnCancel.Click
    If BtnCancel.Text = "Close" Then
    oForm.Dispose()
    Process.Start("explorer.exe", PDFFolderName)
    Else
    oForm.Dispose()
    End If
End Sub

 

 

0 Likes
Message 4 of 4

Michael.Navara
Advisor
Advisor

Don't use oFom.Dispose() in button click handler use oForm.Close() instead. Once you dispose the form, you need to create new instance of them. In this case you can't declare the form using  Public oForm As New BOMtoPDF

I don't know how you start the method Public Sub BOMtoPDFFunction(), but I recommend you to create new instance of form in this method. 

 

Method oForm.ShowDialog() display the form to the user and wait until user closes the form. Next call oForm.Visible = True is called to disposed form. In this case it has no effect or fail.

 

 Here is modified pseudo-code how to do it

Public Sub BOMtoPDFFunction()
    AppSettingsRead() 'Get configuration settings from app.config xml file

    Dim oForm = New BOMtoPDF
    If oForm.ShowDialog() = DialogResult.OK Then
        'Open PDF Folder
        Process.Start("explorer.exe", oForm.PDFFolderName)
    Else
        'Exit Sub or something
    End If
End Sub

Sub AppSettingsRead()
    'Get configuration settings from app.config xml file
End Sub

Class BOMtoPDF
    Inherits Form
    Private WithEvents BtnCancel As Button

    Public PDFFolderName As String

    Private Sub BtnCancel_Click(sender As Object, e As EventArgs) Handles BtnCancel.Click
        If BtnCancel.Text = "Close" Then
            DialogResult = DialogResult.OK
        Else
            DialogResult = DialogResult.Cancel
        End If
        Close()
    End Sub
End Class