iLogic to change bacground

iLogic to change bacground

TA.Fehr
Advocate Advocate
1,165 Views
7 Replies
Message 1 of 8

iLogic to change bacground

TA.Fehr
Advocate
Advocate

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 otherwise it would error out. 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

 

 

0 Likes
1,166 Views
7 Replies
Replies (7)
Message 2 of 8

PaulMunford
Community Manager
Community Manager
Thomas Rambach (@CadToolBox) had a plugin that did this. I can't find it with a web search, so I've tweeted him to see If he can help us out...


Customer Adoption Specialist: Autodesk Informed Design
Help | Learn | Forum | Blog | Ideas | Sample content | Linkedin 

Message 3 of 8

PaulMunford
Community Manager
Community Manager
Here it is...
http://cadtoolbox.com/all-thumbs/


Customer Adoption Specialist: Autodesk Informed Design
Help | Learn | Forum | Blog | Ideas | Sample content | Linkedin 

Message 4 of 8

TA.Fehr
Advocate
Advocate

Thanks for the link, but the download is unavailable. I spoke with my co-worker who got me working on the code and he had found this same plug-in. However, the plug-in is no longer updated and contacting the creator gave me code very similar to what I've written above.

I'm guessing the Dev ran into the same issue I'm finding and figured it wasn't worth his time.

0 Likes
Message 5 of 8

Anonymous
Not applicable
0 Likes
Message 6 of 8

Anonymous
Not applicable

I'm not sure how this translates to iLogic yet but All Thumbs fires for a Save and checks if onBefore or onAfter. For onBefore it saves the current application settings and stores them temporarily. It then switches to the thumbs setting and finishes the save. Inventor then fires the same Save command but flagged as onAfter where All Thumbs reverts back to the original application settings. All Thumbs is written in VB:

 

 

 

Private Sub oAppEvents_OnSaveDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles oAppEvents.OnSaveDocument

 

DoAllThumbs(BeforeOrAfter)

 

End Sub

 

 

 

If BeforeOrAfter = EventTimingEnum.kBefore Then

'## Do Something

Else

'## Do Something Else

End If

 

Message 7 of 8

JohnKHouston
Advocate
Advocate

Hi Thomas,

 

I'm using Inventor 2020 and I tried the All Thumbs and it appeared to work correctly, but it didn't save the info for my background type. I prefer to use gradient instead of one color. When All Thumbs switched back, it switched to one color, unfortunately.

 

Is there any way I can modify the code you posted so that All Thumbs will save the background type? I know it's not supported any more so if you can't find the time, I understand. I just had to ask because it's so close to being what I need.

 

Thanks in advance.

 

Best regards,

John Houston

0 Likes
Message 8 of 8

Anonymous
Not applicable

@JohnKHouston you can capture that information by using:

ThisApplication.ColorSchemes.BackgroundType

The options are  BackgroundTypeEnum.kGradientBackgroundType, BackgroundTypeEnum.kImageBackgroundType or BackgroundTypeEnum.kOneColorBackgroundType. 

0 Likes