Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
aurel_e
334 Views, 3 Replies

Error handling

Hi all,

 

I have the ilogic rule below to export flat pattern of sheet metal parts.

I have found it online and made some mods. Have been used it for months and just now spotted it don't work properly when in the assembly there are sheet metal parts with problems (multi body parts, or parts that cannot flatten). It looks the Ilogic rules stops. It doesn't export the parts with problems (as expected), but misses good parts as well.

I would like to modify so on error to keep going and at the end to show a txt file with the list of the problematic files.

 

 

Sub Main()
oPath = ThisDoc.Path
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim AssyDef As AssemblyComponentDefinition 
AssyDef = oAsmDoc.ComponentDefinition
Dim oAsmName = oAsmDoc.DisplayName.Replace(".iam", "")
Dim New_Folder_Path As String = oPath & "\" & oAsmName & " - LASER"
My.Computer.FileSystem.CreateDirectory(New_Folder_Path) 


Dim oMaterial As String
ExpSettingQuestion = MessageBox.Show("Do you want to export Bend Lines?", "DXF Export Settings", MessageBoxButtons.YesNo)
For Each doc As Document In oAsmDoc.AllReferencedDocuments
If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Dim RefOccs As ComponentOccurrencesEnumerator 
	RefOccs = AssyDef.Occurrences.AllReferencedOccurrences(doc)
		If RefOccs.Count >0 Then 	
Try
oMaterial = doc.ComponentDefinition.Material.Name
oThickness = doc.ComponentDefinition.Thickness.value*10
Material_Path = New_Folder_Path & "\" & oMaterial & " -  " & oThickness & "mm" 

Try
My.Computer.FileSystem.CreateDirectory(Material_Path)
Catch
End Try
If ExpSettingQuestion = vbYes  Then

Call Make_DXF(doc,oAsmDoc, Rev_Level, Material_Path,oThickness,oMaterial)
Else If ExpSettingQuestion = vbNo Then
	Call Make_DXF1(doc,oAsmDoc, Rev_Level, Material_Path,oThickness,oMaterial)
	End If
Catch
End Try
InventorVb.DocumentUpdate()
	iLogicVb.UpdateWhenDone = True
End If
End If

Next
MsgBox("DXF Export Complete",,"All Done")

End Sub

Sub Make_DXF(oDoc As Document,AsmDoc As Document, Rev_L As String, File_Location As String,oThickness As Double ,oMaterial As String)
'Get the ActiveLevelOfDetailRepresentation Name
doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim MyLOD_Name As String
MyLOD_Name = oAssyDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

If Not MyLOD_Name = "Master" Then
'activate master because only it can do the trick
    Call oAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Item(1).Activate
End If
Dim oBOM As BOM = AsmDoc.ComponentDefinition.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

For Each oBOMRow As BOMRow In oBOMView.BOMRows
Dim rDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
If rDoc.DisplayName = oDoc.DisplayName Then

Dim oQty As Integer = oBOMRow.TotalQuantity

ThisApplication.Documents.Open(oDoc.FullFileName, False)

Dim Part_Name As String = oDoc.DisplayName.Replace(".ipt", "")

Dim a As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value

Dim oFilename As String = File_Location & "\" & Part_Name & " - " & oMaterial & " " & oThickness & "mm - " & oQty & " off.dxf"


ThisApplication.SilentOperation = True

Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

If oCompDef.HasFlatPattern = False Then
oCompDef.Unfold

oCompDef.FlatPattern.ExitEdit
End If

Dim optionList As List(Of String) = New List(Of String)()

			optionList.Add("AcadVersion=2004")
			optionList.Add("OuterProfileLayer=0")
			optionList.Add("InteriorProfilesLayer=0")
			optionList.Add("UnconsumedSketchesLayer=YELLOW")
			optionList.Add("UnconsumedSketchesLayerColor=255;255;0") 
			optionList.Add("BendUpLayer=YELLOW") 
			optionList.Add("BendUpLayerColor=255;255;0") 
			optionList.Add("BendDownLayer=YELLOW") 
			optionList.Add("BendDownLayerColor=255;255;0") 
			
			optionList.Add("MarkSurfaceUpLayer=YELLOW") 
			optionList.Add("MarkSurfaceUpLayerColor=255;255;0")
			optionList.Add("MarkSurfaceDownLayer=YELLOW") 
			optionList.Add("MarkSurfaceDownColor=255;255;0") 
			

			Dim sOut As String
			sOut = "FLAT PATTERN DXF?AcadVersion=2000" _
			+ "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES;IV_ARC_CENTERS;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_FEATURE_PROFILES_DOWN"


			For Each opt In optionList
				sOut = sOut & "&" & opt
			Next
			sOut = sOut & "?OFILE"
			oCompDef.DataIO.WriteDataToFile(sOut, oFilename)

oCompDef.FlatPattern.ExitEdit
oDoc.Close
Exit For
End If
Next
oAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Item(MyLOD_Name).Activate
End Sub

Sub Make_DXF1(oDoc As Document,AsmDoc As Document, Rev_L As String, File_Location As String,oThickness As Double ,oMaterial As String)

doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim MyLOD_Name As String
MyLOD_Name = oAssyDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

If Not MyLOD_Name = "Master" Then

    Call oAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Item(1).Activate
End If
Dim oBOM As BOM = AsmDoc.ComponentDefinition.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

For Each oBOMRow As BOMRow In oBOMView.BOMRows
Dim rDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
If rDoc.DisplayName = oDoc.DisplayName Then

Dim oQty As Integer = oBOMRow.TotalQuantity

ThisApplication.Documents.Open(oDoc.FullFileName, False)

Dim Part_Name As String = oDoc.DisplayName.Replace(".ipt", "")

Dim a As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value

Dim oFilename As String = File_Location & "\" & Part_Name & " - " & oMaterial & " " & oThickness & "mm - " & oQty & " off.dxf"

ThisApplication.SilentOperation = True

Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

If oCompDef.HasFlatPattern = False Then
oCompDef.Unfold

oCompDef.FlatPattern.ExitEdit
End If

Dim optionList As List(Of String) = New List(Of String)()

			optionList.Add("AcadVersion=2004")
			optionList.Add("OuterProfileLayer=0")
			optionList.Add("InteriorProfilesLayer=0")
			optionList.Add("UnconsumedSketchesLayer=YELLOW")
			optionList.Add("UnconsumedSketchesLayerColor=255;255;0")
	
			optionList.Add("") 
			optionList.Add("") 
			

			Dim sOut As String
			sOut = "FLAT PATTERN DXF?AcadVersion=2000" _
			+ "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_FEATURE_PROFILES_DOWN"

			For Each opt In optionList
				sOut = sOut & "&" & opt
			Next
			sOut = sOut & "?OFILE"
			oCompDef.DataIO.WriteDataToFile(sOut, oFilename)
			

oCompDef.FlatPattern.ExitEdit
oDoc.Close
Exit For
End If
Next
oAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Item(MyLOD_Name).Activate
End Sub