6 Replies Latest reply on Sep 6, 2017 11:24 AM by Manikandan Babu

    Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled

    Frank Wu Frank Wu

      Hi All,

      anyone know the cause of this problem?

      0x80010105.png

        • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
          Amen Allah Jlili

          Isn't the VChildComp supposed to be an array of object[]? (for clarity reasons). A server fault means that some exception has been raised in the SOLIDWORKS code. There isn't a lot you can do about it. In one API example, the drawing component is selected before the component property is invoked. Perhaps you should try that.

           

          Can you paste your code and not an image (plus an example). No one would want to help if you're pasting code in an image.
          :
          Thanks,
          Amen.

          • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
            Alex Burnett

            Here's a bit of code that I got from this thread.

             

            See if adjusting your code to match the way this is getting the array of children objects works for you. I added line 25 below and it casts the item to a Component2 just fine.

             

            Sub ProcessDrawingComponent _
            ( _
            swApp As SldWorks.SldWorks, _
            swDraw As SldWorks.DrawingDoc, _
            swDrawComp As SldWorks.DrawingComponent, _
            sPadStr As String, _
            sChildrenOnSeparateLayers As Boolean _
            )
            
            
                Dim vDrawCompChildArr As Variant
                Dim vDrawCompChild As Variant
                Dim swDrawCompChild As SldWorks.DrawingComponent
                Dim swChildComp As SldWorks.Component2
                Debug.Print sPadStr & swDrawComp.Name
                
                ChangeComponentLayer swApp, swDraw, swDrawComp, swDrawComp.Name
                
                vDrawCompChildArr = swDrawComp.GetChildren
                
                If Not IsEmpty(vDrawCompChildArr) Then
                
                    For Each vDrawCompChild In vDrawCompChildArr
                    Set swDrawCompChild = vDrawCompChild
                    Set swChildComp = swDrawCompChild.Component
                    If sChildrenOnSeparateLayers = True Then
                        ProcessDrawingComponent swApp, swDraw, swDrawCompChild, sPadStr + " ", sChildrenOnSeparateLayers
                    End If
                    
                    Next
                End If
            
            
            End Sub
            
            • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
              Jacob Corder

              Ok.. So i remember a while ago i was having issues reading data from components from the drawing. My issues were because the components were loaded lightweight. this does not give you access to the custom properties, and also could be causing your issue.

               

              First make sure that SwDrawComp is not lightweight

               

              Dim SwInputComp as component2

              SwInputComp = SwDrawComp.Component

              if SwInputComp.IsLoaded = false then

                   Dim ADoc as assemblydoc    

                   Dim View as drawingview

                    View = SwDrawComp.View

                   Adoc = view.ReferencedDocument

                   ADoc.ResolveAllLightWeight

              End If

              If SwInputComp.IsLoaded then

                   ******************************************Now try your code here****************************************

                   wrap your code in a Try Catch statement.  Com exceptions aren't nearly as bad as AccessViolationExceptions.

                   Try

                       

                   Catch COE as System.Runtime.InteropServices.COMException

                   Catch Ex as exception

                   end try

              end if

              • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
                Frank Wu Frank Wu

                Hi, everybody!

                I used your code, but it did not work either.

                i tested several versions solidworks for this error:

                     Test1:solidworks2015 sp5 >>> Test result: direct collapse

                     Test2:solidworks2016 sp5 >>> no error, but can not work noramlly.i repaired bug                                   SPR954568 http://www.solidworks.com/sw/support/subscription/ServicePackMaintenanceNotes.html Solidworks API.

                                    1.png

                                 it looks have certain connectios with my problem.

                     Test3:solidworks2017 sp4.1>>>test result: no error, but can not work noramlly.

                 

                so, i think solidworks experts may aaware this bug, and remend it on version 2016 sp4, but they didn't solve it completely. i do not know if there are other ways to solve the fixed draft component from IDrawingComponent.

                if there are, pls share with me. thank you.

                 

                 

                ---Frank

                  • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
                    Jacob Corder

                    instead of using NewSelectionNotify which is fired only when a user makes a selection, possibly try it with

                    UserSelectionPostNotify.

                    I prefer the above method as it does not fire when items are selected by code

                    its worth a try.

                     

                    other options are to create a system.windows.forms.timer

                    on NewSelectionNotify start the timer

                    when the timer_tick occurs execute the code there.

                     

                    i have done this on several occations

                     

                    2 ways to do this

                    Add this to the top of the class as a local variable

                    Dim WithEvents NewSelectionTimer as system.windows.forms.timer

                     

                    Add this sub

                      Private Sub NewSelectionTimer_Tick(sender As Object, e As EventArgs) Handles NewSelectionTimer.Tick

                            NewSelectionTimer.Stop()

                            ****************************Execute code here***************************

                      End Sub

                     

                    **************************** Option 2*****************************

                    Function NewSelectionNotify as integer

                         Dim DoExecuteDelay as boolean = false

                     

                    ********************     Some logic to determine if the timer should be activated************************

                    if something then

                         DoExecuteDelay = true

                    end if

                    *****************Last Lines in this method********************

                         if DoExecuteDelay then

                              Dim NewSelTimer as system.windows.forms.timer

                              NewSelectionTimer = new system.windows.forms.timer

                              NewSelectionTimer.Interval = (Desired Milliseconds) use 300 or more

                              AddHandler NewSelectionTimer.Tick addressof me.NewSelectionTimer_Tick

                              'This will then fire to the below subroutine

                         end if

                    end function

                    Private Sub NewSelectionTimer_Tick(sender As Object, e As EventArgs)

                         try

                              Dim ThisTmr as system.windows.forms.timer

                              thistmr = sender

                              thistmr .Stop()

                              RemoveHandler thistmr.Tick addressof me.NewSelectionTimer_Tick

                         Catch Ex as exception

                     

                         End Try

                                ****************************Execute code here***************************

                    End Sub

                  • Re: Component Property (IDrawingComponent)  System.Runtime.InteropServices.COMException was unhandled
                    Manikandan Babu

                    Hi Frank

                     

                    Let try the attached code. Visual studio 2010,SolidWorks 2015 SP5

                     

                    For section view 2-2 and section view 3-3  we could not insert the model item with option of selected component  through manual itself.

                     

                    .

                     

                     

                    It supports the entire model only.

                     

                    So that i have changed API swImportModelItemsFromEntireModel = 0  for section view 2-2 and section view 3-3

                     

                    Output

                     

                    Thanks

                    Manikandan