Here is revised as per your needs.
The error is because the rule environment always tries to run "Sub Main()" first, and if it doesn't find it, it errors out.
From Sub Main you can call other subs to really modularize your programming.
The reason it was ExportPDF(DwgDocString) was for exactly that reason; the sub that called it organized the batch printing aspect of the program.
Sub Main()
Dim oDwgDoc As DrawingDocument
Try
oDwgDoc = ThisApplication.ActiveDocument
Catch
MsgBox("Valid for drawing Documents only!")
End Try
Dim oPDFAddIn As TranslatorAddIn
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' The single line below this is all you need to tweak to select the filename. ie; right now it prints to a folder on my desktop
oDataMedium.FileName = "C:\Users\Owner\Desktop\PDF\" & System.IO.Path.GetFileNameWithoutExtension(oDwgDoc.FullFileName) & ".pdf"
Call oPDFAddIn.SaveCopyAs(oDwgDoc, oContext, oOptions, oDataMedium)
oDwgDoc.Close(False)
End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.