Save all idw's in same folder to pdf

Save all idw's in same folder to pdf

Frank-Oosterwaal
Collaborator Collaborator
706 Views
2 Replies
Message 1 of 3

Save all idw's in same folder to pdf

Frank-Oosterwaal
Collaborator
Collaborator

Hello everyone,

 

I've been trying to use underneath code to save all the .idw files in the same folder to pdf. It seems to work fine but it gives this error at the end: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

 

Any help would be great! Thanks in advance.

 

Greets,

Frank

 

This is the code:

SyntaxEditor Code Snippet

'-----Check path----- 
oPath = ThisDoc.Path 

'-----get PDF target folder path-----
oPDFFolder = Left(oPath, InStrRev(oPath, "\")) & "KSE" & "\" & "PDF"

'-----Check for the pdf folder and create it if it does not exist-----
If Not System.IO.Directory.Exists(oPDFFolder) Then
System.IO.Directory.CreateDirectory(oPDFFolder)
End If


'-----Search for idw's in folder-----
Dim MyFiles As String()
    
    MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw")
    
'-----Starts the Loop-----
For Each MyFile As String In MyFiles


        ThisApplication.SilentOperation = True
        Dim partDoc As Document = ThisApplication.Documents.Open(MyFile, False)
        
        On Error Resume Next
        
        If partDoc.DocumentType = kDrawingDocumentObject Then
        
            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
                                
            oRevNum = iProperties.Value("Project", "Revision Number")
            oPDFAddIn = ThisApplication.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
                
                oRevNum = iProperties.Value("Project", "Revision Number")
                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
            
'-----Filename definition-----
oFileName = oPDFFolder & "\" & PartNumber & "r" & oRevNum & ".pdf"

'-----Set the PDF target file name-----
oDataMedium.FileName = oFileName 
            
'-----Publish document-----
oPDFAddIn.SaveCopyAs(partDoc, oContext, oOptions, oDataMedium)
                        
End If

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

Next


'-----Opens PDF Folder-----
Shell("explorer.exe " & oPDFFolder,vbNormalFocus)

 

 

 

---------------------------------------------------------------------------------------------------------
0 Likes
Accepted solutions (1)
707 Views
2 Replies
Replies (2)
Message 2 of 3

rhasell
Advisor
Advisor
Accepted solution

Hi

 

You never mention where you execute the code from?

 

When I tested it, the document hosting the code is closed at the end, this generates the error.

If I comment out the "partDoc.Close(False)" statement, the code does not generate an error.

 

Hope this sheds some light on the problem.

 

Reg
2026.1
0 Likes
Message 3 of 3

Frank-Oosterwaal
Collaborator
Collaborator

Hi @rhasell,

 

Sorry about that, it's executed from a ilogic form. Thanks for the answer, that solved the problem.

 

Greets,

Frank

---------------------------------------------------------------------------------------------------------