' Sub Main '[ 'Create a List of Every Component Dim ComponentMap As NameValueMap = CreateComponentMap() 'Check for Zero Result, run PDF Generator If Not ComponentMap Is Nothing Then 'List all parts/assemblies without an idw CheckAssemblyForIDW(ComponentMap) 'Preempt PDF generator FileTree(ComponentMap) End If End Sub '] 'Uses BOM iLogic Rule to produce Component List Function CreateComponentMap() As NameValueMap 'Initialise Arguments Dim oRuleArguments As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap() 'Call External Rule iLogicVb.RunExternalRule("L:\iLogic Rules\BOM", oRuleArguments) 'Retreive Result Dim Result As NameValueMap Try Result = CType(oRuleArguments.Item("BOM"), NameValueMap) Catch Result = Nothing End Try Return Result End Function Sub FileTree(vTallyMap As NameValueMap) '[ Dim oMsg As String Dim vTally As Integer = 0 'Prompt for PDF Destination Folder Dim FilePath As String Dim dialog As New System.Windows.Forms.FolderBrowserDialog() dialog.SelectedPath = ThisDoc.Path dialog.Description = "Select Save Location" & vbCrLf & "or" & vbCrLf & "Cancel to Quit" If dialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then FilePath = dialog.SelectedPath 'Prompt For PDF, DWG, Or both UserSelectedActionList = New String(){"DWG & PDF", "PDF Only", "DWG Only"} UserSelectedAction = InputListBox("What action must be performed with selected views?", _ UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options") Select UserSelectedAction Case "DWG & PDF": UserSelectedAction = 3 Case "PDF Only": UserSelectedAction = 1 Case "DWG Only": UserSelectedAction = 2 End Select 'User Inputs Job Number for idw stamp Dim jobNum As String = InputBox("What is the Job Number for these drawings?", "Input Job Number", "") 'Loop each component i = 1 For i = 1 To vTallyMap.Count 'Pull component file path and Qty values Dim vFullFileName As String = vTallyMap.Name(i) Dim vDoc As Document = ThisApplication.Documents.Open(vFullFileName, False) Dim Qty As String = vTallyMap.Value(vFullFileName) If (CheckForFileIDW(vFullFileName)) = True oMsg = oMsg & vbCrLf & Right(vFullFileName, Len(vFullFileName) -InStrRev(vFullFileName, "\")) vTally = vTally + 1 Dim idwPathName As String = Left(vFullFileName, Len(vFullFileName) - 3) & "idw" MakePDFFromDoc(idwPathName, UserSelectedAction, FilePath, jobNum, Qty) Else End If Next 'List the converted files MessageBox.Show(oMsg, vTally & " Files Have Been Converted", MessageBoxButtons.OK, MessageBoxIcon.Information) Else End If End Sub '] Sub CheckAssemblyForIDW(oList As NameValueMap) oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium Dim i As Integer = 1 For i = 1 To oList.Count Dim vFullFileName As String = oList.Name(i) Dim idwPathName As String = Left(vFullFileName, Len(vFullFileName) -3) & "idw" If(System.IO.File.Exists(idwPathName)) = 0 Then oMsg = oMsg & vbCrLf & Right(vFullFileName, Len(vFullFileName) - InStrRev(vFullFileName, "\")) Else 'Do Nothing End If Next MessageBox.Show(oMsg, "The following parts have no idw file", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Function CheckForFileIDW(FileName As String) Dim State As Boolean = True Dim idwPathName As String = Left(FileName, Len(FileName) -3) & "idw" If (System.IO.File.Exists(idwPathName)) = 0 Then State = False Return State Else Return State End If End Function Sub MakePDFFromDoc(oDocument As String, UserSelectedAction As Integer, folderName As String, jobNum As String, Qty As String) oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") ' oMsg = MessageBox.Show(oDocument, "FolderName") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium oFile = ThisApplication.Documents.Open(oDocument, True) 'Create Job Number/Qty Text Box on the idw Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSketch As DrawingSketch = oDrawDoc.ActiveSheet.Sketches.Add oSketch.Edit Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim JBText As String = jobNum & vbCrLf & "QTY: " & Qty Dim oTextBox As Inventor.TextBox ' Dim oStyle As TextStyle = oSketch.TextBoxes.Item(1).Style ' dYOff = oStyle.FontSize * 4 ' oStyle.Color = Red oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(2, 2), JBText) oSketch.ExitEdit oFullFileName = oFile.File.FullFileName ' oMsg = MessageBox.Show(folderName, "oFullFileName") oPath = Left(oFullFileName, InStrRev(oFullFileName, "\") -1) ' oMsg = MessageBox.Show(folderName, "oPath") oFileName = Right(oFullFileName, Len(oFullFileName) -InStrRev(oFullFileName, "\")) ' oMsg = MessageBox.Show(folderName, "oFileName") oFilePart = Left(oFileName, InStrRev(oFileName, ".") -1) ' oMsg = MessageBox.Show(folderName, "oFilePart") oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'get PDF target folder path oFolder = folderName ' oMsg = MessageBox.Show(oFolder, "oFolder") oDirectoryName = System.IO.Path.GetDirectoryName(oFullFileName) ' oMsg = MessageBox.Show(oDirectoryName & oFolder, "oDirectoryName") '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 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf" 'Publish document If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then oPDFAddIn.SaveCopyAs(oFile, oContext, oOptions, oDataMedium)'For PDF's End If If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then oFile.SaveAs(oFolder & "\" & oFilePart & ".dwg", True) 'For DWG's End If ThisApplication.ActiveDocument.Close(True) '------end of iLogic------- End Sub