1 Reply Latest reply on Feb 25, 2014 4:58 PM by Artem Taturevych

    Automation Error

    Evan Heyes

      Hello,

       

      I am currently getting an automation error when trying to run the following code.

       

      My intention is to eventually open each part/assembly and automatically take in data from excel and add it into the configuration properties. Currently I have a component array which seems to be filled, but whenever I try and call a method with a defined index it throws an automation error of the form.

       

      Run-Time error '(9 Digit Number)(f(7 Digit Number)'

      Automation Error

       

      I think this is a variable type issue but I have not been able to track down the problem, any help would be appreciated.

       

      Dim swApp As SldWorks.SldWorks

      Dim FirstDoc As SldWorks.ModelDoc2

      Dim FirstAssembly As SldWorks.AssemblyDoc

      Dim SecDoc As SldWorks.ModelDoc2

      Dim Test As String

      Dim Parts() As SldWorks.Component2

      Dim CompCnt As Integer

       

      Sub main()

       

       

      Set swApp = Application.SldWorks

      Set FirstDoc = swApp.ActiveDoc

      Set FirstAssembly = FirstDoc

       

      Parts = FirstAssembly.GetComponents(False)

      CompCnt = UBound(Parts)Debug.Print CompCnt

          Set SecDoc = Parts(1).GetModelDoc2: Debug.Assert Not Parts(1) Is Nothing

        • Re: Automation Error
          Artem Taturevych

          Change the red line.

           

          Dim swApp As SldWorks.SldWorks

          Dim FirstDoc As SldWorks.ModelDoc2

          Dim FirstAssembly As SldWorks.AssemblyDoc

          Dim SecDoc As SldWorks.ModelDoc2

          Dim Test As String

          Dim Parts As Variant

          Dim CompCnt As Integer

           

          Sub main()

           

          Set swApp = Application.SldWorks

          Set FirstDoc = swApp.ActiveDoc

          Set FirstAssembly = FirstDoc

           

          Parts = FirstAssembly.GetComponents(False)

          CompCnt = UBound(Parts)

          Debug.Print CompCnt

          Set SecDoc = Parts(1).GetModelDoc2 : Debug.Assert Not Parts(1) Is Nothing