Keyboard shortcuts for transparent component

Hi all

A little practical question, on Solidworks there is the keyboard shortcut " tab " to " hide a component ". Is there, or is it possible to set a keyboard shortcut to " make a component transparent "

Thank you

Hello

No ability to assign a key to this function (checked on SW2023 and 2024).

1 Like

Hello

Following this post (https://forum.mycad.visiativ.com/t/affecter-un-raccourci-clavier-a-un-cmdbutton-dans-un-uf/112019/3) the simple idea came to me to use this method to maybe solve your problem, and finally serve us all:


Here is the macro in 2 in 1 version:
CompTransparent-Opaque_(macroSW).zip (19.2 KB)

The pack includes the icons for the 2 macro buttons, targeting both functions (method).

' *****************
' 01/07/25 by Sylk
' *****************
'*** prérequis: assemblage ouvert et au moins un composant sélectionné.
'*** but: rendre transparent ou opaque un ou plusieurs composants d'un assemblage, via des raccourcis clavier associés à ces fonctions.
'*** setup: Ajouter 2 boutons de macro à la barre d'outils (1 pour la fonction Transparent et 1 pour la fonction Opaque) et Assigner des raccourcis clavier aux 2 boutons

Dim swApp, Doc As Object
Dim boolstatus As Boolean
'Dim longstatus, longwarnings As Long

Sub Transparent()
    Set swApp = Application.SldWorks
    Set Doc = swApp.ActiveDoc
    If Doc Is Nothing Or Doc.GetType <> swDocASSEMBLY Then Exit Sub
    boolstatus = Doc.SetComponentTransparent(True)
End Sub

Sub Opaque()
    Set swApp = Application.SldWorks
    Set Doc = swApp.ActiveDoc
    If Doc Is Nothing Or Doc.GetType <> swDocASSEMBLY Then Exit Sub
    boolstatus = Doc.SetComponentTransparent(False)
End Sub

Continuation of the tutorial to follow...

2 Likes

Hello
In fact I don't really see the point. A right click is not a very long and expensive operation...

1 Like

At this point we delete all keyboard shortcuts then!

Joking aside, a right click + a mouse move + another click for transparency will always take longer than a shortcut key. Especially when you work with both hands, the economy of mouse clicks is for me a real optimization problem :slight_smile:

1 Like
Sub T01()
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks

Dim REPONSE As Boolean
REPONSE = swApp.RunCommand(120, False)
End Sub

Sub T02()
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks

Dim REPONSE As Boolean
REPONSE = swApp.RunCommand(swCommands_ChangeTransparency, False)
End Sub

https://help.solidworks.com/2024/English/api/swcommands/solidworks.interop.swcommands~solidworks.interop.swcommands.swcommands_e.html?verRedirect=1