5 Replies Latest reply on Jun 4, 2015 10:11 AM by Danny Bradford

    API no longer functioning in SW 2015

    Danny Bradford

      Greetings,

       

      We recently moved from SW 2013 SP02 to SW2015 SP02 and have a problem with a fairly simple API:

       

              swapp = GetObject(, "SldWorks.Application")

              Doc = swapp.ActiveDoc

              DocExt = Doc.Extension

              CustProp = DocExt.CustomPropertyManager("")

       

              Title = Doc.GetTitle

       

              txtDocNumber.Text = Doc.CustomInfo2("", "Number").ToUpper

       

       

       

      This code pulls the attributes from the Solidworks part and populates a form. It is a Custom Properties tool.

       

      This functioned fine in the previous version but now nothing.

       

      Any assistance or enlightenment would be most appreciated!

       

      Danny Bradford

        • Re: API no longer functioning in SW 2015
          Deepak Gupta

          Try these codes and if they work, then you can modify as required.

           

          Sub main()

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim Value As String

                 

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc   

              Value = swModel.CustomInfo2("", "NUMBER")

              Debug.Print UCase(Value)               

          End Sub

          • Re: API no longer functioning in SW 2015
            Josh Brady

            First, I assume you are using .NET VSTA macros, not VBA, right?

             

            Next, you are getting the custom property manager, but not using it to get the custom property.  CustomInfo2 is a really, really old API.  Not that it doesn't work, but the CustomPropertyManager is the newer, more powerful/flexible way to get to them.

             

            Looks like you've pulled single lines out of a longer program there.  Are these the specific lines that give you errors now that didn't in 2013?

              • Re: API no longer functioning in SW 2015
                Danny Bradford

                Yes on all points. Below is the complete code up to the part that is not working.

                 

                In fact after reading your post I realized that the code did utilize custompropertymanager but then called Custominfo2! Ha!

                 

                I have made the move to a Get but it still does not work. Also, the Msgbox does not work either. It does not even come up so there must be something else wrong. This tool does properly update the property of the part so I know it is working in general.

                 

                Private Sub UserForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

                        Dim swapp As SldWorks

                        Dim Doc As ModelDoc2

                        Dim CustProp As CustomPropertyManager

                        Dim DocExt As ModelDocExtension

                        Dim val As String = ""

                        Dim valout As String = ""

                        Dim boolstatus As Boolean

                        Dim Title As String

                        Dim i As Integer = 0

                        Dim j As Integer = 0

                 

                       swapp = GetObject(, "SldWorks.Application")

                        Doc = swapp.ActiveDoc

                        DocExt = Doc.Extension

                        CustProp = DocExt.CustomPropertyManager("")

                 

                        Title = Doc.GetTitle

                 

                        MsgBox("This is the Doc Number:  " & CustProp.Get("Number") & "  " & CustProp.Count)

                        txtDocNumber.Text = CustProp.Get("Number")

                        txtDescription.Text = Doc.CustomInfo2("", "TITLE1").ToUpper

                  • Re: API no longer functioning in SW 2015
                    Simon Turner

                    You aren't doing any checks for things like there not being an active document.

                    It's possible that GetObject is connecting to a background session of SolidWorks where there is no document open.

                    Put some checks in like::

                    If Doc Is Nothing Then

                         swApp.SendMsgToUser2("No active document.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk)

                         Exit Sub

                    End If

                     

                    and check if it's a part/assembly or drawing:

                     

                    If Doc.GetType <> 1 Then

                         swApp.SendMsgToUser2("No active PART document.", swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk)

                         Exit Sub

                    End If