@ A.Acheson
Thanks for your reaction.
See code, total code is a sloppy 3000 lines which I won't bore you with.
This is pretty much the core in the Main sub where finally the filled dictionaries are treated.
I've been advised to shorten things before, but I'm not sure how.
On the other hand, I think, there is also a lot happening, then such a rule will automatically become longer.
As for 'You would just open excel and loop through dictionary and assign each to a cell.'
I would like to have an Excel in the Inventor BOM style, just like that.
Picture and then columns with data.
Can such a row be filled in one go when I go through the BOMView or does it really have to be cell by cell?
I think I came across a BOMRow an Export there, is it suitable for that?
How can I open Excel from Inventor, are there multiple ways one of which is the best?
'----------------------------------------------------------------------------------------------------
' 1ste BOM loop, based on the BOM, create Lists en calculate string lenghts to make a more clear overview
' Take the 'Model Data' BOM to have also the Phantom Components
BOM_First_Loop_Get_ListsData_TotalQTY_LengthsData(oBOMView.BOMRows)
'----------------------------------------------------------------------------------------------------
' 2nd BOM Loop, create Files and Folders for the output
BOM_Second_Loop_fill_Dictionaries_and_TotalQTY(oBOMView.BOMRows, 1)
'----------------------------------------------------------------------------------------------------
' Publish earlier created Lists at the end of the overview
'Publish_Lists
'----------------------------------------------------------------------------------------------------
' Publish the Dictionaries and check for file lengths
' Inform user when file lengths exeeds the maximum and stop procedure
' PAY ATENTION: Check de descripton in the Declaration Section from this rule (search for Check_for_maxFileLength)
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine("Summary Processed Dictionaries:")
sw.WriteLine
sw.WriteLine
sw.WriteLine("Assemblies Combined Production Output - " & DictionaryCombinedProductionOutput.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Integer) In DictionaryCombinedProductionOutputReadable
sw.WriteLine(pair.Key & " - " & pair.Value & "x")
Next
sw.WriteLine
sw.WriteLine
sw.WriteLine("Weldments - " & DictionaryWeldments.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Integer) In DictionaryWeldmentsReadable
sw.WriteLine(pair.Key & " - " & pair.Value & "x")
Next
sw.WriteLine
sw.WriteLine
sw.WriteLine("Parts - " & DictionaryParts.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Integer) In DictionaryPartsReadable
sw.WriteLine(pair.Key & " - " & pair.Value & "x")
Next
' oProgressBar.Close
' sw.close
' ThisDoc.Launch(Control_and_Debugging_log_file)
' Exit Sub
'----------------------------------------------------------------------------------------------------
' Process the Dictionaries to the Dictionaries_***_Publish
' These Dictionaries_***_Publish will be filled with the final output name including the Quantity needed in the Project
' This gives the opportunity to get a good idea of what will be published and to be able to act on possible errors in advance
' Here the assemblies are broken down
' The, in the assemblies, used Weldments and Parts are subtracted from the Total Quantity to come to the right amount for the Other Parts Collections
For Each pair As KeyValuePair(Of Document, Integer) In DictionaryCombinedProductionOutput
Dim oDoc As Document = pair.Key
Try
Fill_DictionaryCombinedProductionOutputPublish(oDoc, pair.Value)
Catch ex As IOException
If MsgBox("Exception: " & ex.StackTrace & vbNewLine & "Continue?", vbYesNo & vbCritical, "InventorPLUS") = vbNo Then Exit Sub
End Try
Next
For Each pair As KeyValuePair(Of Document, Integer) In DictionaryWeldments
Dim oDoc As Document = pair.Key
logger.debug("=============== oDoc.FullFileName: " & oDoc.FullFileName)
Try
Fill_DictionaryWeldmentsPublish(oDoc, pair.Value)
Catch ex As IOException
If MsgBox("Exception: " & ex.StackTrace & vbNewLine & "Continue?", vbYesNo & vbCritical, "InventorPLUS") = vbNo Then Exit Sub
End Try
Next
For Each pair As KeyValuePair(Of Document, Integer) In DictionaryParts
Dim oDoc As Document = pair.Key
Try
Fill_DictionaryPartsPublish(oDoc, pair.Value)
Catch ex As IOException
If MsgBox("Exception: " & ex.StackTrace & vbNewLine & "Continue?", vbYesNo & vbCritical, "InventorPLUS") = vbNo Then Exit Sub
End Try
Next
'----------------------------------------------------------------------------------------------------
' Check for maxFileLength
If Log_List_File_Lengths.count = 0 Then
' No exeeding file lengths, continue
Else
log.WriteLine
log.WriteLine
log.Write("Files with to long file names: " & Log_List_File_Lengths.count & " (maxFileLength is set to: " & maxFileLength & ")" & vbNewLine & vbNewLine)
For Each item In Log_List_File_Lengths
log.WriteLine(item & " (Length: " & item.length & ")" )
Next
log.WriteLine
log.WriteLine
MsgBox("Files with to long file names: " & Log_List_File_Lengths.count & vbNewLine & vbNewLine & "Process will be terminated." & vbNewLine & vbNewLine & "Check log for details." , vbCritical, "HML InventorPLUS Production Output")
ThisDoc.Launch(Project_Specific_log_file)
GoTo Terminated
End If
'----------------------------------------------------------------------------------------------------
' Now we have Dictionairies_Publish with Key as New File Names and Value as Documents to Publish
' Quantity is at the end of the New File Name between parentheses
' The new file names where checked for length
' These separate dictionaries gives us the oportunity to compare what we have on disk with what we gonna put on disk
' While creating this overview we fill a Dictionary with the Total to publish Documents
' Also check or the file is In Use / Opened
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine
sw.WriteLine("Summary Processed Dictionaries to files for Final Export:")
sw.WriteLine
sw.WriteLine
sw.WriteLine("Assemblies Combined Production Output - " & DictionaryCombinedProductionOutputPublish.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Document) In DictionaryCombinedProductionOutputPublish
sw.WriteLine(pair.Key)
DictionaryAllFilesToBePublished.add(pair.Key, pair.Value)
DictionaryAllFilesToBePublishedNoQTY.add(Left(pair.Key, InStrRev(pair.Key, "(") -1),Left(pair.Key, InStrRev(pair.Key, "(") -1))
'IsFileInUse(pair.Key)
Next
sw.WriteLine
sw.WriteLine
sw.WriteLine("Weldments - " & DictionaryWeldmentsPublish.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Document) In DictionaryWeldmentsPublish
sw.WriteLine(pair.Key)
DictionaryAllFilesToBePublished.add(pair.Key, pair.Value)
DictionaryAllFilesToBePublishedNoQTY.add(Left(pair.Key, InStrRev(pair.Key, "(") -1),Left(pair.Key, InStrRev(pair.Key, "(") -1))
'IsFileInUse(pair.Key)
Next
sw.WriteLine
sw.WriteLine
sw.WriteLine("Parts - " & DictionaryPartsPublish.count & "x")
sw.WriteLine
For Each pair As KeyValuePair(Of String, Document) In DictionaryPartsPublish
sw.WriteLine(pair.Key)
DictionaryAllFilesToBePublished.add(pair.Key, pair.Value)
DictionaryAllFilesToBePublishedNoQTY.add(Left(pair.Key, InStrRev(pair.Key, "(") -1),Left(pair.Key, InStrRev(pair.Key, "(") -1))
'IsFileInUse(pair.Key)
Next
log.WriteLine
log.WriteLine("All Files to be Published: " & DictionaryAllFilesToBePublished.count)
log.WriteLine("All Files on Disk : " & DictionaryAllFilesOnDisk.count)
log.WriteLine
' ' Debug
' log.WriteLine
' log.WriteLine
' log.WriteLine
' For Each pair As KeyValuePair(Of String, String) In DictionaryAllFilesOnDisk
' log.WriteLine("DictionaryAllFilesOnDisk pair.Key) : " & pair.Key)
' log.WriteLine("DictionaryAllFilesOnDisk pair.Value): " & pair.Value)
' Next
' log.WriteLine
' log.WriteLine
' log.WriteLine
' ' Debug
' For Each pair As KeyValuePair(Of String, Document) In DictionaryAllFilesToBePublished
' log.WriteLine("DictionaryAllFilesToBePublished pair.Key) : " & pair.Key)
' log.WriteLine("DictionaryAllFilesToBePublished pair.Value): " & pair.Value.FullFileName)
' Next
' log.WriteLine
' log.WriteLine
' log.WriteLine
'----------------------------------------------------------------------------------------------------
' Compare the Output before Exporting en determine what needs to be exported
For Each pair As KeyValuePair(Of String, Document) In DictionaryAllFilesToBePublished
' FOR HELP: Check if Dictionary Contains Key: DictionaryAllFilesOnDisk.ContainsKey(pair.Key)
' FOR HELP: Get Dictionary Value for given Key: Dictionary_Total_QTY.Item(oDoc.FullFileName)
'If DictionaryAllFilesOnDisk.ContainsKey(pair.Key) Then ' File exist on Disk
If DictionaryAllFilesOnDisk.ContainsKey(Left(pair.Key, InStrRev(pair.Key, "(") -1)) Then ' File exist on Disk
'DictionaryAllFilesToBePublished.remove(pair.Key) !!!!!!!!!!
' It looks like a Dictionary don't like it when Keys are removed while it's been processed with a For Each loop
' Therefore as alternative created another Dictionary that is be filled instead of items removed
' So, the file exist on disk, compare if the QTY we need is the same as the QTY on disk
If GetQTYfromStr(pair.Key) = GetQTYfromStr(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)))
' QTY is the same, do nothing
'log.WriteLine
'log.WriteLine(pair.Value.FullFileName & " - " & GetProp(pair.Value, "DTP", "Description"))
'log.WriteLine(pair.Key)
'log.WriteLine(" Quantity was: " & DictionaryAllFilesOnDisk.item(pair.Key) & "x, now: " & GetQTYfromStr(pair.Key) & "x")
ElseIf GetQTYfromStr(pair.Key) <> GetQTYfromStr(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)))
log.WriteLine
log.WriteLine(pair.Value.FullFileName & " - " & GetProp(pair.Value, "DTP", "Description"))
log.WriteLine(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)))
log.WriteLine(" Quantity changed from: " & GetQTYfromStr(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1))) & "x to: " & GetQTYfromStr(pair.Key) & "x")
'
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)))
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & ".jpg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & ".stp")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & ".pdf")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & ".dwg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & "_Sheet_1.dwg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & "_Sheet_2.dwg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & "_Sheet_3.dwg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & "_Sheet_4.dwg")
System.IO.File.Delete(DictionaryAllFilesOnDisk.item(Left(pair.Key, InStrRev(pair.Key, "(") -1)) & "_Sheet_5.dwg")
' Add to the Final Output Dictionary
DictionaryFinalOutputAllFiles.add(pair.Key, pair.Value)
End If
Else
' Add to the Final Output Dictionary
DictionaryFinalOutputAllFiles.add(pair.Key, pair.Value)
log.WriteLine("File added: " & pair.Key)
End If
Next
log.WriteLine
'----------------------------------------------------------------------------------------------------
' Compare if there are files on disk who are not in DictionaryAllFilesToBePublished, they can be removed
log.WriteLine
For Each pair As KeyValuePair(Of String, String) In DictionaryAllFilesOnDisk
If DictionaryAllFilesToBePublishedNoQTY.ContainsKey(pair.Key) Then
' File on disk can stay, compare age...
'log.WriteLine("DictionaryAllFilesToBePublished.ContainsKey(pair.Value): " & DictionaryAllFilesToBePublished.ContainsKey(pair.Value))
'log.WriteLine("DictionaryAllFilesOnDisk pair.Value: " & pair.Value)
Else
log.WriteLine("File removed: " & Left(pair.Value, Len(pair.Value) -4))
'System.IO.File.Delete(pair.Value)
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & ".jpg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & ".stp")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & ".pdf")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & ".dwg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & "_Sheet_1.dwg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & "_Sheet_2.dwg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & "_Sheet_3.dwg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & "_Sheet_4.dwg")
System.IO.File.Delete(Left(pair.Value, Len(pair.Value) -4) & "_Sheet_5.dwg")
End If
Next
log.WriteLine
'----------------------------------------------------------------------------------------------------
If DictionaryFinalOutputAllFiles.count = 0 Then
log.WriteLine("All files are up to date.")
log.WriteLine
'----------------------------------------------------------------------------------------------------
' Progress Bar settings
oProgressBar.Message = "Calculating Finished"
Else
oSteps_Progress_Bar = DictionaryFinalOutputAllFiles.count
Dim i As Integer
For Each pair As KeyValuePair(Of String, Document) In DictionaryFinalOutputAllFiles
'----------------------------------------------------------------------------------------------------
' Progress Bar, update the Message shown within the Progress Bar with each loop.
oProgressBar.Message = "Processing Documents " & i & " Of " & oSteps_Progress_Bar & " " & pair.Value.DisplayName & " - " & GetProp(pair.Value, "DTP", "Description")
' Debugging mode, check Main Sub
If Debugging Then Exit For
ExportToSTEP(pair.Value, pair.Key, GetQTYfromStr(pair.Key))
PDF_and_DWG_Exporter(pair.Value, pair.Key)
sw.WriteLine("Updated file: " & pair.Key)
sw.WriteLine
'----------------------------------------------------------------------------------------------------
' Update the Progress Bar
oProgressBar.UpdateProgress
i = i +1
Next
sw.WriteLine("Updated files: " & DictionaryFinalOutputAllFiles.count)
sw.WriteLine
End If
' '----------------------------------------------------------------------------------------------------
' ' Export the Dictionairies to Image, STEP, PDF and DWG
' For Each pair As KeyValuePair(Of String, Document) In DictionaryCombinedProductionOutputPublish
' ' Debugging mode, check Main Sub
' If Debugging Then Exit For
' ExportToSTEP(pair.Value, pair.Key, GetQTYfromStr(pair.Key))
' PDF_and_DWG_Exporter(pair.Value, pair.Key)
' Next
' For Each pair As KeyValuePair(Of String, Document) In DictionaryWeldmentsPublish
' ' Debugging mode, check Main Sub
' If Debugging Then Exit For
' ExportToSTEP(pair.Value, pair.Key, GetQTYfromStr(pair.Key))
' PDF_and_DWG_Exporter(pair.Value, pair.Key)
' Next
' For Each pair As KeyValuePair(Of String, Document) In DictionaryPartsPublish
' ' Debugging mode, check Main Sub
' If Debugging Then Exit For
' 'logger.info("QTY: " & QTY)
' ExportToSTEP(pair.Value, pair.Key, GetQTYfromStr(pair.Key))
' PDF_and_DWG_Exporter(pair.Value, pair.Key)
' Next
'----------------------------------------------------------------------------------------------------
' Delete all empty folders
For Each item In System.IO.Directory.GetFiles(sProject_PO_Folder, "*.jpg", System.IO.SearchOption.AllDirectories)
Next