Check for flat patterns are created or not for all sheetmetal components in the assembly using iLogic

Check for flat patterns are created or not for all sheetmetal components in the assembly using iLogic

knb7264
Contributor Contributor
827 Views
13 Replies
Message 1 of 14

Check for flat patterns are created or not for all sheetmetal components in the assembly using iLogic

knb7264
Contributor
Contributor

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 ?

0 Likes
Accepted solutions (2)
828 Views
13 Replies
Replies (13)
Message 2 of 14

emanuel.c
Collaborator
Collaborator

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.

0 Likes
Message 3 of 14

knb7264
Contributor
Contributor

Yes, I want to

1. Get list of the models which don't have flat patterns

2. Create Flat pattern if not created earlier.

0 Likes
Message 4 of 14

emanuel.c
Collaborator
Collaborator

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?

0 Likes
Message 5 of 14

knb7264
Contributor
Contributor

Actually I need list so that first I can raise the revision of that parts in the vault and update properties.

0 Likes
Message 6 of 14

emanuel.c
Collaborator
Collaborator
Accepted solution

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) 

 

0 Likes
Message 7 of 14

knb7264
Contributor
Contributor

@emanuel.c , Pardon me, but it is showing as below and creating blank text file and no flat patterns

kapilnbhasme_0-1706043113099.png

 

0 Likes
Message 8 of 14

m_baczewski
Advocate
Advocate

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)
0 Likes
Message 9 of 14

knb7264
Contributor
Contributor

@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.

kapilnbhasme_0-1706098267160.png

 

0 Likes
Message 10 of 14

m_baczewski
Advocate
Advocate

Are all items checked-out from the Vault?

0 Likes
Message 11 of 14

emanuel.c
Collaborator
Collaborator
Accepted solution

You can try it again, I've changed a line there and it works well for me

0 Likes
Message 12 of 14

knb7264
Contributor
Contributor

Yes

0 Likes
Message 13 of 14

knb7264
Contributor
Contributor

@emanuel.c , Thank you very much ! It's perfect !!!

Message 14 of 14

emanuel.c
Collaborator
Collaborator

You're welcome!

0 Likes