0 Replies Latest reply on Nov 16, 2017 5:57 AM by Alexander Schaaf

    Changing Subcomponents configuration causes SolidWorks window to freeze, Bug?

    Alexander Schaaf

      Hello all,

       

      when I faced the problem, that you cannot change the configuration of sub level assemblies components with

      Component.ReferencedConfiguration
      

      I have created an iterator function, that always ensures to use assemblies as new root while traversing:

          Protected Iterator Function TraverseComponents(__Component2 As Component2) As IEnumerable(Of Component2)
              Dim swChildComponents As Object() = DirectCast(__Component2.GetChildren, Object())
              Trace.WriteLine("TraverseComponents: " & __Component2.GetPathName & " <" & __Component2.ReferencedConfiguration & ">")
      
      
              For Each swChildComponent As Component2 In swChildComponents
      
      
                  Trace.WriteLine("swChildComponent.GetPathName returns: <" & swChildComponent.GetPathName & ">")
      
      
                  Select Case System.IO.Path.GetExtension(swChildComponent.GetPathName)
      
      
                      Case ".SLDASM"
                          Trace.WriteLine("     GetExtension Returns: " & System.IO.Path.GetExtension(swChildComponent.GetPathName))
                          Dim swAssemblyDoc As ModelDoc2 = swChildComponent.IGetModelDoc
                          If swAssemblyDoc IsNot Nothing Then
                              Dim __swConfiguration As Configuration = swAssemblyDoc.IGetConfigurationByName(swChildComponent.ReferencedConfiguration)
                              Dim __swRootComponent As Component2 = __swConfiguration.GetRootComponent3(True)
      
      
                              If __swRootComponent.IsRoot Then
                                  For Each __Component In TraverseComponents(__swRootComponent)
                                      Yield __Component
                                  Next
                              End If
                          End If
      
      
                  End Select
      
      
                  Trace.WriteLine("TraverseComponents Yield: " & swChildComponent.GetPathName & " <" & swChildComponent.ReferencedConfiguration & ">")
                  Yield swChildComponent
      
      
              Next
          End Function
      

       

      While the Function itself is working like a charm, it has one downside when changing configurations of components, the solidworks window freezes. I am not able to click anything. I need to make the SolidWorks window inactive and reactivate it, then I can continue work. In code I found a very dirty solution:

                          Dim procs As Process() = Process.GetProcessesByName("explorer")
                          For Each proc As Process In procs
                              'switch to process by name
                              WindowHelper.SetForegroundWindow(proc.MainWindowHandle)
                          
                           Next
      
                          Dim iSWFrame As Frame = CType(SwApp.Frame, Frame)
                          Dim frmSldWorksHandle As IntPtr = IntPtr.op_Explicit(iSWFrame.GetHWnd)
                          WindowHelper.SetForegroundWindow(frmSldWorksHandle)
      
      
      

      I Hope everyone is with me when I say, I don't want to use this code in Production environment. Can anyone reproduce this problem or maybe even has a solution?

       

      Thanks in Advance