Macro in Solidworks

Hello

I constantly use in the construction tree the display of "Show component descriptions" and I uncheck "Show the name of the display states".

I do this gymnastics to each part or assembly that has not been processed before, because this information, once filled in, is recorded once and for all in the part or assembly.

Don't know the method to make a macro doing this series of commands, I ask for help to make it.

Thank you.

1 Like

Hello

Have you ever tried through the macro recorder??? You start recording and then do the operation edit the description and then you stop it by saving it. Basically, you record what you do and then stop recording.

2 Likes

Hello

Yes I tried but it doesn't work when I run it.

To make my macro:

I click on the red point for recording

Right-click on the part or assembly, in the construction tree, I slide on "Tree Display" and then on "Show component description" which is checked.

I stop recording and save the name of the macro.

1 Like

Hello, have you tried to do this and save as a template?

1 Like

Hello

Yes, I did indeed do this to update my models and it solves the problem for the next new parts or new assemblies.

But I use files that come from clients or old files (library, business or other) that I would like to update to their reuse.

Hello

Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Sub main()
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swFeatMgr = swModelDoc.FeatureManager

    If swFeatMgr.ShowDisplayStateNames = True Then
        swFeatMgr.ShowDisplayStateNames = False
    End If
    If swFeatMgr.ShowComponentDescriptions = False Then
        swFeatMgr.ShowComponentDescriptions = True
    End If
End Sub

6 Likes

Hello

Wow!

I envy the "know-how".

It works like a charm!

Thank you very much!

1 Like

Also think about changing this in your models, that way you won't have to redo it on every newly created piece:)

1 Like

Hello
I was looking for this very useful macro, but it doesn't work with Solidworks 2010, can anyone help me?

Thank you in advance.

 

Hello

Yes and no, I don't have a Solidworks 2010 and the ShowDisplayStateNames  function only appeared from the 2012 version so the lines:

If swFeatMgr.ShowDisplayStateNames = True Then
        swFeatMgr.ShowDisplayStateNames = False
 End If

can't work on your 2010 version, delete them, you should at least have some of the macro functional.

Kind regards

1 Like

Thank you Daniel,
Indeed half of the macro works, that's already a given!
Sincerely,