Sheet Metal Bend FrontFaces and BackFaces Not Working?

Sheet Metal Bend FrontFaces and BackFaces Not Working?

danmorick
Enthusiast Enthusiast
571 Views
3 Replies
Message 1 of 4

Sheet Metal Bend FrontFaces and BackFaces Not Working?

danmorick
Enthusiast
Enthusiast

Hi there.  I have an iLogic rule that has been working fine until recently and I can't figure out why it now has a problem.  It seems to be with Bend.FrontFaces or Bend.BackFaces.  The troublesome part of my code is below.  Does anyone see anything wrong with what I have, or know of something that happened with Inventor 2016 to make it not work?  Again, this used to work perfectly well.

 

Thanks!

 

 

SyntaxEditor Code Snippet

Sub Main()

Dim oApp As Inventor.Application = ThisApplication

If oApp.ActiveDocument.Subtype <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'not sheet metal document
Exit Sub
End If

oApp.SilentOperation = True

Dim oPartDoc As PartDocument = oApp.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oPartDoc.ComponentDefinition

Dim oFeatures As SheetMetalFeatures = oSMDef.Features

Dim oFace As Face
Dim oBend As Bend
Dim oBends As BendsEnumerator = oSMDef.Bends()
Dim i As Integer = 0


'Get a valid face for unfolding and flat sketch
For i = 1 To 80
oPartDoc.SelectSet.Clear
oFace = oSMDef.SurfaceBodies.Item(1).Faces.Item(i)
    If oFace.SurfaceType = 5890 Then
        oPartDoc.SelectSet.Select(oFace)
        Try
        oFeatures.UnfoldFeatures.Add(oFace)
        oApp.CommandManager.ControlDefinitions("AppUndoCmd").Execute
        oFace = oSMDef.SurfaceBodies.Item(1).Faces.Item(i)
        Exit For
        Catch
        oPartDoc.SelectSet.Clear
        End Try
    End If
Next

    If i=80 Then 'failed to find a good face
    MessageBox.Show("Couldn't unfold.", "Failure")
    Exit Sub
    End If

System.Threading.Thread.CurrentThread.Sleep(100)
oPartDoc.SelectSet.Select(oFace)
oFeatures.UnfoldFeatures.Add(oFace)
System.Threading.Thread.CurrentThread.Sleep(100)

Try
oSketch = oSMDef.Sketches.Add(oFace, False) 'Do not project face edges
Catch
Exit Sub
End Try
System.Threading.Thread.CurrentThread.Sleep(100)


Dim oBackFaces As Faces
Dim oFrontFaces As Faces

oSketch.Edit

For Each oBend In oBends
    oBackFaces = oBend.BackFaces
    oFrontFaces = oBend.FrontFaces

'It doesn't make it to here!

 

0 Likes
572 Views
3 Replies
Replies (3)
Message 2 of 4

HermJan.Otterman
Advisor
Advisor

hello Danmorick,

 

you didn't declare osketch.

 

add the line :  (before the try-catch)

 

Dim oSketch As PlanarSketch

 

and it will go

 

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 4

danmorick
Enthusiast
Enthusiast

Herm Jan,

 

Thanks very much for the reply.  I actually do have that in my code; apparently I deleted it out accidentally when I was clearing out unimportant stuff to paste here.  I apologize.  Through my testing I've found that it definitely errors on

SyntaxEditor Code Snippet

oBackFaces = oBend.BackFaces

 and similarly on

SyntaxEditor Code Snippet

oFrontFaces = oBend.FrontFaces

 

But what's weird is that last year it worked consistently.  In Inventor 2016 it seems like something changed internally and this code no longer works. 

0 Likes
Message 4 of 4

HermJan.Otterman
Advisor
Advisor

well, with the line I send you, the code runs on my machine until the last line, with no errors.

so maybe other code is not right??

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes