I've got something that's working for me so far, but everything can't be accounted for. Sorry there aren't any comments, I'll just explain it the best I can here.
For the first loop, it's perusing a list of all documents used to build the assembly. If a sheet metal part is found, it then looks to see if a Flat Pattern exists in the part, the nice thing is you can check for a flat pattern without opening the file directly since it's being referenced already in the assembly.
If the Flat Pattern does exist, the loop moves on to the next document. If it doesn't exist it will open the file. Then the code will Try to 1. create the flat pattern, 2. exit the flat pattern, and 3. save the file. If an error occurs on any of those steps, it will be added to the Error List. In any case, if an attempt is successful or not, the document will close, that way you won't be left with a mess of open files at the end.
If any errors were found, the code will then create a text file in the same folder location as the top assembly and list all of the documents that generated errors, then it will open the text file for you. If a previous text file of the same name already exists in the folder, it will overwrite that file.
The message box saying the process is completed is the end of the code, if a text file wasn't generated, that means no errors were found and all sheet metal parts should have working flat patterns.
Let me know if you use Autodesk Vault, since there are some extra lines and extra work on your end to make sure the Vault Add-In doesn't cause problems. After that question is answered, I can insert some other lines of code to speed up this code a fair amount.
SyntaxEditor Code Snippet
Dim oCompDef As SheetMetalComponentDefinition
Dim ErrorList As New ArrayList
ErrorCount = 0
For Each oDoc As Document In ThisApplication.ActiveDocument.AllReferencedDocuments
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oCompDef = oDoc.ComponentDefinition
If oCompDef.HasFlatPattern = True Then Continue For
If oCompDef.HasFlatPattern = False Then ThisApplication.Documents.Open(oDoc.FullFileName, True)
Try
oCompDef.Unfold
oCompDef.FlatPattern.ExitEdit
oDoc.Save
Catch
ErrorList.Add(oDoc.DisplayName)
ErrorCount += 1
Finally
oDoc.Close(True)
End Try
End If
Next
If ErrorCount > 0 Then
oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) + " Flat Pattern Errors.txt")
oWrite.WriteLine(iProperties.Value("Project", "Part Number") + " Flat Pattern Errors")
oWrite.WriteLine()
For Each i In ErrorList
oWrite.WriteLine(i)
Next
oWrite.Close
Process.Start("notepad.exe", ThisDoc.PathAndFileName(False) + " Flat Pattern Errors.txt")
End If
MessageBox.Show("Flat Pattern Check Completed.", "Flat Pattern Extractor", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Good Luck.