- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have assembly having 500 parts and 150 of them are sheetmetal parts.
And I want to check if flat patterns have been created for all of the sheetmetal parts.
Can we check this using iLogic codes ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Do you only need to check if flat patterns exist?
Create flat patterns if not? Or give a message? Open that Document?
Can you expound a bit?
Yes, you can definitely do this and there are many posts on how to create flat patterns.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
One more question, is it sufficient to create the flat patterns if they don't exist or do you also need a list of files which don't have flat patterns?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is something to start with. It writes the model paths which have missing flat patterns to a .txt file in the same location and with the same name as the Assembly you're running this code from. It also creates the flat patterns if they don't exist.
Dim oCompDef As SheetMetalComponentDefinition
Dim ErrorList As New ArrayList
ErrorCount = 0
'name TXT file by this assembly name and path
oFile = ThisDoc.PathAndFileName(False) & " - Checking for flat patterns" & ".txt"
'clear TXT file
System.IO.File.WriteAllText(oFile, "")
For Each oDoc As Document In ThisApplication.ActiveDocument.AllReferencedDocuments
Dim oExists As Boolean = True
If oDoc.IsModifiable = False Then Continue For
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oCompDef = oDoc.ComponentDefinition
If oCompDef.SurfaceBodies.Count = 0 Then Continue For
If oCompDef.HasFlatPattern = True Then Continue For
If oCompDef.HasFlatPattern = False Then ThisApplication.Documents.Open(oDoc.FullFileName, True)
oExists = False
Try
oCompDef.Unfold
oCompDef.FlatPattern.ExitEdit
oDoc.Save
Catch
ErrorList.Add(oDoc.DisplayName)
ErrorCount += 1
Finally
oDoc.Close(True)
End Try
End If
'Open And append To an existing Text file
Dim oAppend As System.IO.StreamWriter
oAppend = IO.File.AppendText(oFile)
If oExists = False Then
oAppend.WriteLine(oDoc.FullDocumentName)
oOpenTxtFile = True
End If
oAppend.Flush()
oAppend.Close()
Next
If oOpenTxtFile = True Then
MessageBox.Show("Opening Text File With Details", "You Have Some Missing Flat Patterns")
ThisDoc.Launch(oFile)
Else
MessageBox.Show("All components have flat patterns", "Great!")
End If
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("All Flat Patterns Completed", "Flat Pattern Extractor", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@emanuel.c , Pardon me, but it is showing as below and creating blank text file and no flat patterns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
In my version of the code, it checks whether the components comprising the assembly have a flat pattern. If they do not, it saves them names to a .txt file located in the same location, and then creates a flat pattern.
Dim oDoc As Document oDoc = ThisApplication.ActiveDocument Dim countSheetWithoutFlatPattern As Integer = 0 Dim listOfSheetWithoutFlatPattern As String If oDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Dim oRefDoc As DocumentsEnumerator oRefDoc = oDoc.AllReferencedDocuments For Each element In oRefDoc If element.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Dim oSheetCompDef As SheetMetalComponentDefinition oSheetCompDef = element.ComponentDefinition If oSheetCompDef.HasFlatPattern = False oSheetCompDef.Unfold oSheetCompDef.FlatPattern.ExitEdit listOfSheetWithoutFlatPattern = listOfSheetWithoutFlatPattern & element.FullFileName & vbCrLf countSheetWithoutFlatPattern += 1 End If End If Next Else MsgBox("It`s not assembly document") End If If countSheetWithoutFlatPattern>0 oWrite = System.IO.File.CreateText(ThisDoc.Path & "\SheetMetalWithoutFlatPattern.txt") oWrite.WriteLine(listOfSheetWithoutFlatPattern) oWrite.Close MsgBox("I saved in the file the components that didn`t have flat pattern. Now all components have flat pattern.") Else MsgBox("All components has flat pattern") End If InventorVb.DocumentUpdate() oDoc.Save2(True)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@m_baczewski , Thanks for the codes, It is working good upto 1st part without flat pattern only then open it and create flat pattern for that. But after that it is showing error as below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report