Page 1 of 1

Automating Tree Display Settings in SolidWorks Assemblies

Posted: Tue Aug 13, 2024 1:11 pm
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.

Re: Automating Tree Display Settings in SolidWorks Assemblies

Posted: Tue Aug 13, 2024 1:47 pm
by AlexLachance
It can most likely be done with a macro, I think I remember someone asking for something very similar.

Re: Automating Tree Display Settings in SolidWorks Assemblies

Posted: Tue Aug 13, 2024 2:10 pm
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

Re: Automating Tree Display Settings in SolidWorks Assemblies

Posted: Wed Aug 14, 2024 3:41 am
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

Re: Automating Tree Display Settings in SolidWorks Assemblies

Posted: Tue Aug 20, 2024 5:21 am
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]