Show form once, without MDI

Valued Contributor
Valued Contributor

Hi there,

For a small addin i'm trying to show a simple form if a part (or sheet metal) is saved without a material.

 

I use the following code in the 'MyRibbon.vb'

Private Sub seEvents_BeforeDocumentSave(ByVal theDocument As Object) Handles seEvents.BeforeDocumentSave 

Dim objOpendoc As Object
        objOpendoc = SE.ActiveDocument
        SE.StatusBar = objOpendoc.fullname
        Dim SecondForm As New MaterialSelection

        Select Case SE.ActiveDocumentType
            Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument
                If CheckMaterial() <> True Then
                    If SecondForm Is Nothing OrElse SecondForm.IsDisposed Then
                        SecondForm = New MaterialSelection()
                    End If
                    SecondForm.Height = 427
                    SecondForm.Width = 517
                    SecondForm.Show()
                    GoTo endfunction
                End If
	Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument

etc.

 It works, but when you save at least 3 forms appear!

How can I prevent multiple forms from opening?

 

 

Maarten Elings | Mechanical Engineer
3 REPLIES

Re: Show form once, without MDI

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Depending on the scenario, a single GUI save can invoke multiple BeforeDocumentSave events. If you're wanting to catch the save for a specific document (i.e. the active document), you will need to check that the theDocument parameter that is passed in equals the Application.ActiveDocument.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Show form once, without MDI

Valued Contributor
Valued Contributor

Thank you for your reply,

But what causes SE to invoke multiple save events? Sometimes it runs the command once, sometimes 5 times. it seems so random.

 

I have edited the code as follows;

it should trigger if the objOpendoc is not nothing, and it seems to work.

I'm not sure however it will work 100/100 times.

 

Private Sub seEvents_BeforeDocumentSave(ByVal theDocument As Object) Handles seEvents.BeforeDocumentSave 

        Dim objOpendoc As Object = SE.ActiveDocument
        If Not (objOpendoc Is Nothing) Then '<<< this is new

        Dim SecondForm As New MaterialSelection

        Select Case SE.ActiveDocumentType
            Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument
                If CheckMaterial() <> True Then
                    If SecondForm Is Nothing OrElse SecondForm.IsDisposed Then
                        SecondForm = New MaterialSelection()
                    End If
                    SecondForm.Height = 427
                    SecondForm.Width = 517
                    SecondForm.Show()
                    GoTo endfunction
                End If
	Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument

 

Maarten Elings | Mechanical Engineer

Re: Show form once, without MDI

Valued Contributor
Valued Contributor

Thanks again for your reply, it works like a charm!

 

Private Sub seEvents_BeforeDocumentSave(ByVal theDocument As Object) Handles seEvents.BeforeDocumentSave 

        Dim objOpendoc As Object = SE.ActiveDocument
        If theDocument = objOpendoc Then 'check if the save is being executed by the current document, if so... continue

        Dim SecondForm As New MaterialSelection

        Select Case SE.ActiveDocumentType
            Case SolidEdgeFramework.DocumentTypeConstants.igPartDocument
                If CheckMaterial() <> True Then
                    If SecondForm Is Nothing OrElse SecondForm.IsDisposed Then
                        SecondForm = New MaterialSelection()
                    End If
                    SecondForm.Height = 427
                    SecondForm.Width = 517
                    SecondForm.Show()
                    GoTo endfunction
                End If
	Case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument

 

Regards,

 

Maarten

Maarten Elings | Mechanical Engineer