14 Replies Latest reply on Apr 4, 2014 2:22 PM by Matthew Elgie

    Error when using swDocPART in VB.NET

    Matthew Elgie

      Could some one help me with understanding why this is erroring and what I can do to fix it? I tried leaving it out, but everytime I try to use the add-in it just crashes.

       

      This is taken directly from the Solidworks API Help, but there is no explenation is swdocPART is a place holder, or if it is different in newer versions of Visual Studio.

       

      And I am at a loss on how to fix this, nor can I locate any posts really covering this.

       

      2014-04-03_16-10-25-338.png

      2014-04-03_16-09-50-216.png

       

      Imports SolidWorks.Interop.sldworks
      Imports SolidWorks.Interop.swconst
      Imports SolidWorks.Interop
      
       Module OpenPrt
          Dim swApp As SldWorks
          Dim swModel As ModelDoc2
          Dim swSelMgr As SelectionMgr
          Dim swDocSpecification As DocumentSpecification
          Dim sName As String
          Dim longstatus As Long, longwarnings As Long
      
      
          Dim Control1 As UserControl1
          Dim sLocation As String
      
      
          Sub OpenStrtPrt()
              swApp = New SldWorks
              sLocation = Control1.StartParts1.SelectedValue
      
      
              swDocSpecification = swApp.GetOpenDocSpec(sLocation)
              sName = swDocSpecification.FileName
              swDocSpecification.DocumentType = swDocPART
              swDocSpecification.ViewOnly = False
              swDocSpecification.Silent = True
      
      
              swModel = swApp.OpenDoc7(swDocSpecification)
              longstatus = swDocSpecification.Error
              longwarnings = swDocSpecification.Warning
          End Sub
      
      
      End Module
      
      
        • Re: Error when using swDocPART in VB.NET
          Artem Taturevych

          Try

           

          swDocSpecification.DocumentType = swDocumentTypes_e.swDocPART

          ______________________________________________

          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ

           

          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

            • Re: Error when using swDocPART in VB.NET
              Matthew Elgie

              That took away the Error in my code. but it is still crashing.

               

              I looked at my output file and saw this:

               

              "at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</ExceptionString></Exception></TraceRecord>

              The program '[4108] SldWorks.exe' has exited with code 1 (0x1)."

               

              I can't find any direct infor on debugging this though.

               

              I am thinking has something to do with having my Add-in connect with Solidworks.

                • Re: Error when using swDocPART in VB.NET
                  Artem Taturevych

                  You need to identify what exactly the line which crashing SW. You can also try to use ISldWorks::OpendDoc6 instead of OpenDoc7.

                    • Re: Error when using swDocPART in VB.NET
                      Matthew Elgie

                      Alright-

                       

                      So what it looks like is it crashes on

                       

                      sLocation = Control1.StartParts1.SelectedValue

                       

                      The location is being pulls from a Combo box that is connecting to a simple SQL server on my computer.

                       

                      Do SW Task Pane Add-ins have issues with connecting to a SQL sever to get pathing?

                        • Re: Error when using swDocPART in VB.NET
                          Artem Taturevych

                          Put this line in try-catch block and make sure that Control1 and StartPrats1 are not NULL

                            • Re: Error when using swDocPART in VB.NET
                              Matthew Elgie

                              Is this what I am looking for from the Try-Catch block?

                               

                              A first chance exception of type 'System.NullReferenceException' occurred in Solidworks VB.Net Addin Test.dll

                                • Re: Error when using swDocPART in VB.NET
                                  Artem Taturevych

                                  Yes, it says that some of your variables is Null

                                    • Re: Error when using swDocPART in VB.NET
                                      Matthew Elgie

                                      Okay, so I did some testing with it.

                                       

                                      I have a msg box that showed the file path straight from the form

                                       

                                      Public Class UserControl1

                                          Private Sub On_Load(sender As Object, e As EventArgs) Handles MyBase.Load

                                              'TODO: This line of code loads data into the 'Start_Part_TestingDataSet.Start_Parts' table. You can move, or remove it, as needed.

                                              Me.Start_PartsTableAdapter.Fill(Me.Start_Part_TestingDataSet.Start_Parts)

                                          End Sub

                                       

                                          Dim swApp As sldworks.SldWorks

                                       

                                          Private Sub Create1_Click(sender As Object, e As EventArgs) Handles Create1.Click

                                              MsgBox(StartParts1.SelectedValue)

                                          End Sub

                                       

                                      And then tried so use that one, vs the msg box in the Module:

                                       

                                      Dim Control1 As UserControl1

                                         Dim sLocation As String

                                       

                                      Sub OpenStrtPrt()

                                       

                                              sLocation = Control1.StartParts1.SelectedValue

                                       

                                              MsgBox(sLocation)

                                       

                                          End Sub

                                       

                                      ____________

                                       

                                      The first Displays the File path fine:

                                      2014-04-03_19-29-10-094.png

                                       

                                      The 2nd crashed Solidworks.

                                       

                                      I was thinking maybe I need to pass the information through a text box. The idea being that the text box can display the path to ensure tha the value is there, and then pass it to the module from there. But I can't figure out how to have the text box outfill with the file path.

                                      • Re: Error when using swDocPART in VB.NET
                                        Matthew Elgie

                                        Nope still crashes.

                                         

                                        So it seems the information isn't passing between my Form to my Module?

                                         

                                        Any clue as to why?

                                         

                                        Here is my form for reference:

                                        Imports System.Runtime.InteropServices

                                        Imports SolidWorks.Interop

                                        Imports System.Data.SqlClient

                                         

                                         

                                        <ComVisible(True)> _

                                        <ProgId("Solidworks_VB.Net_Addin_Test")> _

                                        Public Class UserControl1

                                         

                                          Private Sub On_Load(sender As Object, e As EventArgs) Handles MyBase.Load

                                                'TODO: This line of code loads data into the 'Start_Part_TestingDataSet.Start_Parts' table. You can move, or remove it, as needed.

                                                Me.Start_PartsTableAdapter.Fill(Me.Start_Part_TestingDataSet.Start_Parts)

                                            End Sub

                                         

                                             Dim swApp As sldworks.SldWorks

                                         

                                              Private Sub Create1_Click(sender As Object, e As EventArgs) Handles Create1.Click

                                                Call OpenStrtPrt()

                                            End Sub

                                         

                                              Friend Sub getSwApp(ByRef swAppIn As sldworks.SldWorks)

                                                swApp = swAppIn

                                            End Sub

                                         

                                             Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

                                              End Sub

                                            

                                              Private Sub StartParts1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles StartParts1.SelectedIndexChanged

                                              End Sub

                                            

                                              Private Sub Run1_Click(sender As Object, e As EventArgs) Handles Run1.Click

                                                TextBox1.Text = StartParts1.SelectedValue

                                            End Sub

                                            

                                              Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

                                             End Sub

                                               

                                             Public Sub New()

                                                InitializeComponent()

                                            End Sub

                                          End Class