Save to single-sheet PDF

Save to single-sheet PDF

vickimclJRCYT
Contributor Contributor
2,168 Views
20 Replies
Message 1 of 21

Save to single-sheet PDF

vickimclJRCYT
Contributor
Contributor

Hi,

 

I am not an ilogic programmer (yet), I am just starting to learn. I copied this code from 2 different sources but I'm having a problem with the sheet number. It's saving with a 2 in the filename, but I do not understand where it is pulling this from especially when running the rule from sheet 1, as it should be a 1 not a 2. All other properties are appearing in filename correctly, except the sheet number. 

 

PDF filename: Project Number-Part Number-Sheet Number Description.pdf (Ex: S2100-A100-1 Tail Frame.pdf)

 

I know you guys are the experts, any help would be greatly appreciated. Thanks.

 

Here is the code:

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDescription = iProperties.Value("Project", "Description")
oPartNumber = iProperties.Value("Project", "Part Number")
oProject = iProperties.Value("Project", "PROJECT")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oDoc = ThisDoc.Document

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()
Dialog.SelectedPath = "T:\ENG 3D\JOBS"
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."
If DialogResult.OK = Dialog.ShowDialog() Then
ExportPath = Dialog.SelectedPath & "\"
Else
Exit Sub
End If

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

	'find the seperator in the sheet name:number
	lPos = InStr(oSheet.Name, ":")
	'find the number of characters in the sheet name
	sLen = Len(oSheet.Name)
	'find the sheet name
	sSheetName = Left(oSheet.Name, lPos -1)
	'find the sheet number
	iSheetNumber = Right(oSheet.Name, sLen - lPos)
	Next

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

If iProperties.Value("Project", "Revision Number") >= "1" Then
ExportPath = ExportPath
End If
oDataMedium.FileName = ExportPath & oProject & "-" & oPartNumber & "-" & iSheetNumber & " " & oDescription & ".pdf"
Try
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

' Ask the user if he/she wants to open the file
question2 = MessageBox.Show("Open PDF file?", "PDF Created",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If question2 = vbYes Then
ThisDoc.Launch(oDataMedium.FileName)
End If
Catch
MessageBox.Show("PDF not created, document may be open.", "Please close and try again ")
End Try
Exit Sub

Thanks,

Victoria

 

0 Likes
Accepted solutions (1)
2,169 Views
20 Replies
Replies (20)
Message 21 of 21

vickimclJRCYT
Contributor
Contributor

@WCrihfield @A.Acheson 

 

That was it! It is working fabulously!

Thank you so much!

 

I appreciate all the help. You both are amazing to take the time to solve my issue. I have learned a lot.

 

And I know others who save out PDF files individually will be thanking you as well.

 

Many Thanks,

Victoria

 

0 Likes