@GosponZ
The sheet numbers change sounds like a reasonable request. However, it's not going to be nearly as easy as it sounds.
In the past I believe I have seen others attempt to save each sheet of the drawing out as its own drawing document, just before exporting them to PDF, then delete the extra documents afterwards near the end of the code. That process may get the job done, but may take too much time and seem to be a heavy user of your system's resources.
The difficult thing about this request is that the Textbox within most TitleBlocks that contains the Sheet number and the total number of sheets in the drawing, contains 'live linked' Properties, that aren't readily available to access and modify through normal means. The current sheet number is a 'derived' property called "Sheet Number" and seems to be within a property set called "Sheet Properties". The total number of sheets is a 'derived' property called "Number of sheets", and seems to be within a property set called "Drawing Properties". These seem to be 'hidden' properties that I'm not sure how to access at this time. They aren't listed with all the other iProperties, of either the Drawing document, or the model document.
So, what I'm doing here is just searching within the TitleBlock's sketch for a TextBox that contains the text "SHEET" OR "Sheet" to find the right TextBox. Then I capture its current "FormattedText" value, to save it, so I can restore it later. Then I attempt to change it to something like "SHEET 1 OF 1", just long enough for the export process of that sheet. Then I attempt to restore the original value of that TextBox's FormattedText property, as if nothing has changed. However, after many tweaks and tests, I haven't got it working just right yet.
Here's what I've got so far.
(Beware: I have a couple of your settings commented out and my own settings in place so it will work in my environment. The changes are the oFolder variable and its folder check process, as well as the oDataMedium.FileName setting. You can just un-comment those if you need them, then comment out my version of the oDataMedium.FileName setting, before running it.)
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDrawing As DrawingDocument = ThisDrawing.Document
Dim oSheetsCount As Integer = oDrawing.Sheets.Count
Dim oInstructions As String = "Enter the sheet numbers you want to publish to PDF." & vbCrLf & _
"Use commas, to separate individual sheet numbers, and to separate sheet ranges." & vbCrLf & _
"Use a dash (-) between two numbers to specify a sheet range." & vbCrLf & _
"NO SPACES!"
Dim oInputSheets As String = InputBox(oInstructions, "Sheets To Publish", "1-" & oSheetsCount)
'split that string up into an array of individual strings so they can be more easily interpreted
Dim oSheetRanges() As String = Split(oInputSheets, ",")
Dim oSheetCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oRangeStart, oRangeEnd As Integer
For Each oSR As String In oSheetRanges
'check to see if the string includes the "-" character
If oSR.Contains("-") Then
'it is a sheet range, so get the two numbers
oRangeStart = CInt(Split(oSR, "-")(0))
oRangeEnd = CInt(Split(oSR, "-")(1))
For i As Integer = oRangeStart To oRangeEnd
oSheetCol.Add(oDrawing.Sheets.Item(i))
Next
Else
oSheetCol.Add(oDrawing.Sheets.Item(CInt(oSR)))
End If
Next
Dim oPath As String = IO.Path.GetDirectoryName(oDrawing.FullFileName)
Dim oFileName As String = IO.Path.GetFileNameWithoutExtension(oDrawing.FullFileName)
''get PDF target folder path
'Dim oFolder As String = Left(oPath, InStrRev(oPath, "\")) & "PDF"
''Check for the PDF folder and create it if it does not exist
'If Not System.IO.Directory.Exists(oFolder) Then
' System.IO.Directory.CreateDirectory(oFolder)
'End If
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer
Dim oTBDef As TitleBlockDefinition
Dim oSketch As DrawingSketch
Dim oTBox As Inventor.TextBox
Dim oFText As String
'step through each drawing sheet
For Each oSheet In oSheetCol
oSheet.Activate
'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)
' oDataMedium.FileName = oFolder & "\" & sSheetName & " " & iSheetNumber & ".pdf"
oDataMedium.FileName = oPath & "\" & sSheetName & " " & iSheetNumber & ".pdf"
oTBDef = oSheet.TitleBlock.Definition
oTBDef.Edit(oSketch)
For Each oTBox In oSketch.TextBoxes
If oTBox.Text.Contains("SHEET") Or _
oTBox.Text.Contains("Sheet") Then
'save its current FormattedText so we can restore it later
oFText = oTBox.FormattedText
' oTBox.FormattedText = oTBox.FormattedText.Replace(oFText, "SHEET 1 OF 1")
oTBox.FormattedText = oTBox.FormattedText.Replace("<DerivedProperty DerivedID='29704'>Sheet Number</DerivedProperty>", "1")
oTBox.FormattedText = oTBox.FormattedText.Replace("<DerivedProperty DerivedID='29703'>Number of sheets</DerivedProperty>", "1")
'change its Text temporarily for this process
' oTBox.Text = "SHEET 1 OF 1"
'when we exit the For loop right now, we preserve the oTBox variable's value as this TextBox
Exit For
End If
Next
oTBDef.ExitEdit(True)
'Publish document
oPDFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
'now restore the Sheet textbox to original setting
'since I have to redefine oSketch here, I'm also redefining oTBox to be safe
oTBDef.Edit(oSketch)
For Each oTBox In oSketch.TextBoxes
If oTBox.Text.Contains("SHEET") Or _
oTBox.Text.Contains("Sheet") Then
oTBox.FormattedText = oFText
Exit For
End If
Next
oTBDef.ExitEdit(True)
Next
'Activate the first sheet again
oDrawing.Sheets.Item(1).Activate
Wesley Crihfield
(Not an Autodesk Employee)