How can I use Python to automate downloading files from Agile PLM?

77 views Asked by At

I periodically need to download all items within a given BOM from an Agile PLM server and save them in individual folders named with their Agile item number, and it's extremely tedious and time-consuming to do manually.

Is there any way to automate this via Python? Everywhere I've looked online has lead to dead-end python packages that are supposedly meant for interfacing with Agile PLM, but have no documentation, and no clear way to actually use them.

So far, the only possible option I've seen is something like Selenium to interface with the Agile servlet through a headless browser, but that seems like it'd be a nightmare to develop from scratch for someone with my low skill level.

While I'd prefer python, if there's any other better way to automate this task, I am very open to suggestions. I don't have any control over the Agile server side of things, however.

1

There are 1 answers

0
Asker On

I'm also stuck with the same thing within my current job. But here's how I do it.

  1. You can search multiple items with "Contains any word" filter.
  2. Search all the items that you want to download at once using above filter.
  3. You'll get a list of all the found items, just click More>Export Objects>Select PDX>Only Attachments(select required formats if applicable)>export
  4. You'll get a PDX/ZIP containing all the files along with a PDX file containing relationships of the file in XML format.
  5. You can read the XML and create a custom Excel VBA script to do anything you want with those files like for example I have made it to list all the items in an excel sheet and create hyperlinks to the downloaded files under each of that items.
  6. For your use case you can write a VBA code to create a folder with item numbers and cut-paste all the files in respective folders.
  7. Use ChatGPT/Gemini to create VBA code if you don't know that language.

For your ref. here is my PDXParser VBA macro code.

Sub ParsePDXXMLFile()
    Dim xmlDoc As Object
    Dim xmlNode As Object
    Dim itemIdentifier As String
    Dim attachmentName As String
    Dim fileIdentifier As String
    Dim filePurpose As String
    Dim rowNum As Long
    Dim ws As Worksheet
    Dim cell As Range
    Dim attachmentCell As Range
    Dim purposeCell As Range

    ' Load the XML file
    Set xmlDoc = CreateObject("MSXML2.DOMDocument")
    xmlDoc.async = False
    xmladdress = InputBox("Enter the address")
    xmlDoc.Load (xmladdress & "\pdx.xml") ' Replace with the path to your PDX XML file

    ' Check for XML parsing errors
    If xmlDoc.parseError.ErrorCode <> 0 Then
        MsgBox "Error parsing XML: " & xmlDoc.parseError.reason
        Exit Sub
    End If

    ' Set initial row number for writing data
    rowNum = 2

    ' Set reference to the first worksheet
    Set ws = ActiveSheet

    ' Loop through each <Item> node in the XML document
    For Each xmlNode In xmlDoc.SelectNodes("//Item")
    
        ' Get the value of the itemIdentifier attribute
        itemIdentifier = xmlNode.getAttribute("itemIdentifier")
        
        ' Write the itemIdentifier to the worksheet and make it bold
        Set cell = ws.Cells(rowNum, 1)
        cell.Value = itemIdentifier
        cell.Font.Bold = True
        Set purposeCell = ws.Cells(rowNum, 2)
        purposeCell.Value = "Master"
        
        ' Increment row number
        rowNum = rowNum + 1
        
        ' Loop through each <Attachment> node within the <Item> node
        For Each attachmentNode In xmlNode.SelectNodes("Attachments/Attachment")
        filePurpose = ""
            ' Get the value of the universalResourceIdentifier attribute
            attachmentName = attachmentNode.getAttribute("universalResourceIdentifier")
            
            ' Get the value of the fileIdentifier attribute
            fileIdentifier = attachmentNode.getAttribute("fileIdentifier")
            
            ' Generate the final attachment text
            attachmentName = fileIdentifier & "." & attachmentName
            
            ' Write the attachmentName to column A
            Set attachmentCell = ws.Cells(rowNum, 1)
            attachmentCell.Value = attachmentName
            
            ' Check if "File Purpose" attribute exists
            On Error Resume Next
            filePurpose = attachmentNode.SelectSingleNode("AdditionalAttributes/AdditionalAttribute[@name='File Purpose']").getAttribute("value")
 
            ' Write the filePurpose to column B
            Set purposeCell = ws.Cells(rowNum, 2)
            If filePurpose <> "" Then
                purposeCell.Value = filePurpose
            Else
                purposeCell.Value = "" ' Default value if attribute is not present
            End If
            
            ' Create hyperlink for the attachment
            ws.Hyperlinks.Add anchor:=attachmentCell, Address:=xmladdress & "\" & attachmentName, TextToDisplay:=attachmentName
            
            ' Increment row number
            rowNum = rowNum + 1
        Next attachmentNode
        
        ' Increment row number for next item
        rowNum = rowNum + 1
    Next xmlNode

    ' Auto-adjust column width to fit content for both columns A and B
    ws.Columns("A:B").AutoFit
    ws.Columns("A:B").AutoFilter
    
    ' Display confirmation message
    'MsgBox "PDX XML file successfully parsed and data displayed in Excel."
End Sub