10 Replies Latest reply on Jun 17, 2016 8:06 PM by Neil Jackson

    Automatic Macro Recording?

    Todd Carpenter

      I've got an assembly with a design table attached, several equations, and custom properties associated with it.  All of a sudden, when opening the assembly, I get a VBA Macro  Type mismatch error.  I'm guessing this has something to do with the design tables/equations/custom properties but I'm not sure where this macro is coming from - if you notice the date, that happens every time.  I can't find where SolidWorks is being told to do this - can somebody tell me where I would look?  I'm particularly confused by the "No output File...", but this is what makes me think it's something to do with the design table.  Here's the macro it tries to record, and the line it errors on is EvaluateDouble = "2.Part" - 5th line from the bottom:

       

      ' ******************************************************************************
      ' No output File - macro recorded on 07/15/15 by tcarpenter
      ' ******************************************************************************
      Option Explicit
      Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
      Private pi As Double
      Dim Part As Object
      Dim Assembly As Object
      Dim swApp As Object
      Function vbStringFromByteArray(ByRef arr) As String
         Dim numbytes, i
         numbytes = UBound(arr) + 1
         Dim byteArray() As Byte
         ReDim byteArray(numbytes)
         For i = 0 To numbytes - 1
            byteArray(i) = arr(i)
         Next i
         vbStringFromByteArray = String$(numbytes / 2 - 1, 0)
         CopyMemory ByVal StrPtr(vbStringFromByteArray), byteArray(0), numbytes
      End Function
      Sub main()
      On Error GoTo errorHandlerSW
      EvaluationError = 0
      Set swApp = Application.SldWorks
         Dim modelName As String ' C:\TDCI3D\Fabco\L_S.SLDASM
         modelName = vbStringFromByteArray(Array(67, 0, 58, 0, 92, 0, 84, 0, 68, 0, 67, 0, 73, 0, 51, 0, 68, 0, 92, 0, 70, 0, 97, 0, 98, 0, 99, 0, 111, 0, 92, 0, 76, 0, 95, 0, 83, 0, 46, 0, 83, 0, 76, 0, 68, 0, 65, 0, 83, 0, 77, 0, 0, 0))
      pi = 4 * Atn(1)
      Set Assembly = swApp.ActiveDoc
      If Assembly.GetType = 2 Then Set Assembly = Assembly.GetEditTarget
      If Assembly.GetType = 3 Then Set Assembly = swApp.GetOpenDocumentByName(modelName)
      Dim PartName As String
      If Assembly.GetPathName <> "" Then PartName = Assembly.GetPathName Else PartName = Assembly.GetTitle
      If Assembly.IsEditingSelf And PartName <> modelName Then Set Assembly = swApp.GetOpenDocumentByName(modelName)
      EvaluateDouble = "2.Part"
      Exit Sub
      errorHandlerSW:
      Evaluation
      Error = Err.Number
      End Sub
      

      Thanks