Morning/Afternoon
I have been desperately searching for a solution to this problem. Currently when we approve and issue a drawing with our revision control iLogic system, the drawing files is saved/checked in etc, and a PDF version of the drawing is created and saved to the C: drive. Ideally I want to upload this PDF to the Vault automatically as well, rather than hoping people remember to manually upload them.
I know this can be done with Vault Pro using:
oVltCon.FileManager.UploadFiles
, but I don't have that option. Any ideas?
Solved! Go to Solution.
Solved by youann21700. Go to Solution.
Solved it! The trick was to have the published PDF file as a referenced file on the drawing, so when the drawing file is checked in, the referenced PDF is also checked in.
My code is below for anyone else who has this issue. Ill do a brief summary of what it does.
1. Starts a transaction
2. Exports the PDF file with correct formatting etc. read-only
3. Attaches the PDF to the drawing file as a referenced document
the end
'CODE BY EUAN YOUR WELCOME
'THIS STARTS A TRANSACTION, WHATEVER THAT IS, THEY CAN TRACK CHANGES TO A DOCUMENT, THEREFORE CAN BE REVERSED
Sub Main()
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Export and Attach PDF file")
Try
If Not ThisApplication.ActiveDocument.FullFilename = String.Empty Then 'won't run if the active document isn't saved.
Dim filenameToAttach As String = ExportToPDF()
If Not filenameToAttach = String.Empty Then
Dim doc As Document = ThisApplication.ActiveDocument
AddReferences(doc, filenameToAttach)
End If
Else
MessageBox.Show("File not saved; save the file and try again!")
trans.Abort()
End If
trans.End()
Catch
trans.Abort()
End Try
End Sub
'MAIN FUNCTION, EXPORTS A PDF FILE OF THE DRAWING, REMOVES LINE WEIGHTS, MAKES READ ONLY (ITS AN ISSUED DRAWING SO READ ONLY IS NEEDED)
Function ExportToPDF() As String
Dim filename As String
' Get the PDF translator Add-In, that is the long string, others for other file formats are online somewhere.
Dim oPDFTranslator As TranslatorAddIn
oPDFTranslator = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oPDFTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = kPrintAllSheets
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = ThisDoc.Path & "\Issued\" & ThisDoc.FileName(False) & " REV " & iProperties.Value("Project", "Revision Number") & " " & iProperties.Value("Custom", "ReleaseStatus") & " .pdf"
checkpath = ThisDoc.Path & "\Issued"
Dim oFolder As String = checkpath
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
oPDFTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
filename = oData.FileName
Dim oFile As System.IO.FileInfo
oFile = New System.IO.FileInfo(filename)
oFile.IsReadOnly = True
End If
If System.IO.File.Exists(filename) Then
Return filename
Else
Return ""
End If
End Function
'THIS PART MAKES THE PDF A REFERENCED DOCUMENT IN THE DRAWING, MEANS WILL BE CHECKED IN/OUT WITH THE DRAWING, this solves the issue of that initial check-in
Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String)
Dim oleReference As ReferencedOLEFileDescriptor
If selectedfile.Contains("|") Then ' we have multiple files selected.
Dim file As String() = selectedfile.Split("|")
For Each s As String In file
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1)
Next
Else
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(selectedfile,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
End If
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.