and ... as your request... this is my updated macro...
Sub FilesToPdf()
Dim oDoc As DrawingDocument
Dim aPath, FileName As String
Dim FSO, FSO_FOLDER, FSO_FILE As Object
aPath = SelFolder
If aPath <> "" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSO_FOLDER = FSO.GetFolder(aPath & "\")
If FSO_FOLDER.Files.Count > 0 Then
For Each FSO_FILE In FSO_FOLDER.Files
If FSO.GetExtensionName(FSO_FILE) = "idw" Then
Set oDoc = ThisApplication.Documents.Open(FSO_FILE)
Call SaveAsPdf(oDoc, Replace(FSO_FILE, ".idw", ".pdf"))
'Call oDoc.SaveAs(Replace(FSO_FILE, ".idw", ".pdf"), True)
oDoc.Close (True)
End If
Next
Else
MsgBox "No Files Found at " & aPath
End If
Set FSO = Nothing
Set FSO_FOLDER = Nothing
End If
End Sub
Sub SaveAsPdf(oDocument As Inventor.Document, oFileName As String)
Dim oOptions, oContext, oPDFAddIn, NameValueMapoDataMedium, oDataMedium
Set oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oDataMedium.FileName = oFileName
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0 ' set to 0 for colors
'oOptions.Value("All_Color_AS_Black") = 1 ' set to 1 for black/white
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = 1
oOptions.Value("Custom_End_Sheet") = oDocument.Sheets.Count
End If
Call oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Publish Document
End Sub
Private Function SelFolder() As String
Dim folderDialog As FileDialog
Dim ShellApp, result
Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, "Please choose a folder", 1, _
ThisApplication.FileLocations.Workspace)
SelFolder = ""
If (ShellApp.items.Item.Path <> "") Then
SelFolder = ShellApp.items.Item.Path
End If
End Function
Bregs
Rossano Praderi
--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------