Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to save all idw's as pdf's for active file directory using iLogic

0 REPLIES 0
Reply
Message 1 of 1
Anonymous
685 Views, 0 Replies

How to save all idw's as pdf's for active file directory using iLogic

Here is the code that I have put together to make pdf's from all idw's in active document location.

But I can't seem to get it to use the pdfaddin options.

Any help would be appreciated.

 

 

Sub Main()
    oPath = ThisDoc.Path
    
    If MsgBox("This will write PDF files from all idw files in this location: " & vbCr & vbCr & oPath & vbCr & vbCr & " *** Are you sure you want to do this? ***", vbOKCancel + vbExclamation, "Batch Write PDF Files") = vbCancel Then Exit Sub
    
    'get PDF target folder path
    oFolder = 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 MyFiles As String()
    ' Sets up the variable "MyFile" to be each file in the directory
    ' This example looks for all the files that have an .ipt extension.
    ' This can be changed to whatever extension is needed. Also, this
    ' macro searches the current directory. 
    
    MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw")
    
    ' Starts the Loop, which will Continue Until there are no more files found.
    For Each MyFile As String In MyFiles
        ' Displays a message box with the name of the file. This can be
        ' changed to any procedure that would be needed to run on every
        ' file in the directory such as opening each file.
        'opens file:
        
        ThisApplication.SilentOperation = True
        Dim partDoc As Document = ThisApplication.Documents.Open(MyFile, False)
        
        On Error Resume Next
        
        If partDoc.DocumentType = kDrawingDocumentObject Then
        
        'oFileName = ThisDoc.FileName(False) 'without extension
        'Dim oPropSet As PropertySet
        'Dim oProp As Inventor.Property
        Dim invPartNoProperty As Inventor.Property = partDoc. _
        PropertySets.Item("Design Tracking Properties").Item("Part Number")
        PartNumber = invPartNoProperty.Value
        
        
        ' Get the DataIO object.
        'Dim oDataIO As DataIO = partDoc.ComponentDefinition.DataIO
        
        'oRevNum = iProperties.Value("Project", "Revision Number")
        oPDFAddIn = partDoc.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 oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
            oOptions.Value("All_Color_AS_Black") = 0
            oOptions.Value("Remove_Line_Weights") = 1
            oOptions.Value("Vector_Resolution") = 400
            'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
            oOptions.Value("Custom_Begin_Sheet") = 1
            'oOptions.Value("Custom_End_Sheet") = 4
        End If

        'Set the PDF target file name
        'oDataMedium.FileName = oFolder & "\" & oFileName & " Rev " & oRevNum & ".pdf"
        oDataMedium.FileName = oFolder & "\" & PartNumber &  ".pdf"

        'Publish document
        'oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
        partDoc.SaveAs(oFolder & "\" & PartNumber &  (".pdf") , True)

    End If

        partDoc.Close(False)
        partDoc = Nothing
        ThisApplication.SilentOperation = False

    Next


Shell("explorer.exe " & oFolder,vbNormalFocus)

End Sub
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report