25 Replies Latest reply on Aug 31, 2017 10:27 AM by Josh Brady

    How To Add Keyboard Shortcut For Go To Component (In Tree)

    Valid Valid

      Is there a way to add a keyboard shortcut for Go To Component (In Tree)?

        • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
          Dan Pihlaja

          I don't know anything about that function/command and I can't seem to find it in my version of Solidworks (2015 SP5).

           

          That being said, do you actually mean this?

          • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
            Dan Pihlaja

            Ignore that message above.....I found what you are talking about (I have never actually use them...LOL):

             

            There are actually two options here:

            and

             

            When you RMB on a component in an assembly.

             

            However, I notice the following:

             

            When I have checked, then "Go to Component (in tree)" disappears

             

             

            I think that this is because as soon as I RMB on a component, my feature tree scrolls to it automatically.

             

            So, I don't think that you can add this feature to a keyboard shortcut.  BUT

            If you check the box that I have shown above, then it doesn't matter.  You just have to select the item.

            • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
              Valid Valid

              I intentionally turned off "Scroll Selected Item Into View".  That's why I want a keyboard shortcut for "Go To Component (In Tree)".

               

               

              I want to be able to activate "Go To Component (In Tree)" by pressing a keyboard key while left clicking.  Right clicking takes too much time.

                • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                  Deepak Gupta

                  You can use a macro (codes below) for that. Select any component from tree manager and run the macro (via keyboard shortcut, mouse gesture, macro button, etc.)

                   

                  I hope some one can improve it such that no pre-selection is required.

                   

                  Dim swApp As SldWorks.SldWorks

                  Sub main()

                  Set swApp = Application.SldWorks

                  swApp.RunCommand swCommands_Edit_Findinfm, ""

                  End Sub

                  • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                    Glenn Schroeder

                    Valid Valid wrote:

                     

                    I intentionally turned off "Scroll Selected Item Into View". That's why I want a keyboard shortcut for "Go To Component (In Tree)".

                     

                     

                    I want to be able to activate "Go To Component (In Tree)" by pressing a keyboard key while left clicking. Right clicking takes too much time.

                    Oookay.

                      • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                        Josh Brady

                        Yes.  Right clicking takes too much time.  Especially if your workflow involves doing that multiple times every day.  I've written macros before that save one click per use. 

                          • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                            Glenn Schroeder

                            Josh Brady wrote:

                             

                            Yes. Right clicking takes too much time. Especially if your workflow involves doing that multiple times every day. I've written macros before that save one click per use.

                             

                            Josh, I'll take your word for that, but in the interest of educating me could you answer a question?  I know next to nothing about running a macro, but don't you have to hit a key or click somewhere to run a macro?  And if so, how does it save time by saving one click?

                              • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                Todd Blacksher

                                I tried to find some sort of example . . .

                                Let's say there is a right-click menu command that I use a lot (perhaps "Replace Components")

                                I right click on the part, scroll through the menu and click on the command - this is really only two clicks.

                                I might see a benefit to putting a macro on the gesture wheel that would allow me to click the part and swoop the gesture, effectively removing a single click.

                                Depending on my workflow, this could feasibly save me some time.

                                (Probably not enough for me to mess around with customizing, but it might be fun to try if I had some free time.)

                                 

                                The part that I am still confused about is:

                                Why do you need to get to the part in the tree quickly if you aren't going to do anything with it?

                                • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                  Josh Brady

                                  A key struck by the left hand that is always present at the keyboard is significantly faster than a right-click, position mouse, left click.  The keybound macro actually "saves" 2 clicks, but I already discounted the clicks to make up for the keystroke.

                                  • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                    Todd Blacksher

                                    Glenn Schroeder - I found a better example!

                                    I recently made a keyboard shortcut for "Select Other" -

                                    Normally I would hover the cursor, left or right click, click the "Select Other" icon, and it would activate the command.

                                    Now I just hit the key and I'm already in the command.

                                    It goes from two clicks to activate the command to a single keystroke - which doesn't really sound like much, but . . .

                                    The big time savings for me is that I don't have to focus on the icon and select it.

                                    (A key on the keyboard is easier for me to hit when I'm under/over caffeinated!)

                                     

                                    Josh Brady has a very good point about the left hand always being on the keyboard - in my AutoCAD days I did almost everything with keyboard shortcuts, and I mapped the majority to the left side of the keyboard.

                                     

                                    Now, if there was only a keyboard shortcut to "grab/activate" the rollback bar in the feature manager, then I could use the arrow keys to roll forward/back, and I could review the construction of a part without even touching the mouse!

                                      • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                        Glenn Schroeder

                                        Todd,

                                         

                                        Thank you.  I have a 3d mouse for my left hand, and avoid going to my keyboard as much as possible.  Now that I understand that you keep your left on the keyboard your explanation (and Josh's) make perfect sense.

                                          • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                            Todd Blacksher

                                            I go back and forth with my 3d mouse - it is not even connected right now, but I think I need to bring it out of "retirement"

                                            (I just have the basic one, but the two buttons were programmed for Ctrl & S, and that saved a lot of trips to the keyboard.

                                            I have barely scratched the surface with my 3dconnexion CAD Mouse - so much stuff you can do with it!

                                            (I've touched on the gestures built into the mouse/software, because you can use those for any program - even windows explorer!)

                                             

                                            I think I can blame AutoCAD for my love of keyboard shortcuts . . . and I can type way faster than I can click.

                                          • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                            Chris Lindloff
                                            Now, if there was only a keyboard shortcut to "grab/activate" the rollback bar in the feature manager, then I could use the arrow keys to roll forward/back, and I could review the construction of a part without even touching the mouse

                                             

                                            I agree, I have been wanting this as well.  I constantly want to scroll through the feature tree one line at a time, but having to go and activate the roll back bar stinks. 

                                              • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                                Josh Brady

                                                I found this in my archive.  I am not sure where I got it, but I'm pretty sure I wasn't the original author.  I might have tweaked it, not sure.  If anyone recognizes it and can give credit please do.  Might be helpful with the rollback model review...

                                                 

                                                '-----------------------------------
                                                ' How to playback a model
                                                '
                                                ' Problem:
                                                '       For a complicated part/assy, it is often very instructive
                                                '       to proceed, step by step, through the history tree.
                                                '       This shows each step of how the model was developed and
                                                '       can give insight into the design intent of the user.
                                                '
                                                '       This sample code shows how to step through the history
                                                '       tree of a model by rolling back to each feature in
                                                '       reverse sequence.  As each feature is played back, it
                                                '       is highlighted in the graphics window.
                                                '
                                                ' Preconditions:
                                                '       1) a part or assy is open
                                                '
                                                ' Postconditions:
                                                '       none
                                                '
                                                ' Notes:
                                                '       1) delay between steps is set at 1 second
                                                '
                                                ' Further Work:
                                                '       1) zoom to each feature:
                                                '               Part/AssemblyDoc::FeatureByName
                                                '
                                                '               Feature::GetBox
                                                '               ModelDoc2::ViewZoomTo2
                                                '                   or
                                                '               Feature::Select2
                                                '               ModelDoc2::ViewZoomToSelection
                                                '
                                                '           probably also require some view manipulation...
                                                
                                                
                                                Option Explicit
                                                
                                                
                                                Public Enum swDocumentTypes_e
                                                    swDocNONE = 0       '  Used to be TYPE_NONE
                                                    swDocPART = 1       '  Used to be TYPE_PART
                                                    swDocASSEMBLY = 2   '  Used to be TYPE_ASSEMBLY
                                                    swDocDRAWING = 3    '  Used to be TYPE_DRAWING
                                                    swDocSDM = 4        '  Solid data manager.
                                                End Enum
                                                
                                                
                                                Public Enum swMoveRollbackBarTo_e
                                                    swMoveRollbackBarToEnd = 1
                                                    swMoveRollbackBarToPreviousPosition = 2
                                                    swMoveRollbackBarToBeforeFeature = 3
                                                    swMoveRollbackBarToAfterFeature = 4
                                                End Enum
                                                
                                                
                                                Sub main()
                                                    ' delay in seconds
                                                    Const DELAY                     As Single = 1#
                                                    
                                                    Dim swApp                       As SldWorks.SldWorks
                                                    Dim swModel                     As SldWorks.ModelDoc2
                                                    Dim swPart                      As SldWorks.PartDoc
                                                    Dim swAssy                      As SldWorks.AssemblyDoc
                                                    Dim swFeatMgr                   As SldWorks.FeatureManager
                                                    Dim swSelMgr                    As SldWorks.SelectionMgr
                                                    Dim swFeat                      As SldWorks.Feature
                                                    Dim vFeatFace                   As Variant
                                                    Dim swFace                      As SldWorks.Face2
                                                    Dim sFeatName()                 As String
                                                    Dim sNow                        As Single
                                                    Dim nDocType                    As Long
                                                    Dim i                           As Long
                                                    Dim j                           As Long
                                                    Dim bRet                        As Boolean
                                                    Dim tStart                      As Double
                                                    Dim tElapse                     As Double
                                                    Dim tTot                        As Double
                                                    Dim myStr                       As String
                                                    
                                                    
                                                    
                                                    Set swApp = CreateObject("SldWorks.Application")
                                                    Set swModel = swApp.ActiveDoc
                                                    Set swFeatMgr = swModel.FeatureManager
                                                    Set swFeat = swModel.FirstFeature
                                                    
                                                    nDocType = swModel.GetType
                                                    Select Case nDocType
                                                        Case swDocPART
                                                            Set swPart = swModel
                                                    
                                                        Case swDocASSEMBLY
                                                            Set swAssy = swModel
                                                    End Select
                                                    
                                                    
                                                    ReDim sFeatName(0)
                                                    
                                                    Do While Not swFeat Is Nothing
                                                        sFeatName(UBound(sFeatName)) = swFeat.Name
                                                        
                                                        ReDim Preserve sFeatName(UBound(sFeatName) + 1)
                                                    
                                                        Set swFeat = swFeat.GetNextFeature
                                                    Loop
                                                    
                                                    ' loop will over allocate array by one,
                                                    ' so remove last (empty) entry
                                                    ReDim Preserve sFeatName(UBound(sFeatName) - 1)
                                                    
                                                    
                                                    ' now playback each feature in the FMT
                                                    tTot = 0
                                                    swModel.Visible = False
                                                    For i = 0 To UBound(sFeatName)
                                                        'Debug.Print sFeatName(i)
                                                        tStart = Timer
                                                        bRet = swFeatMgr.EditRollback(swMoveRollbackBarToAfterFeature, sFeatName(i))
                                                        tElapse = Timer - tStart
                                                        'Debug.Print sFeatName(i), tElapse
                                                        myStr = myStr & sFeatName(i) & vbTab & tElapse & vbCrLf
                                                        tTot = tTot + tElapse
                                                        ' do not assert since may be trying to rollback/forward
                                                        ' to a feature which cannot be rolled back/forward to
                                                        ' eg Lighting or Annotations folder
                                                        'Debug.Assert bRet
                                                        
                                                        ' will remove any previous highlights
                                                        'swModel.GraphicsRedraw2
                                                        
                                                        
                                                        ' highlight feature if it has any geometry
                                                        'Select Case nDocType
                                                        '    Case swDocPART
                                                        '        Set swFeat = swPart.FeatureByName(sFeatName(i))
                                                        
                                                        '    Case swDocASSEMBLY
                                                        '        Set swFeat = swAssy.FeatureByName(sFeatName(i))
                                                        'End Select
                                                        
                                                        'vFeatFace = swFeat.GetFaces
                                                        'If Not IsEmpty(vFeatFace) Then
                                                        '    For j = 0 To UBound(vFeatFace)
                                                        '        Set swFace = vFeatFace(j)
                                                        '
                                                        '        swFace.Highlight True
                                                        '    Next j
                                                        'End If
                                                        
                                                        
                                                        ' only pause if we have successfully rolled back
                                                        'If True = bRet Then
                                                        '    sNow = Timer
                                                        '    While sNow + DELAY > Timer
                                                                ' need to allow SW to refresh screen
                                                        '        DoEvents
                                                        '    Wend
                                                        'End If
                                                    Next i
                                                    myStr = myStr & "Total Rebuild Time: " & vbTab & tTot
                                                    swModel.Visible = True
                                                    MsgBox myStr
                                                    ' remove highlight from last feature
                                                    'swModel.GraphicsRedraw2
                                                End Sub
                                                
                                    • Re: How To Add Keyboard Shortcut For Go To Component (In Tree)
                                      Todd Blacksher

                                      I'm not sure what you are really after, but if you click on an item in the graphics window, and hit the "D" key, you will get breadcrumbs at the location of your cursor - this should have almost anything that you would need to do to the selected component.

                                      As long as you are on SWX 2016 or newer.

                                      todd