Hello,
This error is dealing with checking in a brand new pdf document from local space to vault space where it never has existed before.
I have full ownership of the document I'm using to create the PDF and I have admin privliges on the Vault.
The PDF is being generated correctly locally.
I have the environment variable set both on my local system and on the vault
This is the bit of code I'm using to check in the pdf Document.
pdmwPdf = connection.CheckIn(fileName, pdmwDoc.project, "0", "Automated", "my notes", Default, "", "", True, pdmwDoc.References)
fileName - Correctly points to the PDF document on my local drive.
pdmwDoc.project - Points to the correct project
pdmwDoc.References - I assume to be correct since pdmwDoc.project is correct... I've also tried it with a VBA Nothing.
Ownership on the document used to generate the PDF appears to be correctly changing as well.
When I set the Environmental Variable on the vault the error changed from:
To this slightly diffrent error.
Which makes me believe I am now doing something wrong and it's being caught in Visual Studio and not by solidworks.
My complete code is below:
<pre>Option Explicit<br><br>Sub main()<br> Dim swApp As SldWorks.SldWorks<br> Dim swModel As ModelDoc2<br> Set swApp = Application.SldWorks<br> Set swModel = swApp.ActiveDoc<br> <br> 'LOGIN<br> Dim connection As PDMWConnection<br> Dim pdmwUserName As String<br> Dim pdmwServer As String<br> Set connection = CreateObject("PDMWorks.PDMWConnection")<br> pdmwUserName = "****"<br> pdmwServer = "****"<br> connection.Login pdmwUserName, "****", pdmwServer<br> <br> Dim fso As FileSystemObject<br> Set fso = CreateObject("Scripting.FileSystemObject")<br> <br> Dim filePath As String<br> Dim fileName As String<br> 'On Error GoTo ErrHandler:<br> filePath = swModel.GetPathName<br> fileName = fso.GetFileName(filePath)<br> <br> Dim pdfPath As String<br> 'On Error GoTo ErrHandler:<br> pdfPath = Left(filePath, Len(filePath) - 7) & ".pdf"<br> <br> If fso.FileExists(pdfPath) Then<br> Dim renamePath As String<br> renamePath = Left(filePath, Len(filePath) - 7) & ".old.pdf"<br> <br> 'Check that file exists<br> If Len(Dir\\\$(renamePath)) > 0 Then<br> 'First remove readonly attribute, if set<br> SetAttr renamePath, vbNormal<br> 'Then delete the file<br> Kill renamePath<br> End If<br> <br> Name pdfPath As renamePath<br> <br> pdfPath = Left(filePath, Len(filePath) - 7) & ".pdf"<br> End If<br> <br> Dim pdmwDoc As PDMWDocument<br> Dim projectName As String<br> Set pdmwDoc = connection.GetSpecificDocument(fileName)<br> projectName = pdmwDoc.project + "\\" + fileName<br> <br> If pdmwDoc.Owner <> pdmwUserName Then<br> pdmwDoc.TakeOwnership<br> 'MsgBox "You do not have ownership of this document in the PDMWorks Vault.", vbExclamation<br> 'End<br> End If<br> <br> Dim swSketchMgr As SldWorks.SketchManager<br> Set swSketchMgr = swModel.SketchManager<br> swSketchMgr.InsertSketch True<br><br> Dim boolstatus As Boolean<br> boolstatus = swModel.Extension.SelectByID2("", "NOTE", 0.008199680981595, 0.00594718404908, 0, False, 0, Nothing, swSelectOptionDefault)<br><br> If boolstatus Then<br> boolstatus = swModel.Extension.DeleteSelection2(swDelete_Absorbed)<br> End If<br><br> Dim Auth As String<br> Dim swNote As SldWorks.Note<br> Auth = (Environ\\\$("Username"))<br> <br> Dim vSheetCount As Integer<br> Dim swDraw As SldWorks.DrawingDoc<br> Set swDraw = swModel<br> vSheetCount = swDraw.GetSheetCount<br><br> If (vSheetCount > 1) Then<br> Set swNote = swModel.InsertNote(filePath & " " & pdmwDoc.Number & " " & Date & " " & Time & " by " & Auth)<br> Else<br> Set swNote = swModel.InsertNote(filePath & " " & Date & " " & Time & " by " & Auth)<br> End If<br> <br> Dim Annotation As Annotation<br> Set Annotation = swNote.GetAnnotation()<br> boolstatus = Annotation.SetPosition(0.008199680981595, 0.00594718404908, 0)<br><br> Const vbPRORLandscape = 2<br> Const swPrintOrientation = 1<br> <br> 'Redraw to see all changes<br> swModel.GraphicsRedraw2<br> <br> 'Turn on grid and entity snapping<br> swModel.SetAddToDB False<br> <br> Dim swExportPDFData As ExportPdfData<br> Set swExportPDFData = swApp.GetExportFileData(1)<br> <br> Dim strSheetName(4) As String<br> strSheetName(0) = "Sheet1"<br> <br> Dim varSheetName As Variant<br> varSheetName = strSheetName<br><br> If swExportPDFData Is Nothing Then MsgBox "Nothing"<br><br> Dim lErrors As Long<br> Dim lWarnings As Long<br> boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, varSheetName)<br> boolstatus = swModel.Extension.SaveAs(pdfPath, 0, 0, swExportPDFData, lErrors, lWarnings)<br><br> MsgBox "PDF Exported to: " & pdfPath<br> <br> Dim Refs As Variant<br> Dim pdmwPdf As IPDMWDocument<br> connection.Refresh<br> <br> Set pdmwPdf = connection.CheckIn(pdfPath, pdmwDoc.project, "0", "Automated", "my notes", Default, "0", "0", False, pdmwDoc.References)<br> <br> MsgBox "Done"<br> End<br>Exit Sub<br><br>ErrHandler:<br> MsgBox "Unspecified Error: Try Opening And/Or Saving The Drawing Before Running This Macro."<br>End SubSolidworksApi macros