My Macros

Library for macros
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

My Macros

Unread post by mattpeneguy »

Before anyone tries any of my macros, have a look over at https://www.codestack.net/solidworks-tools/ and see if there's a similar macro, if so use the one from the above site before you try mine.
Those macros were made by @artem. For those that don't know he's a programmer, I'm not.

Some macros I've kludged together:
  • All Title Text Resize - changes all titles in all views in a drawing file to a particular size
  • Change Default Drawing Fonts - Change all annotations in a drawing to set sizes, good for switching fonts and sizes
  • Change Dim Tolerances - Changes dimension tolerances for selected dimensions
  • ChangeToolboxPartType with Dialogue - Self explanatory
  • Rename all Views In Drawing - Cycle through all views and sequentially renumber them A-Z. This is good if you've
  • deleted section views and added new ones
  • Renumber Sheets - Renumbers all sheets in a drawing file based on a starting number you enter in a dialog
  • Roll Back - Rolls the rollback bar up the feature tree and then back down. Needs modifying to be useful
  • Sketch Color Change - Change sketch colors with a dialog
  • Title Text Resize - Self explanatory
  • Update Sheet Formats - Changes out the sheet formats for all sheets in a drawing file
  • View Title Text - Adds the BOM Name to a View Title, if selected.
Attachments
Macros.zip
(125.84 KiB) Downloaded 872 times
User avatar
mike miller
Posts: 878
Joined: Fri Mar 12, 2021 3:38 pm
Answers: 7
Location: Michigan
x 1070
x 1231
Contact:

Re: My Macros

Unread post by mike miller »

A few of mine.....
  • Combine Identical Components - useful for BOMs that have multiple instances of a part. (Pre-selection required)
  • Dynamic Highlight ON - Just what it says
  • Multi-Body DXF - a massive masterpiece from Codestack that was modified by us. It will take an assembly or a multibody part file and save all the DXFs to a specified folder using a name based on cutlist properties (you can edit it).
  • Profile Center Mate - Mates two selected faces/edges, sets distance at 0, locks rotation, and confirms.
  • Reload all Sheet Formats -- reloads 'em all in a large drawing.
  • Remove blanks in BOM -- Scans the second to left row in the selected BOM and hides/deletes any row with a blank value. (Needs a little work yet, but extremely powerful!)
  • Save all sheets as PDF and close - Saves all sheets to a specified location, saves, and closes file. Great for those huge behemoths when you have to go pee while it's saving! ;)

[EDIT: 4-22-21 replaced zip file due to board corruption.]
Attachments
My macros.zip
(106.09 KiB) Downloaded 738 times
He that finds his life will lose it, and he who loses his life for [Christ's] sake will find it. Matt. 10:39
User avatar
AlexLachance
Posts: 2226
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2419
x 2061

Re: My Macros

Unread post by AlexLachance »

Hide referenced geometry - Hides referenced geometries such as sketches, insertpoints, planes.

Link views to BOM - Serves to link views to a specific BOM in a multi-BOM drawing.

Note Level selecter - Allows to select the desired level of a note.

Sketch direction - temporarly displays sketch element directions. Useful for people working in multibody parts

Dynamic Highlighting - Turn on Dynamic Highlight. Dang thing keeps turning off randomly so this is a macro to activate it from a click.
Attachments
MacrosAlexLachance.zip
(111.78 KiB) Downloaded 530 times
User avatar
Jaylin Hochstetler
Posts: 387
Joined: Sat Mar 13, 2021 8:47 pm
Answers: 4
Location: Michigan
x 380
x 355
Contact:

Re: My Macros

Unread post by Jaylin Hochstetler »

Here's a version of the Multi-body DXF macro, that Mike posted, on steroids! It allows you to either browse for the "DXFs" folder location or enter the address of the location instead of putting it in the folder the part is located in.
Attachments
Multibody DXF - browse for folder - test.7z
(38.35 KiB) Downloaded 671 times
A goal is only a wish until backed by a plan.
User avatar
mike miller
Posts: 878
Joined: Fri Mar 12, 2021 3:38 pm
Answers: 7
Location: Michigan
x 1070
x 1231
Contact:

Re: My Macros

Unread post by mike miller »

Due to the board corruption of attachments, could you update your files? TIA, @mattpeneguy, @AlexLachance, @Jaylin Hochstetler.
He that finds his life will lose it, and he who loses his life for [Christ's] sake will find it. Matt. 10:39
User avatar
matt
Posts: 1592
Joined: Mon Mar 08, 2021 11:34 am
Answers: 19
Location: Virginia
x 1219
x 2387
Contact:

Re: My Macros

Unread post by matt »

We can also put them in the Downloads area which is a nice central location. The Download area wasn't affected by the corruption. Admin is the only one who can upload, but I'll take that on. You can attach the macros here and I'll upload.
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: My Macros

Unread post by mattpeneguy »

The mention thing is kinda flakey for me lately. Mike Miller and Matt, I have re-uploaded my macros.
Thanks for letting me know.
User avatar
AlexLachance
Posts: 2226
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2419
x 2061

Re: My Macros

Unread post by AlexLachance »

Also done.
User avatar
Jaylin Hochstetler
Posts: 387
Joined: Sat Mar 13, 2021 8:47 pm
Answers: 4
Location: Michigan
x 380
x 355
Contact:

Re: My Macros

Unread post by Jaylin Hochstetler »

Done.
A goal is only a wish until backed by a plan.
DONALT_95
Posts: 1
Joined: Wed May 25, 2022 3:32 am
Answers: 0

Re: My Macros

Unread post by DONALT_95 »

Hi Matt,

I am new to macros and tried to use your 'rename all views in drawing' macro, however when I attempt to run the macro I get a notification saying
"Run-time error'13': type mismatch" when I click debug it highlights this line "For i = 0 To UBound(vViews)"

I appreciate I am attempting to use something I admittedly know nothing about, but this macro in particular would save me endless amounts of time!

Could you advise me on potential mistakes I am making?

Thanks in advance :) :)
User avatar
AlexB
Posts: 508
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 29
x 274
x 462

