I want to run the code when I press the Vault check-in button.
doc = ThisDoc.Document
docName = ThisDoc.Document.FullFileName
newDocpath = docName.Split("작업공간")(0)
newDocpath = newDocpath + "작업공간\구매팀출도"
PartREV = doc.ReferencedDocuments.Item(1).PropertySets.Item("Inventor Summary Information").Item(7).Value
Dim Time As DateTime = Date.Now
Dim Format As String = "yyyyMd"
todayDate = Time.ToString(Format)
docDN = doc.DisplayName
docDN = docDN.Split(".dwg")(0)
If PartREV = ","
convertdwgName = docDN + "_" + todayDate + "(Cad).dwg"
convertpdfName = docDN + "_" + todayDate + ".pdf"
ElseIf PartREV = ""
convertdwgName = docDN + "_" + todayDate + "(Cad).dwg"
convertpdfName = docDN + "_" + todayDate + ".pdf"
Else
convertdwgName = docDN + PartREV + "(Cad).dwg"
convertpdfName = docDN + PartREV + ".pdf"
End If
Dim oFolder As String
oFolder = newDocpath
If System.IO.Directory.Exists(oFolder) = False Then
System.IO.Directory.CreateDirectory(oFolder)
ElseIf System.IO.Directory.Exists(oFolder) = True Then
'What to do with it if it does exist here.
End If
'----------------------------------------------------------------
'Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "E:\Inventor\00. YMK Template\Inventor 설정 파일\CAD 변환\CAD 파일 구성저장1.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
oDataMedium.FileName = newDocpath + "\" + convertdwgName
'Publish document.
Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'-----------------------------------------------------------------------------------------
Dim oPrintMgr As DrawingPrintManager
oPrintMgr = ThisApplication.ActiveDocument.PrintManager
oPrintMgr.Printer = "Microsoft Print to PDF"
' Set to print in color.
oPrintMgr.AllColorsAsBlack = True
' Set to print two copies.
oPrintMgr.NumberOfCopies = 1
' Set to print using portrait orientation.
oPrintMgr.Orientation = kLandscapeOrientation
' Set the paper size.
oPrintMgr.PaperSize = kPaperSizeA3
' Set to print all sheets.
oPrintMgr.PrintRange = kPrintSheetRange
' Set to print full scale.
oPrintMgr.ScaleMode = kPrintBestFitScale
' Submit the print.
oPrintMgr.PrintToFile(newDocpath + "\" + convertpdfName)
'------------------------------------------------------------------------------------
doc.ReferencedOLEFileDescriptors.Add(newDocpath + "\" + convertdwgName, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
doc.ReferencedOLEFileDescriptors.Add(newDocpath + "\" + convertpdfName, OLEDocumentTypeEnum.kOLEDocumentLinkObject)