6 Replies Latest reply on Jul 19, 2018 10:00 AM by Peter Cranshaw

    Enable/Disable Feature Recognition

    Elliott Grier

      Is there an API that will enable toggling of the "Prompt for feature recognition as part opens" option?

       

      How to activate "Recognize Features"

        • Re: Enable/Disable Feature Recognition
          Amen Allah Jlili

          How about enabling and disabling the add-in?

           

          Cheers,
          Amen
          SOLIDWORKS API and PDM API Training and Services

          • Re: Enable/Disable Feature Recognition
            Amen Allah Jlili

            How are you opening the file? I bet you are not using LoadFile4.

            Cheers,
            Amen
            SOLIDWORKS API and PDM API Training and Services

            • Re: Enable/Disable Feature Recognition
              Peter Cranshaw

              I am trying to get an answer for this as well.

               

              So far I have been looking for and answer in the documentation with no luck,

               

              I haven't got an answer yet. But I did think of something to focus my searching.

               

              Last week it occurred to me to use Solidworks "Macro Record" feature to do it manually and read the code in the created macro.

               

              I did it twice.  Once to turn on the "Prompt for feature recognition as part opens" and once to turn it off.

               

              The only significant difference I can see between the two files is the line...

               

              retval = swApp.Callback("fworks@FWPlaybackManager", 0, "SetExtractFeaturesOnOpenPart 1")

               

              I believe that is the key value we need for focus on for our goals. I haven't tried put this line in any of my code yet.  I would also like to be able to extract the original value and save it so I can reset it back the original value at the end of my sub.

               

              I'll keep looking.

               

              Pete

                • Re: Enable/Disable Feature Recognition
                  Simon Turner

                  To get the current value, read it out of the registry key

                  HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2018\FeatureWorks\General\ExtractFeaturesOnOpenPart

                   

                  Set it using the code you posted:

                  retval = swApp.Callback("fworks@FWPlaybackManager", 0, "SetExtractFeaturesOnOpenPart 1")

                  or

                  retval = swApp.Callback("fworks@FWPlaybackManager", 0, "SetExtractFeaturesOnOpenPart 0")

                    • Re: Enable/Disable Feature Recognition
                      Peter Cranshaw

                      Simon,

                       

                      Thank you very much for your suggestion.  Here's what I came up with t solve the problem....

                       

                       

                      ' For the Full Registry Key Routines..

                      ' See https://vba-corner.livejournal.com/3054.html

                       

                      ' Many thanks to Simon Turner for pointing me to this.

                       

                      '--------------------------------------------------------------'

                      'Reading from the Registry:                                    '

                      '--------------------------------------------------------------'

                      'reads the value for the registry key i_RegKey

                      'if the key cannot be found, the return value is ""

                      Function RegKeyRead(i_RegKey As String) As String

                      Dim myWS As Object

                        On Error Resume Next

                        'access Windows scripting

                        Set myWS = CreateObject("WScript.Shell")

                        'read key from registry

                        RegKeyRead = myWS.RegRead(i_RegKey)

                      End Function

                       

                      '--------------------------------------------------------------'

                      'Saving a Registry key:                                        '

                      '--------------------------------------------------------------'

                      'sets the registry key i_RegKey to the

                      'value i_Value with type i_Type

                      'if i_Type is omitted, the value will be saved as string

                      'if i_RegKey wasn't found, a new registry key will be created

                      Sub RegKeySave(i_RegKey As String, _

                                     i_Value As String, _

                            Optional i_Type As String = "REG_SZ")

                        Dim myWS As Object

                        'access Windows scripting

                        Set myWS = CreateObject("WScript.Shell")

                        'write registry key

                        myWS.RegWrite i_RegKey, i_Value, i_Type

                      End Sub

                       

                       

                      Sub Main()

                          Dim swApp As SldWorks.SldWorks

                          Dim OldFtrStr As String

                          Dim arr() As String

                          Dim SWVersion As String

                          Dim SWRegKeyValue As String

                       

                          ' Get the basic Solidworks Object

                          Set swApp = Application.SldWorks

                       

                          ' Create the string use for the Registration Key

                          arr = Split(swApp.RevisionNumber, ".")

                          SWVersion = arr(0) + 1992

                          SWRegKeyValue = "HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS " & _

                                          SWVersion & _

                                          "\FeatureWorks\General\ExtractFeaturesOnOpenPart"

                                         

                          ' Save the existing value of the "ExtractFeaturesOnOpenPart" value in the registry

                          OldFtrStr = RegKeyRead(SWRegKeyValue)

                         

                          ' Turn the "Prompt for feature recognition as part opens" option off in FeatureWorks

                          ' to prevent it from interupting the program.

                          RegKeySave SWRegKeyValue, "0", "REG_DWORD"

                       

                       

                      '----------------------------------------------------------------------------------------'

                      '                                                                                        '

                      '                              Your code goes here                                       '

                      '                                                                                        '

                      '----------------------------------------------------------------------------------------'

                       

                          ' Restore the saved value of "ExtractFeaturesOnOpenPart"

                          RegKeySave SWRegKeyValue, OldFtrStr, "REG_DWORD"

                         

                          End

                      End Sub