Macro to change View and/or Sheet Scale

Hello,

     I've put together this macro to change the scales on drawings. If a view is selected, it changes the view scale only, if nothing is selected, it changes the sheet scale.

    

     I created macro buttons in the "View Layout" tab and added keyboard shortcuts to it:

    

     Just wanted to share. I'm attaching the macros and the .bmp files of the buttons in this thread in case anyone is interested.

    

     The idea came when reading this thread:

Dim swApp                       As SldWorks.SldWorks

Dim swModel                     As SldWorks.ModelDoc2

Dim swSelMgr                    As SldWorks.SelectionMgr

Dim swView                      As SldWorks.View

Dim boolstatus                  As Boolean

Dim currentSheet                As Sheet

Dim swDraw                      As SldWorks.DrawingDoc

Dim X                           As Integer

Dim Y                           As Integer

Dim swScale                     As Double

Dim bRet                        As Boolean

Sub main()

    X = 1                                                  'The scale will be set as X:Y

    Y = 1

    Debug.Print "Scale          = " & X & ":" & Y

    swScale = X / Y

    Debug.Print "swScale          = "; swScale

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set currentSheet = swModel.GetCurrentSheet

    On Error Resume Next

    Set swView = swSelMgr.GetSelectedObject6(1, -2)

    If Not swView Is Nothing Then

        swView.ScaleDecimal = swScale

        bRet = swDraw.ForceRebuild3(False)

        Else

        boolstatus = currentSheet.SetScale(X, Y, True, False)

        bRet = swDraw.ForceRebuild3(False)

    End If

    swModel.ClearSelection2 False

    swModel.ForceRebuild3 False

    bRet = swDraw.ForceRebuild3(False)

End Sub

SolidworksApi macros
Answers 28
SF
SF 2015-05-27 Best Answer

1.5:1

1.5:2

1.5:3

1.5:4

1.5:5

add you macro

SF
SF 2015-06-03

Hello,

     Well, that's kind of an odd request, but I've made it and attached it here, hope it's helpful.

Thanks for your interest!

    

SF
SF 2015-06-04

never

I want this not

Scale of view

1.5:1

1.5:2

1.5:3

1.5:4

1.5:5

MG
MG 2015-06-04

Hi Leon,

I believe that the ability to change drawing scales directly will be an addition to SolidWorks 2016 so no need for macro's.

Unless you can't wait till October(ish)

Thanks

Mark

SF
SF 2015-06-04

Hello Mark,

    Well, since I would rather be shot in the face with a bazooka than to use any SW version before SP2 is released, I guess I'll be using this macro for a year or so...

     It was worth the effort, but hey, great to hear that this maybe won't be needed in future versions, I always prefer to use built in features than macros.

SF
SF 2015-06-22

@Leon Wurr

Thanks a lot for your effor and for sharing it.

It was really helpful to me, no matter if the new solidworks version will have an option to do this or if it doesn't.

Feel free to upload handy scripts like this one anytime.

JS
JS 2015-08-24

How do you add buttons to the View Layout tab?

DG
DG 2015-08-24

Same way you add to macro toolbar

JS
JS 2015-08-24

lol ... good one .... ok - All I want to ask you is where can I but the API book for dummies - I have no idea how to add a macro toolbar... so I'm like the dog that's chasing it's own tail

JS
JS 2015-08-24

Thanks - I got it done

JP
JP 2019-09-23

‌,

How did you make the Bit Maps? I'll use this package but I've got to add a bunch of scales to it and Id like to add to your bit maps. I'll post here when I'm done

MP
MP 2019-09-23

,

I think you can create them in just about anything.  But they must meet certain requirements.

