- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a sub (vb.net) that caluclates the area of the outer edge loop, and ignores any interior cutouts, holes, slots, etc. It works fairly well, most of the time.
Every now and then I run into a part it just can't handle, with no explanation why. It's bailing out at the 'failure finding outer edge loop' (Error code "Susan".)
I'm attaching a file that seems to give it problems. (Inventor 2015).
Here's the code:
Dim oInvApp As Inventor.Application
Dim oDoc As Inventor.PartDocument
Private WithEvents AreaButton As ButtonDefinition
Sub FlatPatternSF() Handles AreaButton.OnExecute
Dim oEdgeLoops As EdgeLoops
Dim oEdgeLoop As EdgeLoop
Dim oEdges As Edges
Dim oProfile As Profile
Dim dArea As Double
Dim oFlatPattern As FlatPattern
Dim oTransaction As Transaction
Dim oSketch As PlanarSketch
Dim oParameter As UserParameter
Dim ComponentDef As SheetMetalComponentDefinition
oInvApp = Marshal.GetActiveObject("Inventor.Application")
oDoc = oInvApp.ActiveDocument
ComponentDef = oDoc.ComponentDefinition
If ComponentDef.HasFlatPattern = False Then
System.Windows.Forms.MessageBox.Show("Area not calculated. Please create flat pattern first.",
"Error",
Windows.Forms.MessageBoxButtons.OK,
Windows.Forms.MessageBoxIcon.Error)
Exit Sub
End If
oFlatPattern = ComponentDef.FlatPattern
oTransaction = oInvApp.TransactionManager.StartTransaction(oDoc, "Find Area")
Try
oSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Area not calculated. Failure creating sketch in flat pattern. Please report error code ""Jessica"" to the Cad Admin.",
"Error",
Windows.Forms.MessageBoxButtons.OK,
Windows.Forms.MessageBoxIcon.Error)
oTransaction.Abort()
Exit Sub
End Try
Try
oEdgeLoops = oFlatPattern.TopFace.EdgeLoops
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Area not calculated. Failure getting edge loops from top face. Please report error code ""Hilda"" to the Cad Admin.",
"Error",
Windows.Forms.MessageBoxButtons.OK,
Windows.Forms.MessageBoxIcon.Error)
oTransaction.Abort()
Exit Sub
End Try
' Find outer loop.
For Each oEdgeLoop In oEdgeLoops
If oEdgeLoop.IsOuterEdgeLoop Then
Exit For
End If
System.Windows.Forms.MessageBox.Show("Area not calculated. Failure finding outer edge loop. Please report error code ""Susan"" to the Cad Admin.",
"Error",
Windows.Forms.MessageBoxButtons.OK,
Windows.Forms.MessageBoxIcon.Error)
oTransaction.Abort()
Exit Sub
Next
' Add outer loop to sketch.
oEdges = oEdgeLoop.Edges
For Each oEdge In oEdges
oSketch.AddByProjectingEntity(oEdge)
Next
Try
oProfile = oSketch.Profiles.AddForSolid
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Area not calculated. Failure creating perimeter Profile. Please report error code ""Agatha"" to the Cad Admin.",
"Error",
Windows.Forms.MessageBoxButtons.OK,
Windows.Forms.MessageBoxIcon.Error)
oTransaction.Abort()
Exit Sub
End Try
dArea = oProfile.RegionProperties.Area
' Blow away sketch.
oTransaction.Abort()
' Set minimum area to 0.05 square feet (46.45 square cm).
If dArea < 46.45125 Then
dArea = 46.45125
End If
' Convert because user units are kinda wierd. Needed for legacy compatibility.
dArea = dArea * 2.54
Try
oParameter = oDoc.ComponentDefinition.Parameters.Item("Area_cm")
Catch ' Assuming that the parameter "Area_cm" does not exist.
oParameter = oDoc.ComponentDefinition.Parameters.AddByValue("Area_cm", "", UnitsTypeEnum.kInchLengthUnits)
End Try
oParameter.Value = dArea
oDoc.Update()
System.Windows.Forms.MessageBox.Show("Area calculated.",
"Success!",
Windows.Forms.MessageBoxButtons.OK)
End Sub
Solved! Go to Solution.