Make PDF after checkin

Make PDF after checkin

Anonymous
Not applicable
699 Views
1 Reply
Message 1 of 2

Make PDF after checkin

Anonymous
Not applicable

We have a rule to approve a drawing. After the drawing is approved i would like to make a pdf, but my current rule makes the pdf before the user can fill in the approver. With my cut&paste ilogic knowledge i can't find a solution that works for me. Can somebody help me?

'Approve Drawing
oTime = Now.ToShortDateString
approver = InputBox("Wie is de approver?", "Approve", "MP")
iProperties.Value("Status", "Eng. Approved By") = approver
iProperties.Value("Status", "Eng. Approved Date") = oTime
iProperties.Value("Status", "Design State") = 3

'Check in Drawning
ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)

'Make PDF
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This Rule '" & iLogicVb.RuleName & "' only works on Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document

Dim oPDFAddin As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.DisplayName = "Translator: PDF" Then
		oPDFAddin = oAddin
	End If
Next

'The following lines are to define needed aspects of the Translator, so we can modify its options.
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium

'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
	oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
	oOptions.Value("Launch_Viewer") = 1 ' 0 = False, 1 = True
	oOptions.Value("Publish_Mode") = 62721 'This seems to be the norm for exporting a normal drawing. There may be another value for 3D PDF's.
	'oOptions.Value("Enable_Measure") = 1
	'oOptions.Value("Enable_Markups") = 1
	'oOptions.Value("Output_Path") = 
	'oOptions.Value("Sheet_Metal_Flat_Pattern") = 0
	'oOptions.Value("Sheet_Metal_Part") = 1
	'oOptions.Value("Weldment_Symbol") = 0
	'oOptions.Value("BOM_Parts_Only") = 1
	'oOptions.Value("Instructions") = 0
	'oOptions.Value("iAssembly_3D_Models") = 0
	'oOptions.Value("iPart_3D_Models") = 0
	'oOptions.Value("Publish_Mass_Props") = 1
	'oOptions.Value("Publish_Screenshot") = 0
	'oOptions.Value("Facet_Quality") = 69379
	'oOptions.Value("Facet_Recompute_Tolerance") = 0.001
	'oOptions.Value("Sheet_Color") = 0
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 4   (it is not confirmed that this line works)
	oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
	oOptions.Value("Vector_Resolution") = 4800 ' DPI
	oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
	'oOptions.Value("Print_Excluded_Sheets") = 0 ' 0 = False, 1 = True (DOESN'T SEEM TO BE WORKING YET)
End If

'Set the PDF file name
'oDataMedium.FileName = ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".pdf"
Dim oDeskTopDir As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)
Dim oFileName = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
oDataMedium.FileName = oDeskTopDir & "\" & oFileName & ".pdf"

'Check to see if the PDF already exists, if it does, ask if you want to over write existing or not.
If System.IO.File.Exists(oDataMedium.FileName) = True Then
	oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
	"Do you want to over write it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
	If oAnswer = vbNo Then Return
End If

'Publish PDF
oPDFAddin.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
0 Likes
Accepted solutions (1)
700 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor
Accepted solution

I tested your rule as is without the vault check in command and it updated the pdf as it should. I also put in a command to collapse browser to try and simulate a command being pressed. I noticed it was only slightly working so I added  the do events snippet.

 

 

'Slow down events to ensure they are completed in full
ThisApplication.UserInterfaceManager.DoEvents
ThisApplication.StatusBarText = "Checking in......"

 

 

I moved  the iProperties being added  to after the document is checked for it being a drawing. This way you won't modify a part or assembly accidently. I also added in a save for the drawing as the drawing is not being saved before printing. So perhaps the drawing was not fully updated and the approved status wasn't being pushed out onto the pdf. I wonder was the check in command effecting this behavior? Try it and see how it works.!

 

'Make PDF
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This Rule '" & iLogicVb.RuleName & "' only works on Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document

'Approve Drawing
oTime = Now.ToShortDateString
approver = InputBox("Wie is de approver?", "Approve", "MP")
iProperties.Value("Status", "Eng. Approved By") = approver
iProperties.Value("Status", "Eng. Approved Date") = oTime
iProperties.Value("Status", "Design State") = 3

'Save after iPorperty Change
oDDoc.Save
'Check In Drawning
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute2(False)

'Slow down events to ensure they are completed in full
ThisApplication.UserInterfaceManager.DoEvents
ThisApplication.StatusBarText = "Checking in......"

Dim oPDFAddin As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.DisplayName = "Translator: PDF" Then
		oPDFAddin = oAddin
	End If
Next

'The following lines are to define needed aspects of the Translator, so we can modify its options.
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium

'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
	oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
	oOptions.Value("Launch_Viewer") = 1 ' 0 = False, 1 = True
	oOptions.Value("Publish_Mode") = 62721 'This seems to be the norm for exporting a normal drawing. There may be another value for 3D PDF's.
	'oOptions.Value("Enable_Measure") = 1
	'oOptions.Value("Enable_Markups") = 1
	'oOptions.Value("Output_Path") = 
	'oOptions.Value("Sheet_Metal_Flat_Pattern") = 0
	'oOptions.Value("Sheet_Metal_Part") = 1
	'oOptions.Value("Weldment_Symbol") = 0
	'oOptions.Value("BOM_Parts_Only") = 1
	'oOptions.Value("Instructions") = 0
	'oOptions.Value("iAssembly_3D_Models") = 0
	'oOptions.Value("iPart_3D_Models") = 0
	'oOptions.Value("Publish_Mass_Props") = 1
	'oOptions.Value("Publish_Screenshot") = 0
	'oOptions.Value("Facet_Quality") = 69379
	'oOptions.Value("Facet_Recompute_Tolerance") = 0.001
	'oOptions.Value("Sheet_Color") = 0
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 4   (it is not confirmed that this line works)
	oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
	oOptions.Value("Vector_Resolution") = 4800 ' DPI
	oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
	'oOptions.Value("Print_Excluded_Sheets") = 0 ' 0 = False, 1 = True (DOESN'T SEEM TO BE WORKING YET)
End If

'Set the PDF file name
'oDataMedium.FileName = ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".pdf"
Dim oDeskTopDir As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)
Dim oFileName = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
oDataMedium.FileName = oDeskTopDir & "\" & oFileName & ".pdf"

'Check to see if the PDF already exists, if it does, ask if you want to over write existing or not.
If System.IO.File.Exists(oDataMedium.FileName) = True Then
	oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
	"Do you want to over write it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
	If oAnswer = vbNo Then Return
End If

'Publish PDF
oPDFAddin.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes