- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have cobbled together some basic code found here on the forums to export .idw's as PDFs DXFs & DWGs. It works well for a single file, finding the correct folder to place the corresponding format into and appending the either (REL) or (Rev "No.") to the end of the file name.
I am struggling to get a loop to work,
I want the code to ask if I want only the current .IDW or to look for all currently open .IDW's
Then ask what format to save it as.
Then either export the single file or loop though all the open files placing the correct file name and appending the correct revision number
Then at the end display a message that its done.
My coding skills are quite basic any help is appreciated.
Thanks,
Sub Main() '-----Check path----- oPath = ThisDoc.Path '-----Get Target folder paths----- oPDFFolder = Left(oPath, InStrRev(oPath, "\")) & "3. PDFs" oDXFFolder = Left(oPath, InStrRev(oPath, "\")) & "4. DXFs" oDWGFolder = Left(oPath, InStrRev(oPath, "\")) & "5. DWGs" '-----Check for the folder paths and create it if they do not exist----- If Not System.IO.Directory.Exists(oPDFFolder) Then System.IO.Directory.CreateDirectory(oPDFFolder) End If If Not System.IO.Directory.Exists(oDXFFolder) Then System.IO.Directory.CreateDirectory(oDXFFolder) End If If Not System.IO.Directory.Exists(oDWGFOLDER) Then System.IO.Directory.CreateDirectory(oDWGFolder) End If '-----Inital User Input ----- '-----User defined Scope----- UserChoice = InputRadioBox("What files do you want to export", "Only This Open Document", "All Open Documents", True, Title := "Defined the scope") '-----User question setup ----- UserSelectedActionList = New String(){"Sheet Metal - PDF, DXF & DWG", "Machined Part - PDF & DWG", "PDF Only", "DXF Only", "DWG Only"} '-----User question input ----- UserSelectedAction = InputListBox("What Format is Required ?", _ UserSelectedActionList, UserSelectedActionList(0), Title := "File Type to Export", ListName := "File Format Type") Select UserSelectedAction Case "Sheet Metal - PDF, DXF & DWG" : UserSelectedAction = 1 Case "Machined Part - PDF & DWG" : UserSelectedAction = 2 Case "PDF Only" : UserSelectedAction = 3 Case "DXF Only" : UserSelectedAction = 4 Case "DWG Only" : UserSelectedAction = 5 End Select '-----Set active document----- oDocument = ThisApplication.ActiveDocument '-----Load file iproperties into variables----- oFileName = ThisDoc.FileName(False) 'file name Without extesion oPartNumber = iProperties.Value("Project", "Part Number") oDescription = iProperties.Value("Project", "Description") oRevNum = iProperties.Value("Project", "Revision Number") '-----Load PDF Add In----- 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 '-----PDF options ----- If oPDFAddIn.HasSaveCopyAsOptions(oDocument, 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") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If '----- Sets the appened Revision Number text----- If oRevNum = "REL" Then oRevString = " (" & oRevNum & ")" Else oRevString = " (REV " & oRevNum & ")" End If ' MessageBox.Show("This is the rev Number:" & oRevString, "Title") '-----Set the PDF target file name----- oDataMedium.FileName = oPDFFolder & "\" & oFileName & oRevString & ".pdf" '-----Publish User selected formats ----- If UserSelectedAction = 1 Then 'Export PDF oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Export DXF oDocument.SaveAs(oDXFFolder & "\" & oFileName & oRevString & ".dxf", True) 'Export DWG oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True) End If If UserSelectedAction = 2 Then 'Export PDF oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Export DWG oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True) End If If UserSelectedAction = 3 Then 'Export PDF oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If If UserSelectedAction = 4 Then 'Export DXF oDocument.SaveAs(oDXFFolder & "\" & oFileName & oRevString & ".dxf", True) End If If UserSelectedAction = 5 Then 'Export DWG oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True) End If '-----Successful complete message----- If UserSelectedAction = 1 Then MessageBox.Show("File successfully exported to PDF, DXF & DWG", "Export Complete") End If If UserSelectedAction = 2 Then MessageBox.Show("File successfully exported to PDF & DWG", "Export Complete") End If If UserSelectedAction = 3 Then MessageBox.Show("File successfully exported to PDF", "Export Complete") End If If UserSelectedAction = 4 Then MessageBox.Show("File successfully exported to DXF", "Export Complete") End If If UserSelectedAction = 5 Then MessageBox.Show("File successfully exported to DWG", "Export Complete") End If End Sub
Solved! Go to Solution.