7 Replies Latest reply on Jan 17, 2017 9:54 AM by Jana Fischer

    unlock design table after a call of SetConfigurationParams

    Jana Fischer

      I made a VBA macro that suppresses a component of an assembly via IConfigurationManager.SetConfigurationParams.

      Here is the code (I also attached it):

       

      -------------------

       

      Sub main()

       

      Dim swApp As SldWorks.SldWorks

      Dim activeDoc As ModelDoc2

      Dim assyDoc As AssemblyDoc

      Dim vComponents As Variant

      Dim swComp As Component2

      Dim compNameInstance As String

      Dim key(0) As String

      Dim vKeys As Variant

      Dim val(0) As String

      Dim vVals As Variant

      Dim swConfMgr As SldWorks.ConfigurationManager

      Dim swConf As SldWorks.Configuration

      Dim confName As String

      Dim success As Boolean

       

      Set swApp = Application.SldWorks

      Set activeDoc = swApp.activeDoc

      Set assyDoc = activeDoc

       

      vComponents = assyDoc.GetComponents(True)

      Set swComp = vComponents(0)

      compNameInstance = swComp.Name2

      compNameInstance = Replace(compNameInstance, "-", "<") + ">"

       

      key(0) = "$state@" + compNameInstance

      val(0) = "S"

      vKeys = key

      vVals = val

       

      Set swConfMgr = activeDoc.ConfigurationManager

      Set swConf = swConfMgr.ActiveConfiguration

       

      confName = swConf.Name

      success = swConfMgr.SetConfigurationParams(confName, vKeys, vVals)

       

      Debug.Print "success? -> "; success

      End Sub

       

      --------------

       

      It does what it should do, BUT: After it was run, it is not possible to unsuppress the component by hand. If I try, I get this:

      designTableLocked.png

      This happens for all assemblies I tried so far - no matter if they have a design table or not. I attached two of them.

       

      I have tried some things regarding the design table:

       

      Get it via IModelDoc2.GetDesignTable().

      Check if it is null. => Always false.

      Check if it is active (IDesignTable.IsActive()). => Always false.

      Check if it is updatable (IDesignTable.Updatable). => Always true.

      Update it and check if updating was successful (IDesignTable.UpdateTable(2, true)). => Always successful (true).

      Delete the Design Table (IModelDoc2.DeleteDesignTable).

       

      Nothing solves the problem.

      Any ideas or hints?

       

       

      PS: This problem seems to be quite old (check Problem with DesignTable and ConfigurationManager  )...

        • Re: unlock design table after a call of SetConfigurationParams
          Nilesh Patel

          Hi Jana,

           

          If your aim to just suppress the component in the assembly then try IComponent2.SetSuppression method.

           

          Regards,

          • Re: unlock design table after a call of SetConfigurationParams
            Elmar Klammer

            You need to reset the edit control setting to "allow ..."

             

              • Re: unlock design table after a call of SetConfigurationParams
                Jana Fischer

                Unfortunately, this doesn't solve the problem...

                 

                1. Your suggestion only works for models that have a design table (which is seldomly the case).

                2. If the design table had been set to "block model edits" before calling the macro, we still get this lock. But I do not want to touch any setting of the design table at all, so I cannot change it to "allow model edits".

                3. The design table is still open in the background after the macro call. This can be seen from the fact that

                   a) if there was no design table before the macro call, we cannot insert a design table after the macro call (it is greyed out).

                   b) if there was a design table before the macro call, we cannot open the design table after the macro call. And if we try to delete it, SolidWorks crashes (at least SolidWorks 2015).

                 

                Fact 3 is still present after I change the edit control setting to "allow model edits". I am looking for a way to completely get out of this strange/intermediate/buggy state.

                  • Re: unlock design table after a call of SetConfigurationParams
                    Nilesh Patel

                    Hi Jana,

                     

                    Add following codes after: 'Debug.Print "success? -> "; success' in your macro.

                     

                    If activeDoc.Extension.HasDesignTable Then      'If the active doc has design table.
                    
                    
                        Set swDesTable = activeDoc.GetDesignTable   'Gets the design table (where swDesTable as SldWorks.DesignTable).
                        
                        If Not swDesTable Is Nothing Then           'If the design table is found.
                            
                            'Allow changes to the characteristics of the design table
                            swDesTable.EditFeature
                            
                            'Prints the updatable status of the design table.
                            Debug.Print "Design table updatable: " & swDesTable.Updatable
                            
                            'If design table is un-updatable then changes the status to 'TRUE' to allow the model to update the design table.
                            If swDesTable.Updatable = False Then swDesTable.Updatable = True
                        
                            ' Update this characteristic of the design table & prints new updatable status of the design table.
                            If swDesTable.UpdateFeature() Then Debug.Print "Design table updatable: " & swDesTable.Updatable
                    
                    
                        End If
                        
                    End If
                    

                     

                    These codes unlocks the design table (basically allows the model to update the design table). I have tested these codes on both of your models and works OK. You can un-suppress the component after the macro is run and vise-versa.

                     

                    You may get the following warning message which you can hide, so that it won't appear in the future.

                     

                     

                    Hope this helps.

                     

                    Regards,

                    • Re: unlock design table after a call of SetConfigurationParams
                      Jana Fischer

                      My colleague found a way to solve problem 3.

                      Insert the following code between "Debug.Print "success? -> "; success" and "End Sub":

                       

                          Dim tempConfigName

                          Dim tempConf As Configuration

                       

                          tempConfigName = "tempConfigNameThatNoOneUses"

                          Set tempConf = activeDoc.AddConfiguration3(tempConfigName, "", "", 0)

                          success = activeDoc.ShowConfiguration2(confName)

                          success = activeDoc.DeleteConfiguration2(tempConfigName)

                       

                      So we create a new configuration, switch to it, switch back and delete the new configuration.

                       

                      BUT there are two new problems:

                      a) Before calling the macro, if a design table was present, we could right-click on it to access it:

                      designTableAccessible.png

                      But after calling the macro, we can no longer access it by right-click (I don't know if we can access it in some other way):

                      designTableUnlockedButInaccessible.png

                      b) Creating, switching and deleting configurations is SLOW! This eliminates the performance benefits of using SetConfigurationParams completely!

                       

                       

                      There must be another way! (I hope.)