Vb.Net "Addin" exit Sub on Closing a Part Document

Vb.Net "Addin" exit Sub on Closing a Part Document

isocam
Collaborator Collaborator
662 Views
3 Replies
Message 1 of 4

Vb.Net "Addin" exit Sub on Closing a Part Document

isocam
Collaborator
Collaborator

Can anybody help????

 

I have the following "Sub" in a Vb.Net "Addin".....

 

       Private Sub m_applicationEvents_OnCloseDocument(DocumentObject As Inventor._Document, FullDocumentName As String, BeforeOrAfter As Inventor.EventTimingEnum, Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_applicationEvents.OnCloseDocument
            If BeforeOrAfter = EventTimingEnum.kBefore Then
                If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Or DocumentTypeEnum.kAssemblyDocumentObject Or DocumentTypeEnum.kDrawingDocumentObject Then
                    Try
                        Dim invVBAProject As InventorVBAProject = m_inventorApplication.VBAProjects.Item(1)
                        Dim invModule As InventorVBAComponent = invVBAProject.InventorVBAComponents.Item("Module04")
                        Dim invSub As InventorVBAMember = invModule.InventorVBAMembers.Item("OnClose")
                        invSub.Execute()

 

                        ' DO YOU WANT TO CLOSE THE PART YES/NO?

                        ' IF I SELECT "NO" - DO NOT CLOSE THE PART


                    Catch ex As Exception

                    End Try
                End If
            End If
        End Sub

 

All I want to do (For a test only!!!) is to add a MsgBox saying "Do you really want to close Part Yes/No"

 

Selecting "Yes" will work OK because there will be no change to the above code!

 

If I select "No" I want to exit the addin so that the current part does not close.

 

Does anybody know how I can do this?

 

Many thans in advance!

 

Darren

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

GeorgK
Advisor
Advisor

Hello Darren,

 


Select Case MsgBox("DO YOU WANT TO CLOSE THE PART?", vbQuestion or vbYesNo, "Title")
Case vbYes
    ' Yes

     'Your code
Case vbNo
    ' No

    'Your code
End Select

 

Georg

 

 

0 Likes
Message 3 of 4

EelcoWiggers
Enthusiast
Enthusiast

Hello Darren,

 

You can use this code:

If (MessageBox.Show("Question", "Caption", MessageBoxButtons.YesNo, _
       MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
    'Your Code if Yes
Else
    'Your Code if No
End If

 

Regards,

Eelco 

0 Likes
Message 4 of 4

ekinsb
Alumni
Alumni

If you want to stop the document from closing you can set the value of the HandlingCode argument to kEventCanceled within your OnCloseDocument handler.  That will abort the close.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes