3 Replies Latest reply on Oct 31, 2012 4:22 PM by Aj Jones

    A Couple Of Debugging Questions In VB.NET

    Aj Jones

      I'm copying code from a VB Macro I wrote and putting it into vb.net using MS VS 2012 Express.  I went through a lot of the macros made by SolidWorks and then once I got certain things to work in .NET, I tried converting the whole code. A lot of the errors I have been able to fix, but a few things I still have questions on, and I was wondering if anyone knew what needs to be fixed.

       

      The two things I have imported into the project are:

      Imports SolidWorks.Interop.sldworks

      Imports SolidWorks.Interop.swconst

       

      --- For one thing, anything with   swApp = Application.SldWorks   seemed to error out.  From the looks of it, and looking at other VB.NET code this is not needed in VB.NET correct?

       

      ---  When selecting a plane the "swThisConfiguration, Empty" part gets an error stating it is not declared and that it may be inaccessible due to its protection level.

       

      boolstatus = swModelDocExt.SelectByID2("FrontPlane@" & PartName, "PLANE", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)

      swDim = swModel.Parameter("D1@CL OF FRONT OR@" & PartName & ".SLDASM")

      dimValue = swDim.GetSystemValue3(swThisConfiguration, Empty)

       

      --- When checking that the document is an assembly I get an error for the <> part of the document "Overload resolution failed because no accessible '<>' can be called within these arguments

      If Model.GetType <> swDocASSEMBLY Then

       

      Also getting errors for anything ending with "Empty" saying System.Empty is not accessible in this context because it is 'Friend'.

      Part.Extension.RunCommand(swCommands_SaveAs, Empty)

       

      Thanks

        • Re: A Couple Of Debugging Questions In VB.NET
          Michael Jeffries

          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

          --- For one thing, anything with   swApp = Application.SldWorks   seemed to error out.  From the looks of it, and looking at other VB.NET code this is not needed in VB.NET correct?

           

          Use the following instead of "swApp = Application.SldWorks:

           

          swApp = New Sldworks.Sldworks

           

          or

           

          swApp = CreateObject("Sldworks.Application")    'Though I prefer the New Sldworks method

           

          >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

           

          --- When checking that the document is an assembly I get an error for the <> part of the document "Overload resolution failed because no accessible '<>' can be called within these arguments

          If Model.GetType <> swDocASSEMBLY Then

           

          Try the following:

           

          1)

           

          If Model.GetType <> swdocumenttypes_e.swDocASSEMBLY Then

           

          2) This is my preferred method, as it allows for more flexibility and cleans the code up, you don't have to call all 3 out, but it doesnt hurt (in case you need to access them later)

           

          Select Case Model.GetType

               Case swdocumenttypes_e.swDocASSEMBLY

                    'Do Something

               Case swDocumentTypes_e.swDocPART

                    'Do Something

               Case swDocumentTypes_e.swDocDRAWING

              

               case else

          end select


            • Re: A Couple Of Debugging Questions In VB.NET
              Michael Jeffries

              I typically create a module and add the following subroutine(s) to ensure that solidworks is loaded, and that it has the most recent active document reference (copied and pasted from my module).  Before most operations, I'll call the LoadActiveModel() sub to make sure the reference is set and up to date:

               

              Imports SldWorks

              Imports SwConst

               

              Public Class Module_swCustom

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As ModelDoc2

                  Dim swDraw As DrawingDoc

                  Dim swPart As PartDoc

                  Dim swAsm As AssemblyDoc

               

                  ''' <summary>

                  '''Sets the Active Object Model Reference

                  ''' </summary>

                  ''' <remarks></remarks>

                  Sub LoadActiveModel()

                      Select Case swApp Is Nothing

                          Case True

                              swApp = New SldWorks.SldWorks

                      End Select

                      swModel = swApp.ActiveDoc

               

                      Select Case swModel.GetType

                          Case swDocumentTypes_e.swDocDRAWING

                              swDraw = swModel

                          Case swDocumentTypes_e.swDocPART

                              swPart = swModel

                          Case swDocumentTypes_e.swDocASSEMBLY

                              swAsm = swModel

                          Case swDocumentTypes_e.swDocNONE

                              'Nothing

                      End Select

                  End Sub

               

              end class