How to Create Reference from PDF to Drawing file in SolidWorks PDM Enterprise?

 We were using PDM Tasks to create PDF files from Drawings. I liked the "Create a reference from the destination file to the source file" feature in the Output File Details part of the task set up. However we got tired of the slow speed of task execution. Launching a new instance of SolidWorks for every single file takes time and resources on the user's own machine or a long queue on a server. So I wrote a macro to create PDF and STEP files from a SolidWorks drawing file.

Save As PDF from the active drawing? No problem.

Get the model from the view and Save As STEP from that model? No problem.

Add the new PDF and STEP files to the vault and check them in? PDM API documentation isn't the best, but I figured it out.

However, I'm stuck on creating a reference from the PDF file to the drawing file and from the STEP file to the model file.

 

' pdmDrawFile As IEdmFile5
' pdmModelFile As IEdmFile5
' pdfFile As IEdmFile5
' stepFile As IEdmFile5
' All defined earlier in the script and are valid instances used for checking the workflow state and revision of the drawing and model files, and adding and checking in the pdf and step files.

Dim addCustRefs As IEdmAddCustomRefs2
Set addCustRefs = edmVault.CreateUtility(EdmUtility.EdmUtil_AddCustomRefs)
    
Dim pathArray(0) As String
pathArray(0) = pdmDrawFile.GetLocalPath(drawingFolder.ID)
Debug.Print "Test drawing path" & pathArray(0)

Dim qtyArray(0) As Long
qtyArray(0) = 1
    
addCustRefs.AddReferencesPath2 pdfFile.ID, pathArray, qtyArray

addCustRefs.CreateTree (0)
    
Dim pdfRefCheck As Boolean
pdfRefCheck = addCustRefs.CreateReferences()
Debug.Print "pdfRefCheck boolean " & pdfRefCheck

It runs with no errors, but it doesn't work

Just using 'addCustRefs.AddReferencesPath2 pdfFile.ID, pathArray, qtyArray' alone didn't create the references.

Adding 'pdfRefCheck = addCustRefs.CreateReferences()' afterwards didn't create the references.

Adding 'addCustRefs.CreateTree (0)' in between didn't work either.

It all runs but the 'CreateReferences()' returns false, and there are no files added to the Contains tab in File Explorer.

I've also tried 'AddReferencesPath', no luck there.

 

I've looked briefly at 'AddReferencesID2', but I'm not clear on how to create an array of 'EDMSelItem' from an instance of IEdmFile5. 

 

Any suggestions?