16x16 pixels You can use at least 32x32 now (I haven't checked higher resolution)

256 colors

background color white

That's according to ‌ in  

With 4k monitors, that may have changed to allow higher resolution (it has, but I don't know the upper limit).

If you take the file I have attached, open it in paint, white it out, and add whatever scale you need then save it, it should work.  If it doesn't  a simple free application is Paint.net that works (it's what I use).  If you are more adventurous and have some time, Gimp can definitely do it, it just has a very steep learning curve and isn't intuitive at all (at least to me).

JP
JP 2019-09-23

Matt,

Thanks! I couldnt get it to work in Paint but I just got Paint.net and seems pretty freaking easy. Just finished 1:3 now. I'll be up a creek if I need a number he didn't make but so far so good. I stole the "3" from 1:30

Edit: Dang, there is no 6 or 8

comment imagecomment image
MP
MP 2019-09-23

Use the rectangle select tool (circled below), select everything and hit the delete key.  Don't worry that you've deleted the background, bmps don't have transparency.  When you save it, that background will be white.

Then use the text tool with the settings shown below and add the text:

Then when you put your cursor over the arrow box as below, the cursor turns into a "hand".  Then you can drag the text to center it.  Save it and move on to the next one.

comment imagecomment imagecomment imagecomment image
JP
JP 2019-09-23

‌,

You know, I think you might just a hero to a few people. Simple enough, thanks for the explanation!

JS
JS 2019-09-23

I created the bit maps, using Microsoft Office and change the font and color till I got what I wanted, then I used the snipping tool and saved the snips as a jpeg, then I opened them with Paint and saved them to a bit map...

MP
MP 2019-09-23

Glad I could help.

MP
MP 2019-09-23

Hey John (and Justin),

One of the benefits of using Paint.net in this case would be to use layers.  So, if I save my .bmp as a .pdn file(which supports layers).  I can then add a new layer for each scale...Not exactly, but similar to layers in CAD.

Then after creating all my scales I'd save the .pdn.  Then turn on each individual layer one at a time and save out my scales as bmps.  If I ever needed to add a new one I'd open the .pdn and make it.

You turn on and off the visibility of the layer with the checkbox, and you are always working on the highlighted layer, if that helps.

comment imagecomment image
JP
JP 2019-09-23

I thought about asking for your copy, but thought to give it a try. Question: I wanted to try to make a 1.5:1 scale, I see in the macro a mention to integers but in the script I dont see any jargon about rounding up. Is it possible to make the 1.5 macro?

Edit heres my attempt

JP
JP 2019-09-23

lol Dang. I read about layers, but I was looking at how to edit the text, didn't think to make a layer for each scale

MP
MP 2019-09-23

I don't know if it's the "correct" usage for layers, but it works...So, why not?

JP
JP 2019-09-23

Is there a reason my macro button image isn't working?

Any thoughts?

Edit: Ive figured out that it was because I did auto detect. If I choose 4, 8, 16, or 24 it will work but its not a very clear image like johns or leons

comment imagecomment imagecomment imagecomment image
MP
MP 2019-09-23

I'm on my phone right now. But, can you post the image file that isn't working for your macro? 

I'll take a look at it tomorrow.

JP
JP 2019-09-23

Thanks matt for everything, I figured out that it was during the 2nd part of the save as BMP auto detect was setting it to 32 bit but 4 bit seems to work just fine. It was a process but I figured out how to make the icon look fantastic. I'll post the .net file as well as my set of icons soon

MP
MP 2019-09-23

Nice! They don't make icons easy.

But, going back to ‌'s post, you can use 8bit if you need more colors, 256, as opposed to 16 with 4 bit.  So, keep that in mind if you need more contrasting colors.

JP
JP 2019-09-24

‌ and ‌

ok so this was a neat project, discovering the process was a blast. There appears to be a misunderstanding about 16X16, I think that's the smallest size possible but 64 x 64 scales up and down nicely with SW Icon size.

What Ive got is the package of icons and their macros (thanks ‌)

1. start at 16x16, make a temp border for text reference

2 resize up to 64x64

3 resize to w128 by h64

4 insert text at size 48 and center nicely

5 create layers and text (a bunch)

6 resize back down to 64x64 (this squishes the text tall and nice)

7 make a back ground and border layers

8 change visibility and save out to BMP and repeat!

comment imagecomment imagecomment imagecomment image
AT
AT 2019-09-24

You can use this add-in:  and it will scale icons for you and assign the required background. So just select any size image with (optional) transparent background and it will render that correctly. Furthermore you will have separate toolbar. And also it is easy to back this up as it will be managed by a single file and you can even share this from the centralized storage so all your colleagues would have the same set of macros if needed.