Skip to content

Commit a0272a7

Browse files
authored
Merge pull request #1 from EddyAlleman/EddyAlleman-patch-1
Added Toggle Drawing Background White macro
2 parents d46c230 + d97118a commit a0272a7

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed
2.63 KB
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'This macro toggles between 2 colors for the background of drawings.
2+
'It uses a system option, so every drawing you open will get the choosen color
3+
'This can be usefull if you want to make screen captures on a white background.
4+
5+
'Here you can set the 2 colors you want to toggle between
6+
Const Color1 As Variant = 16777215 'color white
7+
Const Color2 As Variant = 14411494 'color grey (default color for drawing background)
8+
9+
10+
Sub main()
11+
12+
try_:
13+
14+
On Error GoTo catch_
15+
16+
Dim swApp As Object
17+
Set swApp = Application.SldWorks
18+
19+
Dim swModel As ModelDoc2
20+
Set swModel = swApp.ActiveDoc
21+
22+
'Get the color on first use (look in Immediate window CTRL + G)
23+
Dim Color As Variant
24+
Color = swApp.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swSystemColorsDrawingsPaper)
25+
Debug.Print "Color : " + CStr(Color)
26+
27+
28+
If Color <> Color1 Then
29+
Color = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swSystemColorsDrawingsPaper, Color1)
30+
Else
31+
Color = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swSystemColorsDrawingsPaper, Color2)
32+
End If
33+
34+
swModel.ForceRebuild
35+
36+
GoTo finally_:
37+
38+
catch_:
39+
40+
Debug.Print "Error: " & Err.Number & ":" & Err.Source & ":" & Err.Description
41+
42+
finally_:
43+
44+
Debug.Print "FINISHED Toggle Drawing Background"
45+
46+
End Sub
16.6 KB
Loading
Lines changed: 132 additions & 0 deletions
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: sw-tool
3+
title: VBA macro to toggle white background in drawings
4+
caption: toggle white drawing background
5+
description: VBA macro to toggle a white background with another color of your choice in drawings using sytem settings
6+
image: ToggleWhiteBackground-icon.svg
7+
labels: [Drawings, options, background, capture]
8+
group: Options
9+
---
10+
Author: [Eddy Alleman](https://www.linkedin.com/in/eddyalleman/) ([EDAL Solutions](https://www.edalsolutions.be/index.php/en/))
11+
12+
![SolidWorks system options to set Drawing Background manually](Option_background.png){ width=450 }
13+
14+
Introduction
15+
On the SolidWorks forum someone asked how to make a macro that toggles between the default drawing background color and a white color.
16+
The goal was to make it easier to capture images where a white background was required.
17+
18+
Here is a simple macro that does exactly that. I will also explain the basic buttons/shortcuts/menus you need.
19+
20+
If you want to toggle between other colors, you can change that in the Color1 and Color2 constants below.
21+
22+
#But how do we get that number that corresponds to the color we want?
23+
Just change it to your favorite color manually in SolidWorks options (in the image above I choose for a more distinct yellow color)
24+
Then open the macro with the macro editor (Menu Tools > Macro > Edit or use the Macros toolbar).
25+
Open the immediate window if it is not already visible (CTRL + G)
26+
Run the macro (F5 or green arrow button) and in the immediate window you should see the color you choose represented by a number:
27+
28+
![Immediate Window showing the choosen color after running the macro](GetChoosenColor.png){ width=150 }
29+
30+
Adapt the number in the code (Color2) and when you run the macro the background color will switch between white and your favorite color.
31+
32+
{% code-snippet { file-name: Macro.vba } %}
33+

0 commit comments

Comments
 (0)