6 Replies Latest reply on Jan 24, 2014 5:40 AM by Mohammed Elkalakhi

    Problem when getting the fixed face of a flat-pattern feature

    Mohammed Elkalakhi

      Hello everybody,

       

      I have a sheetmetal part,

       

      I want to get the fixed face of a flat-pattern feature and then get its edges,

       

      I select the flat-pattern feature and I execute this code

       

              Dim swApp As SldWorks
              Dim swDoc As ModelDoc2
              Dim swSelMgr As SelectionMgr
              Dim boolstatus As Boolean
              Dim swSelObj As Object
              Dim swFeat As Feature
              Dim swFlatPatt As FlatPatternFeatureData
              Dim swFixedFace As Face2
              Dim swEdges() As Object
              Dim newState As Integer
      
              Try
      
                  swApp = CreateObject("SldWorks.Application")
                  swDoc = swApp.ActiveDoc
                  swSelMgr = swDoc.SelectionManager
      
                  swSelObj = swSelMgr.GetSelectedObject6(1, -1)
                  boolstatus = TypeOf swSelObj Is Feature
                  If Not boolstatus Then Exit Sub
                  swFeat = swSelObj
      
                  If Not "FlatPattern".Equals(swFeat.GetTypeName2()) Then Exit Sub
      
                  If swFeat.IsSuppressed2(swInConfigurationOpts_e.swThisConfiguration, "")(0) Then
                      newState = swFeatureSuppressionAction_e.swUnSuppressFeature
                      swFeat.SetSuppression2(newState, swInConfigurationOpts_e.swThisConfiguration, "")
                  End If
      
                  swFlatPatt = swFeat.GetDefinition()
                  boolstatus = swFlatPatt.AccessSelections(swDoc, Nothing)
                  If Not boolstatus Then Exit Sub
                  swFixedFace = swFlatPatt.FixedFace
                  swFlatPatt.ReleaseSelectionAccess()
      
                  swEdges = swFixedFace.GetEdges()
      
                  Console.WriteLine("Done !!")
      
              Catch ex As Exception
                  Throw ex
              End Try
      
              Console.Read()
      

       

      But When it execute the line

       

      swEdges = swFixedFace.GetEdges()

       

      I get this exception I dont know why !!

       

      1.png

       

      Please help me

        • Re: Problem when getting the fixed face of a flat-pattern feature
          Simon Turner

          How about getting the edges before calling swFlatPatt.ReleaseSelectionAccess?

            • Re: Problem when getting the fixed face of a flat-pattern feature
              Mohammed Elkalakhi

              Yes, but I will need to call other api methods that give me the same issue.

               

              Could you tell me why methodes called after swFlatPatt.ReleaseSelectionAccess() throw this exception ?

                • Re: Problem when getting the fixed face of a flat-pattern feature
                  Simon Turner

                  swFlatPatt.AccessSelections rolls the feature tree back to before the flat pattern feature. The face that you get then is different to the face that exists after you rollback after the Flat Pattern feature.

                  The flat pattern feature can potentially modify the flat face (e.g. add corner relief cutouts) so the edges may also be different.

                  It depends if you want the edges that existed on the face before the flat pattern feature, or the ones that are created after the flat pattern.

                  If you want the edges afterwards, you may need to traverse all the faces on the sheet metal body to work out which one is most like the face you get from swFlatPatt.FixedFace (e.g. same normal, roughly the same c of g etc.)

                    • Re: Problem when getting the fixed face of a flat-pattern feature
                      Mohammed Elkalakhi

                      thank you Simon, now it's clear for me,

                       

                      In fact I need edges that are created after the flat pattern feature,

                       

                      I traversed all faces of the sheet metal, but I cant't find my fixedFace within, here is my code :

                       

                       

                              Dim swApp As SldWorks
                              Dim swDoc As ModelDoc2
                              Dim swSelMgr As SelectionMgr
                              Dim boolstatus As Boolean
                              Dim swSelObj As Object
                              Dim swFeat As Feature
                              Dim swFlatPatt As FlatPatternFeatureData
                              Dim swFixedFace As Face2
                              Dim newState As Integer
                      
                              Try
                      
                                  swApp = CreateObject("SldWorks.Application")
                                  swDoc = swApp.ActiveDoc
                                  swSelMgr = swDoc.SelectionManager
                      
                                  swSelObj = swSelMgr.GetSelectedObject6(1, -1)
                                  boolstatus = TypeOf swSelObj Is Feature
                                  If Not boolstatus Then Exit Sub
                                  swFeat = swSelObj
                                  If Not "FlatPattern".Equals(swFeat.GetTypeName2()) Then Exit Sub
                      
                                  If swFeat.IsSuppressed2(swInConfigurationOpts_e.swThisConfiguration, "")(0) Then
                                      newState = swFeatureSuppressionAction_e.swUnSuppressFeature
                                      swFeat.SetSuppression2(newState, swInConfigurationOpts_e.swThisConfiguration, "")
                                  End If
                      
                                  swFlatPatt = swFeat.GetDefinition()
                                  boolstatus = swFlatPatt.AccessSelections(swDoc, Nothing)
                                  If Not boolstatus Then Exit Sub
                                  swFixedFace = swFlatPatt.FixedFace
                                  swFlatPatt.ReleaseSelectionAccess()
                      
                                  Dim swBody As Body2 = swFeat.GetFaces(0).GetBody()
                                  Dim swFaces() As Object = swBody.GetFaces()
                      
                                  If swFaces Is Nothing Then Exit Sub
                      
                                  Dim found As Boolean = False
                                  Dim index As Integer = 0
                      
                                  While Not found AndAlso index < swFaces.Count
                      
                                      found = swFaces(index) Is swFixedFace
                                      found = found Or swApp.IsSame(swFixedFace, swFaces(index)) = swObjectEquality.swObjectSame
                                      found = found Or swFaces(index).IsSame(swFixedFace)
                      
                                      index = index + 1
                      
                                  End While
                      
                                  If found Then
                                      Console.WriteLine("found")
                                  Else
                                      Console.WriteLine("Not found")
                                  End If
                      
                              Catch ex As Exception
                                  Throw ex
                              End Try
                      
                              Console.Read()