Hello, I have a rule that does to things, first it exports entire .idw to pdf, this works perfectly fine. The second part of the rule searches thru all the sheet names and if it finds one named "BASE PLATE POLE CAP", it activate that drawing sheet, then exports the sheet to it's own pdf so that I have it ready to forward to where we would get them cut.
Our workflow isn't perfect and sometimes I don't have a Job Number or Project number available so I created an If/Then/Else statement to create this second pdf. If the JobNumber custom iProperty exists, create a pdf named "this", if it doesn't exist, the just create a generic pdf name "Base Plate Pole Cap".
I can't get the Base Plate Pole Cap pdf export to function properly, it only exports a pdf named "BASE PLATE POLE CAP", and before that export occurs and the pdf appears in windows explorer, I get the error message box where I have to press OK first. But no one has it open, it isn't even created yet.
Not sure where I have gone wrong with this. Any ideas, thanks!
rule below:
'EXPORT ENTIRE PDF
path_and_namePDF = ThisDoc.PathAndFileName(False)
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 4800
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("All_Color_AS_Black") = 0
'oOptions.Value("Custom_End_Sheet") = 4
End If
'Set the destination file name
oDataMedium.FileName = path_and_namePDF & ".pdf" 'SET DESTINATION, FILE LOCATION WITH FILE NAME AND EXTENSION
On Error Goto handlePDFLock
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) ' EXPORT DOCUMENT
'CHECK FOR BASE PLATE POLE CAP SHEET, IF EXIST THEN EXPORT TO PDF
Dim oSheet As Sheet ' Set up an indicator to track progress.
Dim bCheck as Boolean = False
For Each oSheet In ThisApplication.ActiveDocument.Sheets
Dim sSheetName As String = oSheet.Name.Split(":")(0)
If oSheet.Name.StartsWith("BASE PLATE POLE CAP") = True Then
bCheck = True
ActiveSheet = ThisDrawing.Sheet(oSheet.Name)
Exit For
End If
Next
If bCheck = False Then ' Checking we actually found the sheet being looked for.
Return ' No Sheet found with given name so exit.
End If
'if BASE PLATE POLE CAP sheet is found, it should be activated to current sheet, then export current sheet only to pdf
pathPDF = ThisDoc.Path
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument2 = ThisApplication.ActiveDocument
oContext2 = ThisApplication.TransientObjects.CreateTranslationContext
oContext2.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions2 = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium2 = ThisApplication.TransientObjects.CreateDataMedium
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium2, oContext2, oOptions2) Then
oOptions2.Value("Remove_Line_Weights") = 1
oOptions2.Value("Vector_Resolution") = 4800
oOptions2.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("All_Color_AS_Black") = 0
'oOptions.Value("Custom_End_Sheet") = 4
End If
'Set the destination file name
If iProperties.Value("Custom", "JobNumber") = False Then
oDataMedium2.FileName = pathPDF & "\" & "BASE PLATE POLE CAP" & ".pdf"
'MessageBox.Show(oDataMedium2.FileName, "Title")
Else
oDataMedium2.FileName = pathPDF & "\" & iProperties.Value("Custom", "JobNumber") & "_BASE PLATE POLE CAP" & ".pdf"
'MessageBox.Show(oDataMedium2.FileName, "Title")
End If
On Error Goto handlePDFLock
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument2, oContext2, oOptions2, oDataMedium2)
Exit Sub
handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi @Shag_Bore
You will first need to remove the in error resume next line. That's a catch all method that doesn't allow you find what's going wrong. Try using try catch instead and position it around a block of code. You can then keep moving it to a smaller and smaller block of code untill you find the line erroring out. Alternatively just remove the error trap and let the code editor return a line that is failing and address why it could be.
Hi @Shag_Bore
This line will error if the property does not exist. I think this is likely the source of your error.
If iProperties.Value("Custom", "JobNumber") = False Then
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
I think this will work for you
oErrorMsg = "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!" _ & vbLf & "PDF could not be saved, maybe someone else has it open?" '[PDF setup PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oDataMedium = ThisApplication.TransientObjects.CreateDataMedium oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 4800 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("All_Color_AS_Black") = 0 'oOptions.Value("Custom_End_Sheet") = 4 '] '[EXPORT ENTIRE PDF 'set sheet range option oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'set name oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".pdf" 'SET DESTINATION, FILE LOCATION WITH FILE NAME AND EXTENSION Try Call PDFAddIn.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oDataMedium) ' EXPORT DOCUMENT Catch MsgBox(oErrorMsg, , "Problem Creating 1st PDF") End Try '] '[CHECK FOR BASE PLATE POLE CAP SHEET, IF EXIST THEN EXPORT TO PDF Dim bCheck As Boolean = False For Each oSheet As Sheet In ThisApplication.ActiveDocument.Sheets Dim sSheetName As String = oSheet.Name.Split(":")(0) If oSheet.Name.StartsWith("BASE PLATE POLE CAP") = True Then bCheck = True ActiveSheet = ThisDrawing.Sheet(oSheet.Name) Exit For End If Next If bCheck = False Then ' Checking we actually found the sheet being looked for. Return ' No Sheet found with given name so exit. End If Try oJNum = iProperties.Value("Custom", "JobNumber") & "_" Catch oJNum = "" End Try 'update sheet range option oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet 'set name oDataMedium.FileName = ThisDoc.Path & "\" & oJNum & "BASE PLATE POLE CAP" & ".pdf" Try Call PDFAddIn.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oDataMedium) ' EXPORT DOCUMENT Catch MsgBox(oErrorMsg, , "Problem Creating 2nd PDF") End Try ']
Thanks @Curtis_Waguespack and @A.Acheson
I am getting a better understanding now with the Try and catch's,
interesting in this specific case how the try looks for the jobnumber and if it exists, uses it, if it doesn't then the code moves onto the catch which is essentially then blank. very cool!!
thanks again, have a good weekend!
Sean
Can't find what you're looking for? Ask the community or share your knowledge.