4 Replies Latest reply on Sep 10, 2018 2:03 AM by ZhongYu Hao

    How to cerat a part from API

    ZhongYu Hao

      Hello guys,

      I just started learning SW API

      And how to creat a New part ,assembly and drawing ,use API.

      That is my code,but it is still not work.

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

      Imports SolidWorks.Interop.sldworks
      Imports System

      Public Class Form1
          Private swApp As Object
          Private swDocumentTypes_e As Object
          Private swOpenDocOptions_e As Object

          Sub Main()

              Dim swApp As SolidWorks.Interop.sldworks.SldWorks

              swApp = New SolidWorks.Interop.sldworks.SldWorks()

              swApp.ExitApp()

              swApp = Nothing

          End Sub

          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
              Dim swModel As ModelDoc2
              Dim swPart As PartDoc
              Dim swBody As Body2
              Dim nPt() As Double
              Dim vPt As Object
              Dim bRet As Boolean

              swModel = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2015\templates\part.prtdot", 0, 0, 0)
              swPart = swModel
              swBody = swPart.CreateNewBody

          End Sub

      End Class

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

        • Re: How to cerat a part from API
          Deepak Gupta

          Check and make sure that your part template path is correct. If not then change this path "C:\ProgramData\SolidWorks\SolidWorks 2015\templates\Part.prtdot" to correct location/path.

           

          • Re: How to cerat a part from API
            ZhongYu Hao

            I change this path is correct.but VS show me an error.

             

             

            捕获.jpg

              • Re: How to cerat a part from API
                Mr Omkar Deshpande

                Try

                 

                Imports SolidWorks.Interop.sldworks

                Imports System

                 

                Public Class Form1

                    Dim swApp As SldWorks

                    Private swDocumentTypes_e As Object

                    Private swOpenDocOptions_e As Object

                 

                    Sub Main()

                 

                        'Dim swApp As SolidWorks.Interop.sldworks.SldWorks

                 

                        'swApp = New SolidWorks.Interop.sldworks.SldWorks()

                 

                        'swApp.ExitApp()

                 

                        'swApp = Nothing

                 

                    End Sub

                 

                    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

                        Dim swModel As ModelDoc2

                        Dim swPart As PartDoc

                        Dim swBody As Body2

                        Dim nPt() As Double

                        Dim vPt As Object

                        Dim bRet As Boolean

                 

                        swModel = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2015\templates\part.prtdot", 0, 0, 0)

                        swPart = swModel

                        swBody = swPart.CreateNewBody

                 

                    End Sub

                 

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

                 

                 

                        swApp = New SolidWorks.Interop.sldworks.SldWorks()

                 

                        swApp.Visible = True

                 

                    End Sub

                End Class

                 

                 

                Also, check your path of template

                  • Re: How to cerat a part from API
                    ZhongYu Hao

                    Thank you very much!!

                    That is Correct Answer!!!

                     

                    I lost this

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

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

                             swApp = New SolidWorks.Interop.sldworks.SldWorks()

                             swApp.Visible = True

                         End Sub

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