Automating Tree Display Settings in SolidWorks Assemblies

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
senuba
Posts: 16
Joined: Thu Oct 26, 2023 1:37 am
Answers: 0
x 16
x 6

Automating Tree Display Settings in SolidWorks Assemblies

Unread post by senuba »

Hello, I have a setting that I need to apply for every assembly. Can this be done with a macro, or is there a general setting for it? Right-click on the general assembly, "Tree Display" - "Component Name and Description," and in the window that opens, the boxes for 1-"Component Name", 2-"Configuration Name", and 4-"Do not show configuration or display state name if only one exists" should be checked, while 3-"Display state name" should be unchecked. I'm looking for a general setting or macro for this. Is there one available or can it be done? I am attaching screenshots as well.
Attachments
3.PNG
4.PNG
User avatar
AlexLachance
Posts: 2174
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2353
x 2008

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by AlexLachance »

It can most likely be done with a macro, I think I remember someone asking for something very similar.
User avatar
SPerman
Posts: 2035
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2207
x 1860
Contact:

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by SPerman »

See if #Task from Central Innovations does what you want. It is a very powerful set of tools for doing bulk manipulation of solidworks files. It is subscription based, but the cost is very reasonable.

#Task v2.2
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
senuba
Posts: 16
Joined: Thu Oct 26, 2023 1:37 am
Answers: 0
x 16
x 6

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by senuba »

I found the code :)
I'm sharing it below now. Thank you everyone.

Code: Select all

'https://help.solidworks.com/2022/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFeatureManager~HideComponentSingleConfigurationOrDisplayStateNames.html
'https://help.solidworks.com/2024/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFeatureManager~SetComponentIdentifiers.html

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Dim compIdentifierRet As Long

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swFeatMgr = Part.FeatureManager

If (swFeatMgr.ShowDisplayStateNames) Then

compIdentifierRet = swFeatMgr.SetComponentIdentifiers(swComponentIdentifier_ComponentName, 0, 0)
compIdentifierRet = swFeatMgr.SetComponentIdentifiers(swComponentIdentifier_ComponentDescription, 0, 0)
compIdentifierRet = swFeatMgr.SetComponentIdentifiers(swComponentIdentifier_ComponentName, 0, 0)
    
swFeatMgr.ShowComponentNames = True
swFeatMgr.ShowComponentDescriptions = False
swFeatMgr.ShowDisplayStateNames = False
swFeatMgr.HideComponentSingleConfigurationOrDisplayStateNames = True
swFeatMgr.ShowComponentConfigurationNames = True
swFeatMgr.ShowComponentConfigurationDescriptions = False
End If
End Sub
User avatar
DavidWS
Posts: 21
Joined: Fri Jul 28, 2023 11:33 pm
Answers: 1
x 26
x 11

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by DavidWS »

senuba wrote: Wed Aug 14, 2024 3:41 am I found the code :)
I'm sharing it below now. Thank you everyone.

Code: Select all

'https://help.solidworks.com/2022/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFeatureManager~HideComponentSingleConfigurationOrDisplayStateNames.html
'https://help.solidworks.com/2024/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IFeatureManager~SetComponentIdentifiers.html
[/quote]

I like what this should do, but it doesn't seem to do anything... is this pasted correctly?

[attachment=0]image.png[/attachment]
Attachments
image.png
Uncle_Hairball
Posts: 194
Joined: Fri Mar 19, 2021 12:21 pm
Answers: 2
x 37
x 95

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by Uncle_Hairball »

senuba wrote: Wed Aug 14, 2024 3:41 am I found the code :)
I'm sharing it below now. Thank you everyone.
Many thanks for the macro. That's terrific!
HercalloY
Posts: 28
Joined: Tue Mar 30, 2021 7:51 pm
Answers: 0
Location: QLD, Australia
x 38
x 28

Re: Automating Tree Display Settings in SolidWorks Assemblies

Unread post by HercalloY »

I have three macro's i've used for a while that toggle the Display State Name/Configuration Name/Description in the FMT. I have each on a button to toggle easily. Unfort. the Description one seems to have broken in 2024 at some point and now it replaces the file name with the description instead of toggling it alongside the file name like it always did soi have yet to fix that. I'm sure its possible still, it just needs updating to work with their updated changes to this area. I just don't have the patience or chance to fix it yet (I'm no programmer and only hack my way through getting them to work in the fist place).

This code you provide may give me some incite to correct mine when i get around to it, thanks.
Attachments
FMT_MACROS.zip
(18.66 KiB) Downloaded 55 times
Post Reply