Ilogic to do mass drawing export of all drawings related with an assembly

Ilogic to do mass drawing export of all drawings related with an assembly

JacobRL4SN
Enthusiast Enthusiast
126 Views
1 Reply
Message 1 of 2

Ilogic to do mass drawing export of all drawings related with an assembly

JacobRL4SN
Enthusiast
Enthusiast

Hi,

 

I am trying to write a piece of ilogic that would take an overall assembly open all the drawings for all the subassemblies and parts associated and export them all as a PDF to a specified location on my computer and close the documents as it goes. However, I am completely striking out. Anyone have any ideas on how to fix my code, I am very much new to the ilogic world and any help would be appreciated. 

' iLogic code to open and export PDFs for parts and subassemblies of the open assembly

' Create a FolderBrowserDialog to prompt the user for the export location
Dim folderBrowserDialog As New System.Windows.Forms.FolderBrowserDialog()
folderBrowserDialog.Description = "Select a folder to save PDF files"
folderBrowserDialog.ShowNewFolderButton = True

' Show the FolderBrowserDialog
If folderBrowserDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    ' Get the selected export folder
    Dim exportFolder As String = folderBrowserDialog.SelectedPath

    ' Get the active assembly document
    Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument

    ' Iterate through each occurrence in the assembly
    For Each compOccurrence As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
        Dim compDoc As Document = compOccurrence.Definition.Document

        ' Check if the component is a part or a subassembly
        If compDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or compDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            ' Open the part or subassembly document
            Dim compDocPath As String = compDoc.FullFileName
            Dim compDocObj As Document = ThisApplication.Documents.Open(compDocPath)

            ' Check if there is an associated drawing
            Dim drawingDescriptor As FileDescriptor = compDocObj.File.FileDescriptor
            If drawingDescriptor IsNot Nothing AndAlso drawingDescriptor.FileType = FileTypeEnum.kDrawingFileType Then
                ' Open the drawing document
                Dim drawingDocPath As String = drawingDescriptor.FullFileName
                Dim drawingDocObj As Document = ThisApplication.Documents.Open(drawingDocPath)

                ' Export the drawing as a PDF
                Dim pdfPath As String = System.IO.Path.Combine(exportFolder, compDoc.DisplayName & ".pdf")
                drawingDocObj.SaveAs(pdfPath, True)
                MsgBox("PDF for " & compDoc.DisplayName & " exported successfully.", vbInformation)

                ' Close the drawing document
                drawingDocObj.Close(True)
            Else
                MsgBox("No drawing found for " & compDoc.DisplayName, vbExclamation)
            End If

            ' Close the part or subassembly document
            compDocObj.Close(True)
        End If
    Next
Else
    ' User canceled the FolderBrowserDialog
    MsgBox("Export canceled by user.", vbInformation)
End If

 

0 Likes
127 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @JacobRL4SN 

Can you indicate where your having trouble? Please copy the error message on the more info tab and post it here. A note that simply saving as will have likely a low quality result. There is lots of samples on this forum to print to pdf. One such example here

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes