Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

VB.Net OnSave event change background color

Majjek
Advocate

VB.Net OnSave event change background color

Majjek
Advocate
Advocate

Hi all,

 

I'm busy with an add-in in VB.Net which, among other things, can change the background color during save to white.

Therefore I change the colorscheme briefly to presentation and then change it back afterwards.

This works for parts, but when saving assemblies with modified children, it doesn't work.

When I do these steps manually it works, but when automating, it seems like it doesn't really finish the switching of the colorschemes or something.

I've created a workaround to open a view for each part and then saving, but this takes some extra time, especially on larger assemblies.

 

Is there anyone who ran in to the same problem and has a fix?

 

Thanks in advance

0 Likes
Reply
568 Views
4 Replies
Replies (4)

bradeneuropeArthur
Mentor
Mentor

could you upload your 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 !

0 Likes

Majjek
Advocate
Advocate

Hereby the event code.

You can see a part that checks if it's a child document to be saved.

If so, then it get's added to a collection to be processed later on.

All files will get saved in the first run.

After the first run, all files from the collection will be opened and saved again.

To trigger the save again, a temporary change is done.

 

Private Sub m_ApplicationEvents_OnSaveDocument(ByVal DocumentObject As Inventor._Document,
                                                       ByVal BeforeOrAfter As Inventor.EventTimingEnum,
                                                       ByVal Context As Inventor.NameValueMap,
                                                       ByRef HandlingCode As Inventor.HandlingCodeEnum)
            Dim SaveDoc As Document
            Dim sDesigner As String


            If My.Settings.OnSaveWhiteBackground = True Then
                If BeforeOrAfter = EventTimingEnum.kBefore Then     'Check if it's before the actual save command.
                    Debug.Print("Run before save " & DocumentObject.FullFileName)

                    If Context.Item(1) = Context.Item(2) Or Context.Item(2) = "" Then
                        Call ChangeBackground(ColorSchemeOptions.PresentationColorscheme)
                        g_inventorApplication.ScreenUpdating = False

                    Else
                        TempDoc = g_inventorApplication.Documents.ItemByName(Context.Item(1))

                        Debug.Print("    Add Doc to list" & TempDoc.FullDocumentName)

                        SavedDocs.Add(TempDoc)
                        TempDoc = Nothing
                    End If
                End If

                If BeforeOrAfter = EventTimingEnum.kAfter Then      'Check if it's after the actual save command.
                    Debug.Print("Run after save " & DocumentObject.FullFileName)

                    If Context.Item(1) = Context.Item(2) Or Context.Item(2) = "" Then
                        Debug.Print("Er zijn " & SavedDocs.Count & " documenten over.")

                        Try
                            For Each SaveDoc In SavedDocs
                                If SaveDoc.Views.Count = 0 Then
                                    SaveDoc.Views.Add()
                                End If

                                'Temporarily change an iProperty to trigger a save, otherwise it won't be saved and go to kAbort.
                                sDesigner = SaveDoc.PropertySets.Item("Inventor Summary Information").Item("Author").Value
                                SaveDoc.PropertySets.Item("Inventor Summary Information").Item("Author").Value = "..."
                                SaveDoc.PropertySets.Item("Inventor Summary Information").Item("Author").Value = sDesigner
                                SaveDoc.Save()
                                SaveDoc.Views.Item(1).Close()
                                SaveDoc = Nothing
                            Next
                        Catch

                        End Try

                        SavedDocs.Clear()

                        Call ChangeBackground(ColorSchemeOptions.OriginalColorscheme)

                        g_inventorApplication.ScreenUpdating = True
                    End If
                End If

                If BeforeOrAfter = EventTimingEnum.kAbort Then      'Check if it's aborted.
                    Debug.Print("Save canceled")

                    If Not g_inventorApplication.ActiveColorScheme Is oColorscheme Then
                        Debug.Print("    Change back to default")
                        Call ChangeBackground(ColorSchemeOptions.OriginalColorscheme)
                    End If

                    g_inventorApplication.ScreenUpdating = True
                End If
            End If
        End Sub

        Private Sub ChangeBackground(ColorschemeOption As ColorSchemeOptions)

            If ColorschemeOption = ColorSchemeOptions.PresentationColorscheme Then
                g_inventorApplication.ColorSchemes.Item("Presentation").Activate()
                Debug.Print("Change to Presentation")
            ElseIf ColorschemeOption = ColorSchemeOptions.OriginalColorscheme Then
                oColorscheme.Activate()
                Debug.Print("Change to Sky")
            End If

        End Sub
0 Likes

bradeneuropeArthur
Mentor
Mentor

first I see is:

 

oColorscheme is not declared/defined!

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 !

0 Likes

Majjek
Advocate
Advocate

Sorry, I forgot to mention.

Some variables are declared as global during startup.

I only pasted the code for the event.

All variables are declared and the code works as is.

 

But I don't want to have to use the section with catching the children in a collection to reopen them after the save command.

0 Likes