21 Replies Latest reply on Oct 18, 2017 7:39 PM by Anton Ivanov

    2 Questions (for now)

    Anton Ivanov

      Hi,

       

      I have 2 questions (for now):

       

      1. Is there a way to turn off, what it looks like, an automatic pre-selection of last touched surface when trimming, boundary surface creation (it happens in other commands too). It is one of those situations that when you want to trim something and when you open the command there is already a surface there and most of the time it is not what I want so it extends the function by two clicks. That's the measurable metric; it is also very annoying especially when I don't catch it right a way and my trim ends up not working and have to redo it. 

       

      2. Is there a good way to set up a toggle short cut key, let say "E" , between showing the model in "Shaded With Edges" and "Hidden Lines Visible".

       

      Thank you!

        • Re: 2 Questions (for now)
          Solid Air

          Do not have an answer for your first question, for the second you could write a macro and assign it to a shortcut key to do your "toggle"

          • Re: 2 Questions (for now)
            Kelvin Lamport

            Not a toggle, but you can use the Keyboard Shortcut utility to set the view mode.

            I have W set for Wireframe and E set for Shaded with Edges

              • Re: 2 Questions (for now)
                Anton Ivanov

                Hi Kelvin,

                I may have to have two keys for it. Even if I create a Macro I believe it will be a custom button on a tool bar and I am looking for a keyboard shortcut key.

                Thx !

                  • Re: 2 Questions (for now)
                    Solid Air

                    Unfortunately, you can assign a macro to a shortcut key.  Look in SolidWorks help under User Interface Customization for Macros.

                      • Re: 2 Questions (for now)
                        Mahir Abrahim

                        Why unfortunate? But yes, you can write a simple 5 line macro (minus declarations) that checks the current view state and toggles one way or the other.

                          • Re: 2 Questions (for now)
                            Solid Air

                            Unfortunate was probably the wrong word.  I apologize for using it.

                             

                            In my initial post, based on what Anton asked, the only way I could think of to do what he wanted was to write a macro.  I try very hard not to post answers that cannot be accomplished so I was taken back when it was posted that a macro could not be assigned to shortcut key.  I could have suggested as Kelvin did and assign them to two short cut keys.  I could also have suggested to add then to the S (shortcut) key.  Or I could have suggested they be assigned to a mouse gesture.  However, I think a macro still may be the best.

                             

                            Assigned to shortcut toolbar

                             

                            Assigned to mouse gestures (taken from SW2018 new 12 gestures setting)

                             

                            Assigning macro to key.

                            After SW2012 a macro can be located anywhere by clicking [ . . . ] button and fill in the blanks just like when assigning a macro to a toolbar button.

                             

                            Assigning macro to key.

                             

                            Here is the code.  Start a new macro then copy and paste.  Try and see if it works.  You will notice that I assigned the macro to the P key because the E key was assigned to another function.

                             

                            Dim swApp As SldWorks.SldWorks
                            Dim swDoc As SldWorks.ModelDoc2
                            Dim swDocActiveView As Object

                            Sub main()

                                Set swApp = Application.SldWorks
                                Set swDoc = swApp.ActiveDoc
                                Set swDocActiveView = swDoc.ActiveView
                               
                                If swDocActiveView.DisplayMode <> swViewDisplayMode_e.swViewDisplayMode_ShadedWithEdges Then
                               
                                    swDocActiveView.DisplayMode = swViewDisplayMode_e.swViewDisplayMode_ShadedWithEdges
                                   
                                Else

                                    swDocActiveView.DisplayMode = swViewDisplayMode_e.swViewDisplayMode_HiddenLinesGrayed

                                End If
                               
                                Set swApp = Nothing
                                Set swDoc = Nothing
                                Set swDocActiveView = Nothing

                            End Sub

                              • Re: 2 Questions (for now)
                                Mahir Abrahim

                                I think we're both confused. Unless something has changed since SW2016 (and well before that), I'm certain you can assign a keyboard shortcut to a macro. The only restriction is that the macro must first be assigned to a button. It doesn't matter where the button is. If I never intend on using the button, I'll usually drop it on some little used toolbar like Add-ins. After that you can assign a keyboard shortcut the normal way via Customize>Keyboard. I even think you can delete the button from the toolbar, and the keyboard shortcut will still work (not sure about this one).

                                  • Re: 2 Questions (for now)
                                    Solid Air

                                    Mahir,

                                     

                                    No confusion; you can assign a macro to a keyboard shortcut (sorry if I lead you to believe you could not).  No restrictions either.  From the SolidWorks menu you select Tools, Customize...  In the Customize dialog, you select the Keyboard tab along the top of the window. Then select Macros from the Category drop down.  The first entry in the list should be New Macro Button (inappropriately named in my opinion since you are assigning it to a key); select the ellipse button (one with three dots in it) to the right.  In the Customize Macro Button dialog, you select the ellipse button to the right of the Macro field.  Then in the Open dialog browse to the macro you want to assign to a key; select it then select the Open button.  Back in the Customize Macro Button, you select the method (which sub procedure to start the macro with).  No need to assign a icon or, fill in the Tooltip and Prompt fields.  Select OK to close the dialog.  Back in the Customize dialog you select the Shortcut cell to the right of your macro that is listed in the Command column.  After selecting a shortcut key, select OK to close.  Now you macro will run from a shortcut key

                                  • Re: 2 Questions (for now)
                                    Anton Ivanov

                                    Thank you for all example you have done. They are all very good for streamlining modeling. It is good to know that a macro can work as a keyboard shortcut. I was under the impression that macros are assigned to new buttons only. I will try the macro although I did it in two keyboard keys yesterday and that is how I have been using it. 

                                    • Re: 2 Questions (for now)
                                      Anton Ivanov

                                      I tried the macro and it worded like a charm. Than you. Was it hard to record it? I believe this was the only step that you did not outline - correct? Thanks again.

                                        • Re: 2 Questions (for now)
                                          Solid Air

                                          I spent some time looking through the API help but could not quickly come up with the correct calls.  So getting lazy, I recorded changing the display state from shaded with edges and hidden line visible.  But that only gave me the calls and one call I could not use for the way I wanted to write the code.  The rest of the code I wrote; I do not think I have every recorded a macro that adds if statements.  So yes I did not outline how I created the code as only some was recorded (swDocActiveView.DisplayMode) <- this was the only code I kept from the recorded).  Anyway, my intention was to only show how to assign a macro to a shortcut key not on how to write macros.

                              • Re: 2 Questions (for now)
                                Adam Humphries

                                HI Anton,

                                 

                                1. if it is possible to achieve the behaviour i am not sure how you would do that. the only recommendation i can make is just press escape once before you start a command. still an extra step but may be easier than a couple extra clicks

                                 

                                2.  Link below is old but content should still be good. runs through how to create keyboard shortcuts on solidworks.

                                Keyboard and Mouse Shortcuts in SolidWorks

                                 

                                Hope that helps

                                 

                                Adam

                                  • Re: 2 Questions (for now)
                                    Dave Dinius

                                    Question 1 - Another way to not have this behavior is to simply click  off of the part in the blank space of the work area. This is a habit of mine that I am always doing so without even thinking about doing it. True it is an extra step (like pressing the ESC key), do it enough and it becomes second nature.

                                  • Re: 2 Questions (for now)
                                    Mahir Abrahim

                                    I'm in agreement with everyone else. Either hit Esc or click a blank part of your model. You'll get used to it. Problem is pre-selection is a global behavior. Virtually EVERY feature works with pre-selection to some degree. It's easier to slightly modify your modeling behavior vs. figure out a way to change how the underlying software functions.