Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
m_baczewski
in reply to: knb7264

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)