VBA Marco background color

VBA Marco background color

Darkforce_the_ilogic_guy
Advisor Advisor
2,551 Views
7 Replies
Message 1 of 8

VBA Marco background color

Darkforce_the_ilogic_guy
Advisor
Advisor

I want to make a marco that chance between 2 background color

 

 

I want it to run this code if the ColorSchemes is not Millennum

ThisApplication.ColorSchemes.Item("Millennium").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
  

 

I want it to run this code if the ColorSchemes is not Presentation

ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737

 

And I only what to want to run the marco to make it happen ... .no dialog Box please

 

I got code form a coworker. but that force me to make the chose ... I want it to do it for me by reading what background is aktiv before hitting the marco. can you help

 


      

Accepted solutions (1)
2,552 Views
7 Replies
Replies (7)
Message 2 of 8

pball
Mentor
Mentor
Accepted solution

I can't find a way to get the active color scheme so this isn't ideal but it seems to work. It is possible get the current value for the background type so a simple check of the current value lets you toggle the two color schemes.

 

    If (ThisApplication.ColorSchemes.BackgroundType = 52737) Then
        ThisApplication.ColorSchemes.Item("Millennium").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
    Else
        ThisApplication.ColorSchemes.Item("Presentation").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
    End If
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 3 of 8

aurel_e
Collaborator
Collaborator

Hi all,

I am using this code copied from this discussion(Inventor 2018):

Sub ChangeBackground()
If (ThisApplication.ColorSchemes.BackgroundType = 52737) Then
        ThisApplication.ColorSchemes.Item("High Contrast").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
    Else
        ThisApplication.ColorSchemes.Item("Sky").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
    End If
End Sub

The problem is that I want to switch from a "Sky" color scheme with the "Background Image" (please see screenshot attached) and the macro is giving me a normal blu background. I don't know how to write it.

Thanks.2018-12-17 08_36_23-Application Options.png

Message 4 of 8

Darkforce_the_ilogic_guy
Advisor
Advisor
Sub ChangeBackground()
If (ThisApplication.ColorSchemes.BackgroundType = 52737) Then
        ThisApplication.ColorSchemes.Item("High Contrast").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
    Else
        ThisApplication.ColorSchemes.Item("Sky").Activate
ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType


is this what your want?
End If End Sub
Message 5 of 8

aurel_e
Collaborator
Collaborator

nearly there:

I'm using this now (trying to understand and messing around):

Sub ChangeBackground()
If (ThisApplication.ColorSchemes.BackgroundType <> kImageBackgroundType) And (ThisApplication.ColorSchemes.BackgroundType <> 52737) Then
 ThisApplication.ColorSchemes.Item("Sky").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
        Else
        
If (ThisApplication.ColorSchemes.BackgroundType = 52737) Then
        ThisApplication.ColorSchemes.Item("Sky").Activate
        ThisApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
    Else
        ThisApplication.ColorSchemes.Item("High Contrast").Activate
        ThisApplication.ColorSchemes.BackgroundType = 52737
        
    End If
    End If
End Sub

I don't like this 2 lines:

If (ThisApplication.ColorSchemes.BackgroundType <> kImageBackgroundType) And (ThisApplication.ColorSchemes.BackgroundType <> 52737) Then
 ThisApplication.ColorSchemes.Item("Sky").Activate

What I'm tryoing to say is : If the color scheme is neither Sky or High Contrast, activate "Sky".

Thanks.

 

Message 6 of 8

Darkforce_the_ilogic_guy
Advisor
Advisor

This is all your need I think..

 

 

Public Sub ChangeBackground()

If ThisApplication.ActiveColorScheme.Name = "High Contrast" Then
ThisApplication.ColorSchemes.Item("Sky").Activate
Stop
If ThisApplication.ActiveColorScheme.Name = "Sky" Then
ThisApplication.ColorSchemes.Item("High Contrast").Activate
Stop
Else


ThisApplication.ColorSchemes.Item("Sky").Activate

End If
End If
End Sub

Message 7 of 8

aurel_e
Collaborator
Collaborator

Hi BT,

the "stop" for same reason is not working.

I have changed it in:

Sub ChangeBackground()
If ThisApplication.ActiveColorScheme.Name = "High Contrast" Then
ThisApplication.ColorSchemes.Item("Sky").Activate
Else
If ThisApplication.ActiveColorScheme.Name = "Sky" Then
ThisApplication.ColorSchemes.Item("High Contrast").Activate

Else


ThisApplication.ColorSchemes.Item("Sky").Activate

End If
End If
End Sub

This is now fine!

Thank you for your support.

0 Likes
Message 8 of 8

Anonymous
Not applicable

Below is the code I use.  I use a grey gradient when I'm normally working, and then if I want to do a screenshot of something, I change the background to white.  Then I want to switch it back easily.  Only thing to note is the custom image file I made called "Plain white" and the folder location.  Edit those lines to match your setup.

 

Sub Background_Switch()
Dim oBackGroundType As BackgroundTypeEnum

With ThisApplication.ColorSchemes 'edit the application background settings easily

oBackGroundType = .BackgroundType
Dim oColorScheme As ColorScheme

Set oColorScheme = ThisApplication.ActiveColorScheme


If oBackGroundType = kGradientBackgroundType Then
.BackgroundType = BackgroundTypeEnum.kImageBackgroundType
oColorScheme.ImageFullFileName = "C:\Users\Public\Documents\Autodesk\Inventor 2019\Backgrounds\PLAIN WHITE.png"
.BackgroundType = BackgroundTypeEnum.kImageBackgroundType

Else

.BackgroundType = BackgroundTypeEnum.kGradientBackgroundType
End If

End With
End Sub

0 Likes