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:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'LOGIN
Dim connection As PDMWConnection
Dim pdmwUserName As String
Dim pdmwServer As String
Set connection = CreateObject("PDMWorks.PDMWConnection")
pdmwUserName = "****"
pdmwServer = "****"
connection.Login pdmwUserName, "****", pdmwServer
Dim fso As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Dim filePath As String
Dim fileName As String
'On Error GoTo ErrHandler:
filePath = swModel.GetPathName
fileName = fso.GetFileName(filePath)
Dim pdfPath As String
'On Error GoTo ErrHandler:
pdfPath = Left(filePath, Len(filePath) - 7) & ".pdf"
If fso.FileExists(pdfPath) Then
Dim renamePath As String
renamePath = Left(filePath, Len(filePath) - 7) & ".old.pdf"
'Check that file exists
If Len(Dir$(renamePath)) > 0 Then
'First remove readonly attribute, if set
SetAttr renamePath, vbNormal
'Then delete the file
Kill renamePath
End If
Name pdfPath As renamePath
pdfPath = Left(filePath, Len(filePath) - 7) & ".pdf"
End If
Dim pdmwDoc As PDMWDocument
Dim projectName As String
Set pdmwDoc = connection.GetSpecificDocument(fileName)
projectName = pdmwDoc.project + "\" + fileName
If pdmwDoc.Owner <> pdmwUserName Then
pdmwDoc.TakeOwnership
'MsgBox "You do not have ownership of this document in the PDMWorks Vault.", vbExclamation
'End
End If
Dim swSketchMgr As SldWorks.SketchManager
Set swSketchMgr = swModel.SketchManager
swSketchMgr.InsertSketch True
Dim boolstatus As Boolean
boolstatus = swModel.Extension.SelectByID2("", "NOTE", 0.008199680981595, 0.00594718404908, 0, False, 0, Nothing, swSelectOptionDefault)
If boolstatus Then
boolstatus = swModel.Extension.DeleteSelection2(swDelete_Absorbed)
End If
Dim Auth As String
Dim swNote As SldWorks.Note
Auth = (Environ$("Username"))
Dim vSheetCount As Integer
Dim swDraw As SldWorks.DrawingDoc
Set swDraw = swModel
vSheetCount = swDraw.GetSheetCount
If (vSheetCount > 1) Then
Set swNote = swModel.InsertNote(filePath & " " & pdmwDoc.Number & " " & Date & " " & Time & " by " & Auth)
Else
Set swNote = swModel.InsertNote(filePath & " " & Date & " " & Time & " by " & Auth)
End If
Dim Annotation As Annotation
Set Annotation = swNote.GetAnnotation()
boolstatus = Annotation.SetPosition(0.008199680981595, 0.00594718404908, 0)
Const vbPRORLandscape = 2
Const swPrintOrientation = 1
'Redraw to see all changes
swModel.GraphicsRedraw2
'Turn on grid and entity snapping
swModel.SetAddToDB False
Dim swExportPDFData As ExportPdfData
Set swExportPDFData = swApp.GetExportFileData(1)
Dim strSheetName(4) As String
strSheetName(0) = "Sheet1"
Dim varSheetName As Variant
varSheetName = strSheetName
If swExportPDFData Is Nothing Then MsgBox "Nothing"
Dim lErrors As Long
Dim lWarnings As Long
boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, varSheetName)
boolstatus = swModel.Extension.SaveAs(pdfPath, 0, 0, swExportPDFData, lErrors, lWarnings)
MsgBox "PDF Exported to: " & pdfPath
Dim Refs As Variant
Dim pdmwPdf As IPDMWDocument
connection.Refresh
Set pdmwPdf = connection.CheckIn(pdfPath, pdmwDoc.project, "0", "Automated", "my notes", Default, "0", "0", False, pdmwDoc.References)
MsgBox "Done"
End
Exit Sub
ErrHandler:
MsgBox "Unspecified Error: Try Opening And/Or Saving The Drawing Before Running This Macro."
End Sub