ilogic code that remember your Background , how would you do it ?

ilogic code that remember your Background , how would you do it ?

Darkforce_the_ilogic_guy
Advisor Advisor
251 Views
5 Replies
Message 1 of 6

ilogic code that remember your Background , how would you do it ?

Darkforce_the_ilogic_guy
Advisor
Advisor

I have to make a that change form what ever backgound you have now, to the all white Presentation backgound. but if you run it again it need to turn it back to what every backgrond you have last time.

 

So the user of the code can change if setup to what ever background that he/she want and then if they need to change to white for a picture then can run it ... and when they are done they just run if again and be back to what every they have before 

 

today I use this code 

 If (ThisApplication.ColorSchemes.BackgroundType = 52737) Then
      
        
        ThisApplication.ColorSchemes.Item("Winter Day").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kGradientBackgroundType
    Else
        ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
    End If

Else

, but that lock all user to have the same  and can't change it... I want it more flexsibel 🙂 

0 Likes
Accepted solutions (1)
252 Views
5 Replies
Replies (5)
Message 2 of 6

a.brusamolino
Enthusiast
Enthusiast

Hi!

 

I’m not sure if this is the most robust method, but it works.
The first idea that comes to mind is to save the current settings in a TXT file that you can store wherever you want.

 

So first, run this code (only once, just to save the settings—after that, you won’t need it anymore).

 

 

Sub Main()
	Dim oApp As Inventor.Application = ThisApplication
	Dim CurrentColorScheme As Inventor.ColorScheme = oApp.ActiveColorScheme
	Dim CurrentBackGroundType As BackgroundTypeEnum = oApp.ColorSchemes.BackGroundType

	FileNameTxt = "YourPathHere"
	
	oWrite = System.IO.File.CreateText(FileNameTxt)
	oWrite.WriteLine(CurrentColorScheme.Name)
	oWrite.WriteLine(CurrentBackGroundType)
	oWrite.Close()
	oWrite.Dispose	
End Sub

 

 

Then, this is the code you should place in your rule. The important thing is not to delete or move the TXT file. That’s why I mentioned that it might not be the most robust method.

 

 

Sub Main ()
	Dim oApp As Inventor.Application = ThisApplication
	Dim CurrentColorScheme As Inventor.ColorScheme = oApp.ActiveColorScheme
	Dim CurrentBackGroundType As BackgroundTypeEnum = oApp.ColorSchemes.BackGroundType

	If CurrentColorScheme.Name = "Presentation" Then
		' Read File
		FileNameTxt = "YourPathHere"
		Dim oRead As System.IO.StreamReader = System.IO.File.OpenText(FileNameTxt)
		Dim line(1) As String

		Dim i As Integer = 0
		Do While Not oRead.EndOfStream
			line(i) = oRead.ReadLine()
			i + = 1
		Loop
		
		oRead.Close()
		oRead.Dispose()
		
		oApp.ColorSchemes.Item(line(0)).Activate
		oApp.ColorSchemes.BackGroundType = line(1)
	
	Else
		oApp.ColorSchemes.Item("Presentation").Activate
		oApp.ColorSchemes.BackGroundType = kOneColorBackgroundType	
	End If
End Sub

 

 

Hope it helps!

 

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Hi folks.  Another idea would be to use the iLogic 'SharedVariable' resource, which can be used to hold data in Inventor's session memory.  That would be much simpler & easier to use.  However, if you quit Inventor after switching to Presentation ColorScheme, it would not be able to remember the one it was set to before that, since that data would be lost.  But other than that, this should work just fine.  I tested it myself, and it seemed to work OK for me.

Dim oInvApp As Inventor.Application = ThisApplication
Dim sActiveCSName As String = oInvApp.ActiveColorScheme.Name
Dim oCSs As Inventor.ColorSchemes = oInvApp.ColorSchemes
Dim bSharedExist As Boolean = SharedVariable.Exists("Previous ColorScheme")
If Not bSharedExist OrElse sActiveCSName <> "Presentation" Then
	SharedVariable.Value("Previous ColorScheme") = sActiveCSName
	SharedVariable.Value("Previous BackgroundType") = oCSs.BackgroundType
	oCSs.Item("Presentation").Activate()
	oCSs.BackgroundType = BackgroundTypeEnum.kOneColorBackgroundType
Else 'not first time, and not currently Presentation, so previous data available
	Dim sPrevCS_Name As String = SharedVariable.Value("Previous ColorScheme")
	Dim sPrevBG_Type = SharedVariable.Value("Previous BackgroundType")
	oCSs.Item(sPrevCS_Name).Activate()
	oCSs.BackgroundType = sPrevBG_Type
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

_dscholtes_
Advocate
Advocate

Just like @a.brusamolino, I use an external file (not in text, but in ini format) for keeping some user settings (e.g. start up location of forms, previously selected check boxes) and I use the Autodesk Inventor AppData location (C:\Users\<your name>\AppData\Roaming\Autodesk\Inventor 2023\) to store it (as this location always exists and is accessible by the user).

0 Likes
Message 5 of 6

machiel.veldkamp
Collaborator
Collaborator

The original article for who's interested..

 

https://clintbrown.co.uk/2019/11/02/ilogic-quick-background-toggle-rule/

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 6 of 6

Darkforce_the_ilogic_guy
Advisor
Advisor
Accepted solution

thank for your idear.  I made this code what work for what I needed .  It remember the background that was not presentation.  when you run it and then change it to presentaion one colour and if it is not presentation it read the text file to see what to turn it back to 

 

Imports System.IO

'1 Dark
'2 Deep Blue
'3 Forest
'4 High Contrast
'5 Light
'6 Millennium
'7 Presentation
'8 Sky
'9 Winter Day
'10 Winter Night
'11 Wonderland

'52737 1 Color
'52738 Grandient


'3 Background Image
' Import the necessary namespace
 Dim filePath As String = "C:\Working Folder\CAD\Kallesoe\BackgroundColor.txt"
 Dim content As String


If System.IO.File.Exists(filePath) Then
    'MessageBox.Show("The file exists.")
Else
	 ' Create an empty file
    System.IO.File.Create(filePath).Dispose()
   ' MessageBox.Show("The file does not exist.")
End If

 Dim content2 As String = System.IO.File.ReadAllText(filePath)

Dim oCSchemes As ColorSchemes = ThisApplication.ColorSchemes
Dim Colorcode As String
Dim ColorSchemesNr As String
Dim ColorBackground As String


If ThisApplication.ActiveColorScheme Is oCSchemes("Presentation") Then
	
	If (content2 = "1-52737") Then
		ThisApplication.ColorSchemes.Item("Dark").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "2-52737") Then
		ThisApplication.ColorSchemes.Item("Deep Blue").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "3-52737") Then
		ThisApplication.ColorSchemes.Item("Forest").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "4-52737") Then
		ThisApplication.ColorSchemes.Item("High Contrast").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "5-52737") Then
		ThisApplication.ColorSchemes.Item("Light").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "6-52737") Then
		ThisApplication.ColorSchemes.Item("Millennium").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "8-52737") Then
		ThisApplication.ColorSchemes.Item("Sky").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "9-52737") Then
		ThisApplication.ColorSchemes.Item("Winter Day").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "10-52737") Then
		ThisApplication.ColorSchemes.Item("Winter Night").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	If (content2 = "11-52737") Then
		ThisApplication.ColorSchemes.Item("Wonderland").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52737
	End If 
	
	'not one color
	If (content2 = "1-52738") Then
		ThisApplication.ColorSchemes.Item("Dark").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "2-52738") Then
		ThisApplication.ColorSchemes.Item("Deep Blue").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "3-52738") Then
		ThisApplication.ColorSchemes.Item("Forest").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "4-52738") Then
		ThisApplication.ColorSchemes.Item("High Contrast").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "5-52738") Then
		ThisApplication.ColorSchemes.Item("Light").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "6-52738") Then
		ThisApplication.ColorSchemes.Item("Millennium").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "8-52738") Then
		ThisApplication.ColorSchemes.Item("Sky").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "9-52738") Then
		ThisApplication.ColorSchemes.Item("Winter Day").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "10-52738") Then
		ThisApplication.ColorSchemes.Item("Winter Night").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	If (content2 = "11-52738") Then
		ThisApplication.ColorSchemes.Item("Wonderland").Activate
		ThisApplication.ColorSchemes.BackgroundType = 52738
	End If 
	
	
	Else
ColorSchemesNr = ThisApplication.ColorSchemes.BackgroundType
If ThisApplication.ActiveColorScheme Is oCSchemes("Dark") Then
	
ColorSchemesNr = "1"
ColorBackground = ThisApplication.ColorSchemes.BackgroundType
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Deep Blue") Then
	ColorSchemesNr  = "2"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Forest") Then
	ColorSchemesNr  = "3"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("High Contrast") Then
	ColorSchemesNr = "4"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Light") Then
	ColorSchemesNr  = "5"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Millennium") Then
	ColorSchemesNr  = "6"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Sky") Then
	ColorSchemesNr  = "8"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Winter Day") Then
	ColorSchemesNr  = "9"
	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Winter Night") Then
	ColorSchemesNr  = "10"
 	ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 
If ThisApplication.ActiveColorScheme Is oCSchemes("Wonderland") Then
	ColorSchemesNr  = "11"
    ColorBackground = ThisApplication.ColorSchemes.BackgroundType
	content = ColorSchemesNr.ToString & "-" & ColorBackground.ToString
	ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End If 

End If 


Try
	
    System.IO.File.WriteAllText(filePath, content)
   ' MessageBox.Show("File written successfully.")
Catch ex As Exception
   ' MessageBox.Show("Error writing to file: " & ex.Message)
   
   ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
End Try

 

 

0 Likes