Print idw with BOM order

Print idw with BOM order

aries.1482
Enthusiast Enthusiast
373 Views
4 Replies
Message 1 of 5

Print idw with BOM order

aries.1482
Enthusiast
Enthusiast

Hi,

I try to print all idw related to an assembly used task scheduler, it's ok. But i want to print with right order as they were sorted in assembly BOM and it is very tedious because i must chose idw file one by one. Any solutions for me!? Thanks!

 

0 Likes
374 Views
4 Replies
Replies (4)
Message 2 of 5

Xun.Zhang
Alumni
Alumni

Hello @aries.1482,

It is possible, you can export part list to xls and then copy to a txt file, leverage API with VBA code to print from this list one by one.

Hope it helps!


Xun
Message 3 of 5

aries.1482
Enthusiast
Enthusiast

Thanks for reply, i think it is possible Smiley Very Happy; but i'm not friendly with VBA, can you post code here?

 

 

0 Likes
Message 4 of 5

Xun.Zhang
Alumni
Alumni

Here is a sample file to export drawing to PDF with a list file for your reference.

Hope it helps!

Sub Main()
      
    Dim arrFileslist() As String
    arrFileslist = GetFilesFromTxt

    Dim iStep As Integer
    
    For iStep = 0 To UBound(arrFileslist)
    On Error Resume Next
            Set oDoc = ThisApplication.Documents.Open(arrFileslist(iStep), True)
            Call Export2PDF
    On Error GoTo 0
    Next
End Sub

'Get all files from txt files
Public Function GetFilesFromTxt() As String()
    Dim strLine As String
    Dim strFilesListArr() As String
    
    Dim k As Integer: k = 0
    Open sFilelistTxt For Input As #1
    Do Until EOF(1)
        Line Input #1, strLine
        ReDim Preserve strFilesListArr(k) As String
        strFilesListArr(k) = strLine
        k = k + 1
    Loop
    Close #1
    
    GetFilesFromTxt = strFilesListArr
End Function


Public Function Export2PDF()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument


'Dump PDF

Dim oPDFAddIn As TranslatorAddIn
Set oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

Dim oPath As String
oPath = "C:\temp" ' PDF save folder

Dim oFileName As String
oFileName = oDoc.DisplayName

oDataMedium.FileName = oPath & "\" & oFileName & ".pdf"

Call oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)

Dim oSheets As Sheets
Set oSheets = oDoc.Sheets
For Each oSheet In oSheets
    FileName = oPath & "\" & oFileName & "_" & Left(oSheet.Name, Len(oSheet.Name) - 2) & ".dwg"
Next

Call oDoc.SaveAs(oPath & "\" & oFileName & ".dwg", True)

End Function

Xun
Message 5 of 5

rhasell
Advisor
Advisor