5 Replies Latest reply on Jun 8, 2012 2:39 AM by Steven Naylor

    Export BOM with Levels from Workflow...

    Christina Seay

      Ok... I'm a little rusty on api programming with EPDM... so I'm hoping someone can point me in the right direction on this one.  I need to find a way to make the following happen automatically on a workflow transition:

       

      This is the manual process:

      - Locate the assembly file in the vault in Windows Explorer

      - Select the BOM tab

      - Select "Export as CSV"

      - Wait for Excel to launch tmp file

      - File Save As

      - Map to H:XML

      - Save file to Config name

       

      This is how the data that comes into the CSV looks now... and that's what I need from an automated process as well:

      LevelFILE NAMECONFIGURATION
      1TC0000083.SLDPRTTC0000083P01
      2TC0000014.SLDPRTTC0000014P01
      3TC0000008.SLDPRTTC0000008W01

       

      Does anyone have any pointers?

        • Re: Export BOM with Levels from Workflow...
          Steven Naylor

          Hi Christina,

           

          You can loop through the file references using the following code, hope that helps

           

          Private Function AddReferences(file As IEdmReference5, ByVal indent As Long, ByRef projName As String) As String
            Dim msg As String
            msg = String(indent, " ")
            msg = msg + file.Name + vbLf

            Dim isTop As Boolean
            isTop = True
            If indent > 0 Then isTop = False
            indent = indent + 4

            Dim pos As IEdmPos5
            Set pos = file.GetFirstChildPosition(projName, isTop, True, 0)
            Dim ref As IEdmReference5
            While Not pos.IsNull
              Set ref = file.GetNextChild(pos)
              msg = msg + AddReferences(ref, indent, projName)
            Wend

            AddReferences = msg
          End Function


          Private Sub ShowReferences(vault As EdmVault5, filePath As String)
          On Error GoTo ErrHand

            Dim projName As String
            Dim file As IEdmFile5
            Dim folder As IEdmFolder5
            Set file = vault.GetFileFromPath(filePath, folder)
            If file Is Nothing Then
          MsgBox "file not found"
            Else
              Dim ref As IEdmReference5
              Set ref = file.GetReferenceTree(folder.ID, 0)
              MsgBox AddReferences(ref, 0, projName)
            End If

            Exit Sub

          ErrHand:
            Dim ename As String
            Dim edesc As String
            file.vault.GetErrorString Err.Number, ename, edesc
            MsgBox ename + vbLf + edesc
          End Sub

            • Re: Export BOM with Levels from Workflow...
              Christina Seay

              I think I understand how that's working... I think what I'm lost on at this point is how to go from there to making it export that to a csv file automatically.

                • Re: Export BOM with Levels from Workflow...
                  Steven Naylor

                  Hi,

                   

                  You can write to files using system.io

                   

                   

                  'method arguments are the filename including path

                  ' for a csv this would be C:\myfile.csv

                  'message would be some comma seperated string such as "1,TC0000083.SLDPRT,TC0000083P01"

                     Private Sub writetofile(filePathAndName As String, message As String)

                          Try

                                 'create a stream write object using the file path, in this case append is set to true so that each line is appended to the file

                              Dim s As New system.io.StreamWriter(filePathAndName, True)

                   

                             'write the line

                              s.WriteLine(message)

                            'flush out all writes

                              s.Flush()

                            'close the stream

                              s.Close()

                          Catch ex As Exception

                                 'Handle errors here

                   

                          End Try

                       

                      End Sub

                    • Re: Export BOM with Levels from Workflow...
                      Christina Seay

                      Thank-you for being so helpful and patient with me. 

                       

                      Do you know how I would go about tying to kick this off during a workflow transition and be able to the grab the info from the file going through......???

                        • Re: Export BOM with Levels from Workflow...
                          Steven Naylor

                          This code will hook on a file change state.

                           

                          Public Sub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfo, ByVal poVault As EdmLib.IEdmVault5, ByVal poCmdMgr As EdmLib.IEdmCmdMgr5) Implements EdmLib.IEdmAddIn5.GetAddInInfo

                           

                           

                            'Return information about this add-in to SolidWorks Enterprise PDM in the struct

                            poInfo.mbsAddInName = "My first add-in"

                            poInfo.mbsCompany = "The name of my company"

                           

                           

                            poInfo.mbsDescription = "An addin to create csv files"

                            poInfo.mlAddInVersion = 1

                            poInfo.mlRequiredVersionMajor = 5

                            poInfo.mlRequiredVersionMinor = 2

                           

                           

                           

                           

                           

                           

                            'Call me when a file is changing state

                            poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState)

                           

                           

                            'Call me when a file has changed state

                            poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostState)

                           

                           

                           

                          End Sub

                           

                           

                           

                           

                          Public Sub OnCmd(ByRef poCmd As EdmLib.EdmCmd, ByRef ppoData As System.Array) Implements EdmLib.IEdmAddIn5.OnCmd

                           

                           

                            'Check the kind of hook that was called.

                           

                           

                            Select Case poCmd.meCmdType

                              Case EdmCmdType.EdmCmd_PreState

                               

                                    'PUT YOUR LOGIC HERE

                           

                           

                           

                           

                              Case EdmCmdType.EdmCmd_PostState

                           

                                    'PUT YOUR LOGIC HERE

                           

                           

                           

                           

                            End Select

                           

                           

                          End Sub