3 Replies Latest reply on May 11, 2016 3:49 AM by Mario Zahren

    Writing a variable value within a Task (EPDM)

    Mario Zahren

      Hello all,

       

      I want to write a value into a datacard field during Task execution (Convert Task -> SolidWorks Drawint to DWG)

      For debugging I copied the code, using "debug.assert False",  from the Task into SolidWorks VBA-Editor.

      Unfortunately I can´t figure out how to do that. I can not find a solution for "setvar" in VBA.

      Can anybody help?

      Cheers Mario

       

      The code I use so far:

       

       convFileName = ParseFilename(docFileName, convFileName)
      
          convFilePath = Left(convFileName, InStrRev(convFileName, "\"))
          CreatePath convFilePath
          convFileName = convFileName & ext
          'Dateiname DWG verfügbar "convFileName"
          'Call Function
          VarValueCustExt = SetVariableValue(convFileName, "Conf2", "Model", VarValueCustExt)
      
      Private Function SetVariableValue(FilePath, VariableName, Configuration, VarValueCustExt)
      
          Call LoginToVault
          
          On Error GoTo ErrHand
      
          Dim File As Object
          Dim Folder As Object
      
          Set File = vault.GetFileFromPath
      
          Dim pEnumVar As Object
      
          Set pEnumVar = File.GetEnumeratorVariable
      
          pEnumVar.SetVar(VariableName, Configuration, VarValueCustExt, False)
      
      
          'Dim value As Variant
      
          If pEnumVar.SetVar(VariableName, Configuration, VarValueCustExt) Then
              Set SetVariableValue = VarValueCustExt
          Else
               SetVariableValue = ""
          End If
      
          Exit Sub
      
      ErrHand:
              Dim ename As String
              Dim edesc As String
      
              vault.GetErrorString Err.Number, ename, edesc
              Log "GetvariableValue error" & vbCrLf & ename & vbCrLf & errdesc
      End Function
      
      
        • Re: Writing a variable value within a Task (EPDM)
          Mario Zahren

          OK, I modified the Code as shown. In Debugmode in SolidWorks it works fine. Unfortunately not in EPDM-Task...

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

          Thats the Error Code:

          GetvariableValue error

          0x5B

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

          I realy need help.

           

          Call Function:

          'Call Function   
           ...
              VarValueCustExt = SetVariableValue(convFileName, "Conf2", "Model", VarValueCustExt)
          
              KillHolder convFilePath
              KillHolder convFilePath2
             
              If docType = swDocASSEMBLY Then
                  Dim vComponents As Variant
                  Set swAssembly = swModel
          
                  vComponents = swAssembly.GetComponents(True)
          
                  If Not IsEmpty(vComponents) Then
                    For i = 0 To UBound(vComponents)
                        Dim swComponent As SldWorks.Component2
                        Set swComponent = vComponents(i)
          
                        If swComponent.IsVirtual Then
                            Convert swComponent.GetPathName()
                        End If
                    Next i
                End If
              End If
              swApp.QuitDoc swModel.GetTitle
          End Sub
          
          Private Function SetVariableValue(FilePath, VariableName, Configuration, VarValueCustExt)
               Call LoginToVault
               Call Sleeping 'Sleeptime = 5sek.
          
          On Error GoTo ErrHand
          
               Dim file As Object
               Dim Folder As Object
               Set file = vault.GetFileFromPath(FilePath, Folder)
          
               Dim pEnumVar As Object
               Set pEnumVar = file.GetEnumeratorVariable
          
               pEnumVar.SetVar VariableName, Configuration, VarValueCustExt, False
               pEnumVar.CloseFile (True)
          
               SetVariableValue = VarValueCustExt
          
          Exit Function
          
          ErrHand:
          Dim ename As String
          Dim edesc As String
          vault.GetErrorString Err.Number, ename, edesc
          Log "GetvariableValue error" & vbCrLf & ename & vbCrLf & errdesc
          End Function
          
          SubSleeping()
          Sleep 5000
          End Sub