iLogic Change Background Colour
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've written two iLogic codes that change the bacground colour to white before save (so the thumbnail shows the part/assembly cleanly), and then after save to revert to the original colours. The code exists in each part and is triggered to run the same way for each part.
The code works perfectly on single parts, and on assemblies where all the sub-components are open within Inventor.
However, when I make changes and save at the assembly level (while the sub-components are not open in Inventor) the code stops running after the first rule. Manually running the second rule reverts the changes, but the sub-components do not update their respective thumbnails as per the first example.
Because the rules are triggered by the save command I had to split the code into pre and post save because the function can't call a save without going into an infinite loop. The code saves the bacground color to the part location to retrieve after thet save, and then deletes the txt file. I considered making this an external rule, but this would cause issues when we send any parts/assemblies to our clients.
The first rule triggered to run before the save is:
SyntaxEditor Code Snippet
fs = CreateObject("Scripting.FileSystemObject") OldColorFile = fs.CreateTextFile(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt", True) Dim OldColorSchemeName As String OldColorSchemeName = ThisApplication.ActiveColorScheme.Name OldColorFile.WriteLine (OldColorSchemeName) OldColorFile.Close OldBackgroundFile = fs.CreateTextFile(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt", True) Dim OldBackground As BackgroundTypeEnum OldBackground = ThisApplication.ColorSchemes.BackgroundType OldBackgroundFile.WriteLine (OldBackground) OldBackgroundFile.Close ThisApplication.ColorSchemes.Item("Presentation").Activate ThisApplication.ColorSchemes.BackgroundType = 52737
The second rule, which is triggered to run after the save is:
SyntaxEditor Code Snippet
Imports System.IO Dim oRead As New StreamReader(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt") Dim aLine As String aLine = oRead.readline() oRead.Close Kill (ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldBackground.txt") Dim Read As New Streamreader(ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt") Dim bLine As String bLine = Read.readline() Read.Close Kill (ThisDoc.Path & "\" & ThisDoc.FileName(False) & "OldColorName.txt") ThisApplication.ColorSchemes.Item(bline).Activate ThisApplication.ColorSchemes.BackgroundType = aline ThisApplication.GeneralOptions.Show3DIndicator = True