Not finding a edge loop that IsOuterEdgeLoop using vb.net, Inventor 2015

Not finding a edge loop that IsOuterEdgeLoop using vb.net, Inventor 2015

awatt
Advocate Advocate
719 Views
3 Replies
Message 1 of 4

Not finding a edge loop that IsOuterEdgeLoop using vb.net, Inventor 2015

awatt
Advocate
Advocate

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

0 Likes
Accepted solutions (1)
720 Views
3 Replies
Replies (3)
Message 2 of 4

awatt
Advocate
Advocate

I found the logic error.  Re-testng now.

 

 

0 Likes
Message 3 of 4

awatt
Advocate
Advocate
Accepted solution

Yep.  Logic error.

 

The for-each was exiting on the first iteration.

 

As long as the first edge loop happened to be the outer edge loop, (small parts), the program worked fine.  This lead me to blame the part, not the code.

 

Sorry to bother everyone.

0 Likes
Message 4 of 4

rob_bolter
Enthusiast
Enthusiast
Sorry to drag up an old post, but did you not know about the following? Function Area() As Double Dim Doc As Inventor.Document = InvApp.ActiveDocument If Doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then If Doc.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then 'Is sheet metal Dim pDoc As PartDocument = Doc Dim SMDef As SheetMetalComponentDefinition = pDoc.ComponentDefinition If SMDef.HasFlatPattern Then Return SMDef.FlatPattern.Length * SMDef.FlatPattern.Width Else Return Nothing End If Else MsgBox("Not a sheet metal part.") Return Nothing End If Else MsgBox("Not a part document!") Return Nothing End If End Function
Intel Xeon 3.5GHz (8 Cores)
Dual nVidia Quadro K2200 (4GB) - Dual Screen
32GB RAM
0 Likes