Re: My Macros

Unread post by AlexB »

DONALT_95 wrote: Wed May 25, 2022 3:42 am Hi Matt,

I am new to macros and tried to use your 'rename all views in drawing' macro, however when I attempt to run the macro I get a notification saying
"Run-time error'13': type mismatch" when I click debug it highlights this line "For i = 0 To UBound(vViews)"
I got curious and had a look. There's a for loop in there to look through all the views on a sheet. If the view array is empty, meaning there are no views on the sheet, then it will produce an error.

Surround the for loop with this if statement:

If Not IsEmpty(vViews) Then
[for loop]
End If

Code: Select all

If Not IsEmpty(vViews) Then
    For i = 0 To UBound(vViews)
        
        Dim swView As SldWorks.View
        
        Set swView = vViews(i)
        
        Select Case swView.Type
            Case swDrawingViewTypes_e.swDrawingSectionView
                Dim swSectionView As SldWorks.DrSection
                Set swSectionView = swView.GetSection
                Debug.Print swSectionView.GetLabel
                swSectionView.SetLabel2 GetNextName
            Case swDrawingViewTypes_e.swDrawingDetailView
                Dim swDetailedView As SldWorks.DetailCircle
                Set swDetailedView = swView.GetDetail
                Debug.Print swDetailedView.GetLabel
                swDetailedView.SetLabel GetNextName
        End Select
        
    Next
End If
Arnaud7.77
Posts: 1
Joined: Fri Sep 01, 2023 5:04 am
Answers: 0

Re: My Macros

Unread post by Arnaud7.77 »

Hello everyone,

Do you have a macro for bom export (catia V5 to excel)?
Either from Product to excel
Either from a drawing table to excel

Arnaud
mme
Posts: 9
Joined: Fri Apr 09, 2021 2:11 am
Answers: 0
x 10

Re: My Macros

Unread post by mme »

Open part or assemblies. Run the macro. Enter a new name. If there is a drawing, it will put the same name on the drawing.
Attachments
ReName.7z
(26.25 KiB) Downloaded 402 times
User avatar
Stefan Sterk
Posts: 37
Joined: Tue Aug 10, 2021 2:40 am
Answers: 3
x 51
x 77

Re: My Macros

Unread post by Stefan Sterk »

mme wrote: Tue Oct 24, 2023 9:42 am Open part or assemblies. Run the macro. Enter a new name. If there is a drawing, it will put the same name on the drawing.
Hi @mme,
Sounds the same as this macro; https://www.codestack.net/solidworks-ap ... t-drawing/
mme
Posts: 9
Joined: Fri Apr 09, 2021 2:11 am
Answers: 0
x 10

Re: My Macros

Unread post by mme »

Stefan Sterk wrote: Thu Nov 02, 2023 4:35 am Hi @mme,
Sounds the same as this macro; https://www.codestack.net/solidworks-ap ... t-drawing/
Oh! I'm sorry. So I have labored in vain.
mme
Posts: 9
Joined: Fri Apr 09, 2021 2:11 am
Answers: 0
x 10

Re: My Macros

Unread post by mme »

There is actually some difference. Artyom's macro works with a batch of assemblies and renames the file in the assembly as well. For me, I copy parts or assemblies and rename them along with the drawing.
laukejas
Posts: 202
Joined: Sun Sep 05, 2021 8:27 am
Answers: 0
x 43
x 114

Re: My Macros

Unread post by laukejas »

Adding my macros as well.

Modify External References - small dialog to Lock / Unlock / Break all references for all components in the assembly. Useful with Master models.

Rebuild Assembly Parts - for when Force Rebuild doesn't cut it. This macro opens each part individually, shakes it down, saves and closes it. Should get these stuck references to update.

Set Image Quality For All Parts - quickly change imaqe quality for all components in an assembly. Useful when you have tons of components that have high quality setting inherited from template or something.

Toggle Tangent Edge Display - quickly toggle tangent edge view without having to go into Options.

Edit Component - we all know how annoying it is that you can't assign Edit Component / Part command to a keyboard shortcut or mouse gesture. But you can with this macro. Select face / feature of any component in the assembly, and it will enter Edit Component mode. Run it again without anything selected, and it will exit Edit Component mode.

Draw CoV - creates a sketch with a point that marks the center of volume (not mass) of the assembly components. Useful when parts have different materials and densities and CoM doesn't match CoV.

Each body to STL - exports each body from a multibody part to an STL. There are some naming rules in there (I use this in conjunction with my Revision Control App (viewtopic.php?t=1823), so there are rules to add revision name to the file. You might want to adjust naming for your use case.
Attachments
laukejas macros.zip
(84.14 KiB) Downloaded 321 times
Post Reply